// react import { useEffect } from "react"; // swr import useSWR, { mutate } from "swr"; // react-hook-form import { Controller, useForm } from "react-hook-form"; // services import modulesService from "lib/services/modules.service"; // hooks import useUser from "lib/hooks/useUser"; import useToast from "lib/hooks/useToast"; // components import SelectMembers from "components/project/modules/module-detail-sidebar/select-members"; import SelectStatus from "components/project/modules/module-detail-sidebar/select-status"; // ui import { Spinner } from "ui"; // icons import { CalendarDaysIcon, ClipboardDocumentIcon, LinkIcon, PlusIcon, TrashIcon, UserIcon, } from "@heroicons/react/24/outline"; // types import { IModule } from "types"; // fetch-keys import { MODULE_DETAIL } from "constants/fetch-keys"; // common import { copyTextToClipboard } from "constants/common"; const defaultValues: Partial = { members_list: [], start_date: new Date().toString(), target_date: new Date().toString(), status: null, }; type Props = { module?: IModule; isOpen: boolean; handleDeleteModule: () => void; }; const ModuleDetailSidebar: React.FC = ({ module, isOpen, handleDeleteModule }) => { const { activeWorkspace, activeProject } = useUser(); const { setToastAlert } = useToast(); const { reset, watch, control } = useForm({ defaultValues, }); const submitChanges = (data: Partial) => { if (!activeWorkspace || !activeProject || !module) return; modulesService .patchModule(activeWorkspace.slug, activeProject.id, module.id, data) .then((res) => { console.log(res); mutate(MODULE_DETAIL); }) .catch((e) => { console.log(e); }); }; useEffect(() => { if (module) reset({ ...module, members_list: module.members_list ?? module.members_detail?.map((member) => member.id), }); }, [module, reset]); return ( <>
{module ? ( <>

{module.name}

Lead

{module.lead_detail.first_name !== "" ? ( <> {module.lead_detail.first_name} {module.lead_detail.last_name} ) : ( module.lead_detail.email )}

Start date

( )} />

End date

( { submitChanges({ target_date: e.target.value }); onChange(e.target.value); }} className="hover:bg-gray-100 bg-transparent border rounded-md shadow-sm px-2 py-1 cursor-pointer focus:outline-none focus:ring-1 focus:ring-indigo-500 focus:border-indigo-500 text-xs duration-300 w-full" /> )} />

Links

Aaryan Khandelwal

Added 2 days ago by aaryan.khandelwal@caravel.tech

) : (
)}
); }; export default ModuleDetailSidebar;