import { FC, MouseEvent, useState } from "react"; import { useRouter } from "next/router"; // next imports import Link from "next/link"; // hooks import useToast from "hooks/use-toast"; // components import { CycleCreateUpdateModal, CycleDeleteModal } from "components/cycles"; // ui import { AssigneesList } from "components/ui/avatar"; import { CustomMenu, Tooltip, LayersIcon, CycleGroupIcon } from "@plane/ui"; // icons import { Info, LinkIcon, Pencil, Star, Trash2 } from "lucide-react"; // helpers import { getDateRangeStatus, findHowManyDaysLeft, renderShortDate, renderShortMonthDate, } from "helpers/date-time.helper"; import { copyTextToClipboard } from "helpers/string.helper"; // types import { ICycle } from "types"; // store import { useMobxStore } from "lib/mobx/store-provider"; // constants import { CYCLE_STATUS } from "constants/cycle"; export interface ICyclesBoardCard { workspaceSlug: string; projectId: string; cycle: ICycle; } export const CyclesBoardCard: FC = (props) => { const { cycle, workspaceSlug, projectId } = props; // store const { cycle: cycleStore } = useMobxStore(); // toast const { setToastAlert } = useToast(); // states const [updateModal, setUpdateModal] = useState(false); const [deleteModal, setDeleteModal] = useState(false); // computed const cycleStatus = getDateRangeStatus(cycle.start_date, cycle.end_date); const isCompleted = cycleStatus === "completed"; const endDate = new Date(cycle.end_date ?? ""); const startDate = new Date(cycle.start_date ?? ""); const router = useRouter(); const currentCycle = CYCLE_STATUS.find((status) => status.value === cycleStatus); const areYearsEqual = startDate.getFullYear() === endDate.getFullYear(); const cycleTotalIssues = cycle.backlog_issues + cycle.unstarted_issues + cycle.started_issues + cycle.completed_issues + cycle.cancelled_issues; const completionPercentage = (cycle.completed_issues / cycleTotalIssues) * 100; const issueCount = cycle ? cycleTotalIssues === 0 ? "0 Issue" : cycleTotalIssues === cycle.completed_issues ? cycleTotalIssues > 1 ? `${cycleTotalIssues} Issues` : `${cycleTotalIssues} Issue` : `${cycle.completed_issues}/${cycleTotalIssues} Issues` : "0 Issue"; const handleCopyText = (e: MouseEvent) => { e.preventDefault(); e.stopPropagation(); const originURL = typeof window !== "undefined" && window.location.origin ? window.location.origin : ""; copyTextToClipboard(`${originURL}/${workspaceSlug}/projects/${projectId}/cycles/${cycle.id}`).then(() => { setToastAlert({ type: "success", title: "Link Copied!", message: "Cycle link copied to clipboard.", }); }); }; const handleAddToFavorites = (e: MouseEvent) => { e.preventDefault(); if (!workspaceSlug || !projectId) return; cycleStore.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; cycleStore.removeCycleFromFavorites(workspaceSlug?.toString(), projectId.toString(), cycle.id).catch(() => { setToastAlert({ type: "error", title: "Error!", message: "Couldn't add the cycle to favorites. Please try again.", }); }); }; const handleEditCycle = (e: MouseEvent) => { e.preventDefault(); e.stopPropagation(); setUpdateModal(true); }; const handleDeleteCycle = (e: MouseEvent) => { e.preventDefault(); e.stopPropagation(); setDeleteModal(true); }; const openCycleOverview = (e: MouseEvent) => { const { query } = router; e.preventDefault(); e.stopPropagation(); router.push({ pathname: router.pathname, query: { ...query, peekCycle: cycle.id }, }); }; return (