import { useEffect } from "react"; import { Controller, useForm } from "react-hook-form"; // components import { DateDropdown, ProjectDropdown } from "components/dropdowns"; // ui import { Button, Input, TextArea } from "@plane/ui"; // helpers import { renderFormattedPayloadDate } from "helpers/date-time.helper"; // types import { ICycle } from "@plane/types"; type Props = { handleFormSubmit: (values: Partial, dirtyFields: any) => Promise; handleClose: () => void; status: boolean; projectId: string; setActiveProject: (projectId: string) => void; data?: ICycle | null; }; const defaultValues: Partial = { name: "", description: "", start_date: null, end_date: null, }; export const CycleForm: React.FC = (props) => { const { handleFormSubmit, handleClose, status, projectId, setActiveProject, data } = props; // form data const { formState: { errors, isSubmitting, dirtyFields }, handleSubmit, control, watch, reset, } = useForm({ defaultValues: { project: projectId, name: data?.name || "", description: data?.description || "", start_date: data?.start_date || null, end_date: data?.end_date || null, }, }); useEffect(() => { reset({ ...defaultValues, ...data, }); }, [data, reset]); const startDate = watch("start_date"); const endDate = watch("end_date"); const minDate = startDate ? new Date(startDate) : new Date(); minDate.setDate(minDate.getDate() + 1); const maxDate = endDate ? new Date(endDate) : null; maxDate?.setDate(maxDate.getDate() - 1); return (
handleFormSubmit(formData,dirtyFields))}>
{!status && ( ( { onChange(val); setActiveProject(val); }} buttonVariant="background-with-text" tabIndex={7} /> )} /> )}

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

( )} />
(