diff --git a/components/flow.tsx b/components/flow.tsx index 518a2418..40e96b5b 100644 --- a/components/flow.tsx +++ b/components/flow.tsx @@ -72,19 +72,14 @@ export function Flow() { if (!response.ok) { throw new Error('Failed to fetch tasks'); } - const data: ApiResponse = await response.json(); - - // Extract tasks from the result property - const tasksList = data.result || []; - - if (!Array.isArray(tasksList)) { - console.warn('No tasks found in response', tasksList); - setTasks([]); - return; - } + const data = await response.json(); - // Sort tasks by date and limit to 4 - const sortedTasks = tasksList + // Check if data is an array directly + const tasksList = Array.isArray(data) ? data : []; + + // Filter tasks with status 3 and sort by date + const filteredAndSortedTasks = tasksList + .filter((task: Task) => task.status === 3) .sort((a: Task, b: Task) => { const dateA = a.dateToFinish ? new Date(a.dateToFinish).getTime() : a.date ? new Date(a.date).getTime() : Date.now(); @@ -94,7 +89,7 @@ export function Flow() { }) .slice(0, 4); // Limit to 4 tasks - setTasks(sortedTasks); + setTasks(filteredAndSortedTasks); } catch (error) { console.error('Error fetching tasks:', error); setError('Failed to fetch tasks');