import { FC, MouseEvent, useCallback } from "react"; import Link from "next/link"; // ui import { AvatarGroup, Tooltip, LinearProgressIndicator, ContrastIcon, RunningIcon, LayersIcon, StateGroupIcon, Avatar, } from "@plane/ui"; // components import { SingleProgressStats } from "components/core"; import { ActiveCycleProgressStats } from "./active-cycle-stats"; // hooks import { useCycle } from "hooks/store"; import useToast from "hooks/use-toast"; import useLocalStorage from "hooks/use-local-storage"; // icons import { ArrowRight, CalendarDays, Star, Target } from "lucide-react"; // types import { ICycle, TCycleLayout, TCycleView } from "@plane/types"; // helpers import { renderFormattedDate, findHowManyDaysLeft } from "helpers/date-time.helper"; import { truncateText } from "helpers/string.helper"; // constants import { STATE_GROUPS_DETAILS } from "constants/cycle"; export type ActiveCycleInfoProps = { cycle: ICycle; workspaceSlug: string; projectId: string; }; export const ActiveCycleInfo: FC = (props) => { const { cycle, workspaceSlug, projectId } = props; // store const { addCycleToFavorites, removeCycleFromFavorites } = useCycle(); // local storage const { setValue: setCycleTab } = useLocalStorage("cycle_tab", "active"); const { setValue: setCycleLayout } = useLocalStorage("cycle_layout", "list"); // toast alert const { setToastAlert } = useToast(); const groupedIssues: any = { backlog: cycle.backlog_issues, unstarted: cycle.unstarted_issues, started: cycle.started_issues, completed: cycle.completed_issues, cancelled: cycle.cancelled_issues, }; const progressIndicatorData = STATE_GROUPS_DETAILS.map((group, index) => ({ id: index, name: group.title, value: cycle.total_issues > 0 ? ((cycle[group.key as keyof ICycle] as number) / cycle.total_issues) * 100 : 0, color: group.color, })); const handleCurrentLayout = useCallback( (_layout: TCycleLayout) => { setCycleLayout(_layout); }, [setCycleLayout] ); const handleCurrentView = useCallback( (_view: TCycleView) => { setCycleTab(_view); if (_view === "draft") handleCurrentLayout("list"); }, [handleCurrentLayout, setCycleTab] ); const handleAddToFavorites = (e: MouseEvent) => { e.preventDefault(); if (!workspaceSlug || !projectId) return; addCycleToFavorites(workspaceSlug?.toString(), projectId.toString(), cycle.id).catch(() => { setToastAlert({ type: "error", title: "Error!", message: "Couldn't add the cycle to favorites. Please try again.", }); }); }; const handleRemoveFromFavorites = (e: MouseEvent) => { e.preventDefault(); if (!workspaceSlug || !projectId) return; removeCycleFromFavorites(workspaceSlug?.toString(), projectId.toString(), cycle.id).catch(() => { setToastAlert({ type: "error", title: "Error!", message: "Couldn't add the cycle to favorites. Please try again.", }); }); }; return (

{truncateText(cycle.name, 70)}

{findHowManyDaysLeft(cycle.end_date ?? new Date())} Days Left {cycle.is_favorite ? ( ) : ( )}
{cycle?.start_date && {renderFormattedDate(cycle?.start_date)}}
{cycle?.end_date && {renderFormattedDate(cycle?.end_date)}}
{cycle.owned_by.avatar && cycle.owned_by.avatar !== "" ? ( {cycle.owned_by.display_name} ) : ( {cycle.owned_by.display_name.charAt(0)} )} {cycle.owned_by.display_name}
{cycle.assignees.length > 0 && (
{cycle.assignees.map((assignee: any) => ( ))}
)}
{cycle.total_issues} issues
{cycle.completed_issues} issues
{ handleCurrentView("active"); }} > View Cycle View Cycle Issues
Progress
{Object.keys(groupedIssues).map((group, index) => ( {group}
} completed={groupedIssues[group]} total={cycle.total_issues} /> ))}
); };