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

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