import Link from "next/link"; import { useRouter } from "next/router"; import { observer } from "mobx-react"; import { Star, User2 } from "lucide-react"; // hooks import { useCycle, useEventTracker, useMember } from "hooks/store"; // components import { CycleQuickActions } from "components/cycles"; // ui import { Avatar, AvatarGroup, setPromiseToast } from "@plane/ui"; // helpers import { renderFormattedDate } from "helpers/date-time.helper"; // constants import { CYCLE_FAVORITED, CYCLE_UNFAVORITED } from "constants/event-tracker"; type Props = { cycleId: string; }; export const UpcomingCycleListItem: React.FC = observer((props) => { const { cycleId } = props; // router const router = useRouter(); const { workspaceSlug, projectId } = router.query; // store hooks const { captureEvent } = useEventTracker(); const { addCycleToFavorites, getCycleById, removeCycleFromFavorites } = useCycle(); const { getUserDetails } = useMember(); // derived values const cycle = getCycleById(cycleId); const handleAddToFavorites = (e: React.MouseEvent) => { e.preventDefault(); if (!workspaceSlug || !projectId) return; const addToFavoritePromise = addCycleToFavorites(workspaceSlug?.toString(), projectId.toString(), cycleId).then( () => { captureEvent(CYCLE_FAVORITED, { cycle_id: cycleId, element: "List layout", state: "SUCCESS", }); } ); setPromiseToast(addToFavoritePromise, { loading: "Adding cycle to favorites...", success: { title: "Success!", message: () => "Cycle added to favorites.", }, error: { title: "Error!", message: () => "Couldn't add the cycle to favorites. Please try again.", }, }); }; const handleRemoveFromFavorites = (e: React.MouseEvent) => { e.preventDefault(); if (!workspaceSlug || !projectId) return; const removeFromFavoritePromise = removeCycleFromFavorites( workspaceSlug?.toString(), projectId.toString(), cycleId ).then(() => { captureEvent(CYCLE_UNFAVORITED, { cycle_id: cycleId, element: "List layout", state: "SUCCESS", }); }); setPromiseToast(removeFromFavoritePromise, { loading: "Removing cycle from favorites...", success: { title: "Success!", message: () => "Cycle removed from favorites.", }, error: { title: "Error!", message: () => "Couldn't remove the cycle from favorites. Please try again.", }, }); }; if (!cycle) return null; return (
{cycle.name}
{cycle.start_date && cycle.end_date && (
{renderFormattedDate(cycle.start_date)} - {renderFormattedDate(cycle.end_date)}
)} {cycle.assignee_ids?.length > 0 ? ( {cycle.assignee_ids?.map((assigneeId) => { const member = getUserDetails(assigneeId); return ; })} ) : ( )} {cycle.is_favorite ? ( ) : ( )} {workspaceSlug && projectId && ( )}
); });