import React from "react"; import { format } from "date-fns"; import { ClipboardDocumentListIcon, ClockIcon, ArrowPathIcon, CalendarDaysIcon, // Import the icon for due tasks } from "@heroicons/react/24/outline"; import { Task } from "../../entities/Task"; import { Project } from "../../entities/Project"; import useFetchTasks from "../../hooks/useFetchTasks"; import useFetchProjects from "../../hooks/useFetchProjects"; import useManageTasks from "../../hooks/useManageTasks"; import NewTask from "./NewTask"; import TaskList from "./TaskList"; const TasksToday: React.FC = () => { // Fetch tasks and metrics const { tasks, metrics, isLoading: loadingTasks, isError: errorTasks, } = useFetchTasks({ type: "today", }); // Fetch projects const { projects, isLoading: loadingProjects, isError: errorProjects, } = useFetchProjects(); // Task management functions const { updateTask, deleteTask } = useManageTasks(); // Handle task updates const handleTaskUpdate = (updatedTask: Task): void => { if (updatedTask.id === undefined) { console.error("Error updating task: Task ID is undefined."); return; } updateTask(updatedTask.id, updatedTask) .then(() => { // Optionally, refetch tasks or update local state }) .catch((error) => { console.error("Error updating task:", error); }); }; // Handle task deletion const handleTaskDelete = (taskId: number): void => { deleteTask(taskId) .then(() => { // Optionally, refetch tasks or update local state }) .catch((error) => { console.error("Error deleting task:", error); }); }; // Handle loading and error states if (loadingTasks || loadingProjects) { return
Loading...
; } if (errorTasks) { returnError loading tasks.
; } if (errorProjects) { returnError loading projects.
; } return (Backlog
{metrics.total_open_tasks}
Stale
{metrics.tasks_pending_over_month}
In Progress
{metrics.tasks_in_progress_count}
Due Today
{metrics.tasks_due_today.length}
No tasks available for today.
)}