From 16f20958ad3bc4eda641bfaecbdd0aa4056b0c7f Mon Sep 17 00:00:00 2001 From: Alma Date: Sat, 12 Apr 2025 14:03:32 +0200 Subject: [PATCH] working leantime widget 24 --- components/flow.tsx | 84 ++++++++++++++++++++++++++++++--------------- 1 file changed, 57 insertions(+), 27 deletions(-) diff --git a/components/flow.tsx b/components/flow.tsx index 813aee73..5c402f19 100644 --- a/components/flow.tsx +++ b/components/flow.tsx @@ -12,7 +12,8 @@ interface Task { projectId: number; status: string; dueDate: string | null; - milestone?: string; + milestone: string | null; + details: string | null; } export function Flow() { @@ -43,7 +44,27 @@ export function Flow() { const data = await response.json(); if (data.tasks && Array.isArray(data.tasks)) { - setTasks(data.tasks); + // Sort tasks by due date (overdue first) + const sortedTasks = data.tasks.sort((a: Task, b: Task) => { + // If a task has no due date, put it at the end + if (!a.dueDate) return 1; + if (!b.dueDate) return -1; + + const dateA = new Date(a.dueDate); + const dateB = new Date(b.dueDate); + const now = new Date(); + + // If one task is overdue and the other isn't, put overdue first + const aOverdue = dateA < now; + const bOverdue = dateB < now; + if (aOverdue && !bOverdue) return -1; + if (!aOverdue && bOverdue) return 1; + + // Otherwise sort by due date + return dateA.getTime() - dateB.getTime(); + }); + + setTasks(sortedTasks); } else { setTasks([]); } @@ -66,15 +87,6 @@ export function Flow() { }; }, []); - // Group tasks by project - const tasksByProject = tasks.reduce((acc, task) => { - if (!acc[task.projectName]) { - acc[task.projectName] = []; - } - acc[task.projectName].push(task); - return acc; - }, {} as Record); - const getStatusClass = (status: string): string => { switch (status.toLowerCase()) { case 'new': @@ -83,6 +95,8 @@ export function Flow() { return 'bg-yellow-100 text-yellow-800'; case 'completed': return 'bg-green-100 text-green-800'; + case 'overdue': + return 'bg-red-100 text-red-800'; default: return 'bg-gray-100 text-gray-800'; } @@ -98,6 +112,15 @@ export function Flow() { }); }; + // Group tasks by project, maintaining the sorted order + const tasksByProject = tasks.reduce((acc, task) => { + if (!acc[task.projectName]) { + acc[task.projectName] = []; + } + acc[task.projectName].push(task); + return acc; + }, {} as Record); + return ( @@ -119,30 +142,37 @@ export function Flow() { ) : error ? (
{error}
- ) : Object.keys(tasksByProject).length === 0 ? ( + ) : tasks.length === 0 ? (
No tasks found
) : ( -
+
{Object.entries(tasksByProject).map(([projectName, projectTasks]) => (
-

{projectName}

-
- {projectTasks.map((task) => ( -
-
-
{task.headline}
-
+

{projectName}

+
+ {projectTasks.map((task) => { + const dueDate = task.dueDate ? new Date(task.dueDate) : null; + const isOverdue = dueDate && dueDate < new Date(); + + return ( +
+
+
{task.headline}
{task.milestone && ( - {task.milestone} +
+ {task.milestone} +
)} - {formatDate(task.dueDate)} +
+ {formatDate(task.dueDate)} +
+
+
+ {isOverdue ? 'OVERDUE' : task.status.toUpperCase()}
-
- {task.status.toUpperCase()} -
-
- ))} + ); + })}
))}