import { useEffect } from "react"; import { Controller, useForm } from "react-hook-form"; // types import { ICycle } from "@plane/types"; // ui import { Button, Input, TextArea } from "@plane/ui"; // components import { DateRangeDropdown, ProjectDropdown } from "@/components/dropdowns"; // helpers import { getDate, renderFormattedPayloadDate } from "@/helpers/date-time.helper"; import { shouldRenderProject } from "@/helpers/project.helper"; 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, reset, } = useForm({ defaultValues: { project_id: 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]); return (
handleFormSubmit(formData, dirtyFields))}>
{!status && ( (
{ onChange(val); setActiveProject(val); }} buttonVariant="border-with-text" renderCondition={(project) => shouldRenderProject(project)} tabIndex={7} />
)} /> )}

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

( )} /> {errors?.name?.message}
(