import { useEffect, useState } from "react"; // react-hook-form import { Controller, useForm } from "react-hook-form"; // hooks import useToast from "hooks/use-toast"; // components import { ModuleLeadSelect, ModuleMembersSelect, ModuleStatusSelect } from "components/modules"; // ui import { CustomDatePicker, Input, PrimaryButton, SecondaryButton, TextArea } from "components/ui"; // helper import { isDateRangeValid } from "helpers/date-time.helper"; // types import { IModule } from "types"; type Props = { handleFormSubmit: (values: Partial) => Promise; handleClose: () => void; status: boolean; data?: IModule; }; const defaultValues: Partial = { name: "", description: "", status: null, lead: null, members_list: [], }; export const ModuleForm: React.FC = ({ handleFormSubmit, handleClose, status, data }) => { const [isDateValid, setIsDateValid] = useState(true); const { setToastAlert } = useToast(); const { register, formState: { errors, isSubmitting }, handleSubmit, watch, control, reset, } = useForm({ defaultValues, }); const handleCreateUpdateModule = async (formData: Partial) => { await handleFormSubmit(formData); reset({ ...defaultValues, }); }; useEffect(() => { reset({ ...defaultValues, ...data, }); }, [data, reset]); return (

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