import { useEffect, useState } from "react"; import Link from "next/link"; import { useRouter } from "next/router"; import { mutate } from "swr"; // react-hook-form import { Controller, useForm } from "react-hook-form"; // icons import { CalendarDaysIcon, ChartPieIcon, LinkIcon, PlusIcon, TrashIcon, } from "@heroicons/react/24/outline"; // progress-bar import { CircularProgressbar } from "react-circular-progressbar"; // services import modulesService from "services/modules.service"; // hooks import useToast from "hooks/use-toast"; // components import { ModuleLinkModal, SidebarLeadSelect, SidebarMembersSelect, SidebarStatusSelect, } from "components/modules"; import "react-circular-progressbar/dist/styles.css"; // components import { SidebarProgressStats } from "components/core"; // ui import { CustomDatePicker, Loader } from "components/ui"; // helpers import { timeAgo } from "helpers/date-time.helper"; import { copyTextToClipboard } from "helpers/string.helper"; import { groupBy } from "helpers/array.helper"; // types import { IIssue, IModule, ModuleIssueResponse } from "types"; // fetch-keys import { MODULE_DETAILS } from "constants/fetch-keys"; import ProgressChart from "components/core/sidebar/progress-chart"; const defaultValues: Partial = { lead: "", members_list: [], start_date: null, target_date: null, status: null, }; type Props = { issues: IIssue[]; module?: IModule; isOpen: boolean; moduleIssues: ModuleIssueResponse[] | undefined; handleDeleteModule: () => void; }; export const ModuleDetailsSidebar: React.FC = ({ issues, module, isOpen, moduleIssues, handleDeleteModule, }) => { const [moduleLinkModal, setModuleLinkModal] = useState(false); const router = useRouter(); const { workspaceSlug, projectId, moduleId } = router.query; const { setToastAlert } = useToast(); const { reset, watch, control } = useForm({ defaultValues, }); const groupedIssues = { backlog: [], unstarted: [], started: [], cancelled: [], completed: [], ...groupBy(moduleIssues ?? [], "issue_detail.state_detail.group"), }; const submitChanges = (data: Partial) => { if (!workspaceSlug || !projectId || !moduleId) return; mutate( MODULE_DETAILS(moduleId as string), (prevData) => ({ ...(prevData as IModule), ...data, }), false ); modulesService .patchModule(workspaceSlug as string, projectId as string, moduleId as string, data) .then((res) => { console.log(res); mutate(MODULE_DETAILS(moduleId as string)); }) .catch((e) => { console.log(e); }); }; useEffect(() => { if (module) reset({ ...module, members_list: module.members_list ?? module.members_detail?.map((m) => m.id), }); }, [module, reset]); return ( <> setModuleLinkModal(false)} module={module} />
{module ? ( <>

{module.name}

Progress

{groupedIssues.completed.length}/{moduleIssues?.length}

Start date

( submitChanges({ start_date: val, }) } /> )} />

End date

( submitChanges({ target_date: val, }) } /> )} />

Links

{module.link_module && module.link_module.length > 0 ? module.link_module.map((link) => (
{link.title}

Added {timeAgo(link.created_at)} ago by{" "} {link.created_by_detail.email}

)) : null}
) : (
)}
); };