import { useEffect } from "react"; import { useRouter } from "next/router"; import { mutate } from "swr"; // react-hook-form import { Controller, useForm } from "react-hook-form"; // icons import { CalendarDaysIcon, ChartPieIcon, LinkIcon, UserIcon } from "@heroicons/react/24/outline"; // services import cyclesService from "services/cycles.service"; // hooks import useToast from "hooks/use-toast"; // ui import { Loader } from "components/ui"; //progress-bar import { CircularProgressbar } from "react-circular-progressbar"; import "react-circular-progressbar/dist/styles.css"; // helpers import { copyTextToClipboard } from "helpers/string.helper"; import { groupBy } from "helpers/array.helper"; // types import { CycleIssueResponse, ICycle } from "types"; // fetch-keys import { CYCLE_DETAIL } from "constants/fetch-keys"; type Props = { cycle: ICycle | undefined; isOpen: boolean; cycleIssues: CycleIssueResponse[]; }; const defaultValues: Partial = { start_date: new Date().toString(), end_date: new Date().toString(), }; const CycleDetailSidebar: React.FC = ({ cycle, isOpen, cycleIssues }) => { const router = useRouter(); const { query: { workspaceSlug, projectId }, } = router; const { setToastAlert } = useToast(); const { reset, control } = useForm({ defaultValues, }); const groupedIssues = { backlog: [], unstarted: [], started: [], cancelled: [], completed: [], ...groupBy(cycleIssues ?? [], "issue_detail.state_detail.group"), }; const submitChanges = (data: Partial) => { if (!workspaceSlug || !projectId || !module) return; cyclesService .patchCycle(workspaceSlug as string, projectId as string, cycle?.id ?? "", data) .then((res) => { console.log(res); mutate(CYCLE_DETAIL); }) .catch((e) => { console.log(e); }); }; useEffect(() => { if (cycle) reset({ ...cycle, }); }, [cycle, reset]); return (
{cycle ? ( <>

{cycle.name}

Owned by

{cycle.owned_by.first_name !== "" ? ( <> {cycle.owned_by.first_name} {cycle.owned_by.last_name} ) : ( cycle.owned_by.email )}

Progress

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

Start date

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

End date

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