// react import React, { useState } from "react"; // next import Link from "next/link"; import Image from "next/image"; // swr import useSWR from "swr"; // services import cyclesService from "lib/services/cycles.service"; // hooks import useUser from "lib/hooks/useUser"; // ui import { Button, CustomMenu } from "ui"; // types import { CycleIssueResponse, ICycle } from "types"; // fetch-keys import { CYCLE_ISSUES } from "constants/fetch-keys"; import { groupBy, renderShortNumericDateFormat } from "constants/common"; import { ArrowPathIcon, CheckIcon, UserIcon } from "@heroicons/react/24/outline"; import { CalendarDaysIcon } from "@heroicons/react/20/solid"; import { useRouter } from "next/router"; type Props = { cycle: ICycle; handleEditCycle: () => void; handleDeleteCycle: () => void; }; const stateGroupColours: { [key: string]: string; } = { backlog: "#3f76ff", unstarted: "#ff9e9e", started: "#d687ff", cancelled: "#ff5353", completed: "#096e8d", }; const SingleStat: React.FC = ({ cycle, handleEditCycle, handleDeleteCycle }) => { const { activeWorkspace, activeProject } = useUser(); const router = useRouter(); 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"), }; const startDate = new Date(cycle.start_date ?? ""); const endDate = new Date(cycle.end_date ?? ""); const today = new Date(); return ( <>

{cycle.name}

{today < startDate ? "Not started" : today > endDate ? "Over" : "Active"}
Edit cycle Delete cycle permanently
Cycle dates
{renderShortNumericDateFormat(startDate)} - {renderShortNumericDateFormat(endDate)}
Created by
{cycle.owned_by.avatar && cycle.owned_by.avatar !== "" ? ( {cycle.owned_by.first_name} ) : ( {cycle.owned_by.first_name.charAt(0)} )} {cycle.owned_by.first_name}
Active members

PROGRESS

{Object.keys(groupedIssues).map((group) => { return (
{group}
{groupedIssues[group].length}{" "} -{" "} {cycleIssues && cycleIssues.length > 0 ? `${Math.round( (groupedIssues[group].length / cycleIssues.length) * 100 )}%` : "0%"}
); })}
); }; export default SingleStat;