// next import Link from "next/link"; // swr import useSWR from "swr"; // services import cyclesService from "lib/services/cycles.service"; // hooks import useUser from "lib/hooks/useUser"; // types import { CycleIssueResponse, ICycle } from "types"; // fetch-keys import { CYCLE_ISSUES } from "constants/fetch-keys"; import { groupBy, renderShortNumericDateFormat } from "constants/common"; import { CheckIcon, ExclamationCircleIcon, ExclamationTriangleIcon, } from "@heroicons/react/24/outline"; type Props = { cycle: ICycle }; const stateGroupIcons: { [key: string]: JSX.Element; } = { backlog: , unstarted: , started: , cancelled: , completed: , }; const SingleStat: React.FC = ({ cycle }) => { const { activeWorkspace, activeProject } = useUser(); const { data: cycleIssues } = useSWR( activeWorkspace && activeProject && cycle.id ? CYCLE_ISSUES(cycle.id as string) : null, activeWorkspace && activeProject && cycle.id ? () => cyclesService.getCycleIssues(activeWorkspace?.slug, activeProject?.id, cycle.id as string) : null ); const groupedIssues = { backlog: [], unstarted: [], started: [], cancelled: [], completed: [], ...groupBy(cycleIssues ?? [], "issue_details.state_detail.group"), }; // status calculator const startDate = new Date(cycle.start_date ?? ""); const endDate = new Date(cycle.end_date ?? ""); const today = new Date(); return ( <>
{cycle.name}
{renderShortNumericDateFormat(startDate)} {" - "} {renderShortNumericDateFormat(endDate)}
{today.getDate() < startDate.getDate() ? "Not started" : today.getDate() > endDate.getDate() ? "Over" : "Active"}
{Object.keys(groupedIssues).map((group) => { return (
{stateGroupIcons[group]}
{group}
{groupedIssues[group].length}
); })}
); }; export default SingleStat;