import { useEffect } from "react"; import { Controller, useForm } from "react-hook-form"; import { IModule } from "@plane/types"; // ui import { Button, Input, TextArea } from "@plane/ui"; // components import { DateRangeDropdown, ProjectDropdown, MemberDropdown } from "@/components/dropdowns"; import { ModuleStatusSelect } from "@/components/modules"; // helpers import { getDate, renderFormattedPayloadDate } from "@/helpers/date-time.helper"; import { shouldRenderProject } from "@/helpers/project.helper"; // types type Props = { handleFormSubmit: (values: Partial, dirtyFields: any) => Promise; handleClose: () => void; status: boolean; projectId: string; setActiveProject: React.Dispatch>; data?: IModule; }; const defaultValues: Partial = { name: "", description: "", status: "backlog", lead_id: null, member_ids: [], }; export const ModuleForm: React.FC = (props) => { const { handleFormSubmit, handleClose, status, projectId, setActiveProject, data } = props; // form info const { formState: { errors, isSubmitting, dirtyFields }, handleSubmit, control, reset, } = useForm({ defaultValues: { project_id: projectId, name: data?.name || "", description: data?.description || "", status: data?.status || "backlog", lead_id: data?.lead_id || null, member_ids: data?.member_ids || [], }, }); const handleCreateUpdateModule = async (formData: Partial) => { await handleFormSubmit(formData, dirtyFields); reset({ ...defaultValues, }); }; useEffect(() => { reset({ ...defaultValues, ...data, }); }, [data, reset]); return (
{!status && ( (
{ onChange(val); setActiveProject(val); }} buttonVariant="border-with-text" renderCondition={(project) => shouldRenderProject(project)} tabIndex={10} />
)} /> )}

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

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