"use client"; import { getAllSchedulesApi } from "@/app/utils/api/projectApi"; import { Card } from "ikoncomponents"; import { useEffect, useState, useMemo } from "react"; interface Task { id: number; taskName: string; taskDescription: string; taskStart: string; taskEnd: string; milestoneTask: boolean; } export default function CurrentMonthMilestones() { const [apiTasks, setApiTasks] = useState([]); useEffect(() => { const fetchScheduleData = async () => { try { const response = await getAllSchedulesApi(); // Flatten all nested task arrays across every project in the response const allTasks = response.flatMap((project: any) => project.task || []); setApiTasks(allTasks); } catch (error) { console.error("Error fetching schedule data:", error); } }; fetchScheduleData(); }, []); const visibleMilestones = useMemo(() => { const today = new Date(); today.setHours(0, 0, 0, 0); return ( apiTasks .filter((task) => { // 1. Must be a milestone task const isMilestone = task.milestoneTask === true; // 2. Must be today or a future date const taskStartDate = new Date(task.taskStart); taskStartDate.setHours(0, 0, 0, 0); const isTodayOrFuture = taskStartDate >= today; return isMilestone && isTodayOrFuture; }) // 3. Keep exactly the top 3 items .slice(0, 3) ); }, [apiTasks]); return (

Current Month Milestones

{visibleMilestones.length === 0 ? (

No milestone tasks scheduled for this period.

) : (
{visibleMilestones.map((task, index) => (
{/* Index and Task Name */}

{index + 1}. {task.taskName}

{/* Description Block */}

{task.taskDescription || "No description provided."}

{/* Dates in a Separate Line Below */}
Start: {" "} {task.taskStart}
End:{" "} {task.taskEnd}
))}
)}
); }