import { useEffect } from "react"; import { Controller, useForm } from "react-hook-form"; // components import { ModuleStatusSelect } from "components/modules"; import { DateDropdown, ProjectDropdown, ProjectMemberDropdown } from "components/dropdowns"; // ui import { Button, Input, TextArea } from "@plane/ui"; // helpers import { renderFormattedPayloadDate } from "helpers/date-time.helper"; // types import { IModule } from "@plane/types"; type Props = { handleFormSubmit: (values: Partial) => Promise; handleClose: () => void; status: boolean; projectId: string; setActiveProject: React.Dispatch>; data?: IModule; }; const defaultValues: Partial = { name: "", description: "", status: "backlog", lead: null, members: [], }; export const ModuleForm: React.FC = ({ handleFormSubmit, handleClose, status, projectId, setActiveProject, data, }) => { const { formState: { errors, isSubmitting }, handleSubmit, watch, control, reset, } = useForm({ defaultValues: { project: projectId, name: data?.name || "", description: data?.description || "", status: data?.status || "backlog", lead: data?.lead || null, members: data?.members || [], }, }); const handleCreateUpdateModule = async (formData: Partial) => { await handleFormSubmit(formData); reset({ ...defaultValues, }); }; useEffect(() => { reset({ ...defaultValues, ...data, }); }, [data, reset]); const startDate = watch("start_date"); const targetDate = watch("target_date"); const minDate = startDate ? new Date(startDate) : new Date(); minDate?.setDate(minDate.getDate()); const maxDate = targetDate ? new Date(targetDate) : null; maxDate?.setDate(maxDate.getDate()); return (
{!status && ( (
{ onChange(val); setActiveProject(val); }} buttonVariant="border-with-text" tabIndex={10} />
)} /> )}

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

( )} />
(