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

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