import { useEffect } from "react"; import { useForm } from "react-hook-form"; // ui import { Input, PrimaryButton, SecondaryButton, TextArea } from "components/ui"; // types import { IPageForm } from "types"; type Props = { handleFormSubmit: (values: IPageForm) => Promise; handleClose: () => void; status: boolean; data?: IPageForm; }; const defaultValues: IPageForm = { name: "", description: "", }; export const PageForm: React.FC = ({ handleFormSubmit, handleClose, status, data }) => { const { register, formState: { errors, isSubmitting }, handleSubmit, reset, } = useForm({ defaultValues, }); const handleCreateUpdatePage = async (formData: IPageForm) => { await handleFormSubmit(formData); reset({ ...defaultValues, }); }; useEffect(() => { reset({ ...defaultValues, ...data, }); }, [data, reset]); return (

{status ? "Update" : "Create"} Page