mirror of
https://github.com/awatertrevi/infisical.git
synced 2026-10-08 14:28:20 +00:00
feat: adds cancel button and uses zod over yup
This commit is contained in:
@@ -1,20 +1,20 @@
|
|||||||
import { FC } from "react";
|
import { FC } from "react";
|
||||||
import { Controller, useForm } from "react-hook-form";
|
import { Controller, useForm } from "react-hook-form";
|
||||||
import { useRouter } from "next/router";
|
import { useRouter } from "next/router";
|
||||||
import { yupResolver } from "@hookform/resolvers/yup";
|
import { zodResolver } from "@hookform/resolvers/zod";
|
||||||
import * as yup from "yup";
|
import z from "zod";
|
||||||
|
|
||||||
import { useNotificationContext } from "@app/components/context/Notifications/NotificationProvider";
|
import { useNotificationContext } from "@app/components/context/Notifications/NotificationProvider";
|
||||||
import { Button, FormControl, Input, Modal, ModalContent } from "@app/components/v2";
|
import { Button, FormControl, Input, Modal, ModalContent } from "@app/components/v2";
|
||||||
import { useCreateOrg } from "@app/hooks/api";
|
import { useCreateOrg } from "@app/hooks/api";
|
||||||
|
|
||||||
const schema = yup
|
const schema = z
|
||||||
.object({
|
.object({
|
||||||
name: yup.string().required("Organization name is required")
|
name: z.string().nonempty({ message: "Name is required" })
|
||||||
})
|
})
|
||||||
.required();
|
.required();
|
||||||
|
|
||||||
export type FormData = yup.InferType<typeof schema>;
|
export type FormData = z.infer<typeof schema>;
|
||||||
|
|
||||||
interface CreateOrgModalProps {
|
interface CreateOrgModalProps {
|
||||||
isOpen: boolean;
|
isOpen: boolean;
|
||||||
@@ -31,7 +31,7 @@ export const CreateOrgModal: FC<CreateOrgModalProps> = ({ isOpen, onClose }) =>
|
|||||||
reset,
|
reset,
|
||||||
formState: { isSubmitting }
|
formState: { isSubmitting }
|
||||||
} = useForm<FormData>({
|
} = useForm<FormData>({
|
||||||
resolver: yupResolver(schema),
|
resolver: zodResolver(schema),
|
||||||
defaultValues: {
|
defaultValues: {
|
||||||
name: ""
|
name: ""
|
||||||
}
|
}
|
||||||
@@ -83,15 +83,20 @@ export const CreateOrgModal: FC<CreateOrgModalProps> = ({ isOpen, onClose }) =>
|
|||||||
</FormControl>
|
</FormControl>
|
||||||
)}
|
)}
|
||||||
/>
|
/>
|
||||||
<Button
|
<div className="flex w-full gap-4">
|
||||||
className=""
|
<Button
|
||||||
size="sm"
|
className=""
|
||||||
type="submit"
|
size="sm"
|
||||||
isLoading={isSubmitting}
|
type="submit"
|
||||||
isDisabled={isSubmitting}
|
isLoading={isSubmitting}
|
||||||
>
|
isDisabled={isSubmitting}
|
||||||
Create
|
>
|
||||||
</Button>
|
Create
|
||||||
|
</Button>
|
||||||
|
<Button className="" size="sm" variant="outline_bg" type="button" onClick={onClose}>
|
||||||
|
Cancel
|
||||||
|
</Button>
|
||||||
|
</div>
|
||||||
</form>
|
</form>
|
||||||
</ModalContent>
|
</ModalContent>
|
||||||
</Modal>
|
</Modal>
|
||||||
|
|||||||
Reference in New Issue
Block a user