import { FC, MouseEvent } from "react"; import { observer } from "mobx-react"; import { useRouter } from "next/router"; // icons import { Check, Info } from "lucide-react"; // types import type { TCycleGroups } from "@plane/types"; // ui import { CircularProgressIndicator } from "@plane/ui"; // components import { ListItem } from "@/components/core/list"; import { CycleListItemAction } from "@/components/cycles/list"; // hooks import { useCycle } from "@/hooks/store"; import { usePlatformOS } from "@/hooks/use-platform-os"; type TCyclesListItem = { cycleId: string; handleEditCycle?: () => void; handleDeleteCycle?: () => void; handleAddToFavorites?: () => void; handleRemoveFromFavorites?: () => void; workspaceSlug: string; projectId: string; isArchived?: boolean; }; export const CyclesListItem: FC = observer((props) => { const { cycleId, workspaceSlug, projectId, isArchived = false } = props; // router const router = useRouter(); // hooks const { isMobile } = usePlatformOS(); // store hooks const { getCycleById } = useCycle(); // derived values const cycleDetails = getCycleById(cycleId); if (!cycleDetails) return null; // computed // TODO: change this logic once backend fix the response const cycleStatus = cycleDetails.status ? (cycleDetails.status.toLocaleLowerCase() as TCycleGroups) : "draft"; const isCompleted = cycleStatus === "completed"; const cycleTotalIssues = cycleDetails.backlog_issues + cycleDetails.unstarted_issues + cycleDetails.started_issues + cycleDetails.completed_issues + cycleDetails.cancelled_issues; const completionPercentage = (cycleDetails.completed_issues / cycleTotalIssues) * 100; const progress = isNaN(completionPercentage) ? 0 : Math.floor(completionPercentage); // handlers const openCycleOverview = (e: MouseEvent) => { const { query } = router; e.preventDefault(); e.stopPropagation(); if (query.peekCycle) { delete query.peekCycle; router.push({ pathname: router.pathname, query: { ...query }, }); } else { router.push({ pathname: router.pathname, query: { ...query, peekCycle: cycleId }, }); } }; return ( { if (isArchived) { openCycleOverview(e); } }} prependTitleElement={ {isCompleted ? ( progress === 100 ? ( ) : ( {`!`} ) ) : progress === 100 ? ( ) : ( {`${progress}%`} )} } appendTitleElement={ } actionableItems={ } isMobile={isMobile} /> ); });