import React from "react"; import { format } from "date-fns"; import { ClipboardDocumentListIcon, ClockIcon, ArrowPathIcon, CalendarDaysIcon, } 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 = () => { const { tasks, metrics, isLoading: loadingTasks, isError: errorTasks, mutate: mutateTasks, } = useFetchTasks({ type: "today", }); const { projects, isLoading: loadingProjects, isError: errorProjects, } = useFetchProjects(); const { updateTask, deleteTask } = useManageTasks(); const handleTaskUpdate = (updatedTask: Task): void => { if (updatedTask.id === undefined) { console.error("Error updating task: Task ID is undefined."); return; } updateTask(updatedTask.id, updatedTask) .then(() => { mutateTasks(); }) .catch((error) => { console.error("Error updating task:", error); }); }; const handleTaskDelete = (taskId: number): void => { deleteTask(taskId) .then(() => { mutateTasks(); }) .catch((error) => { console.error("Error deleting task:", error); }); }; if (loadingTasks || loadingProjects) { return

Loading...

; } if (errorTasks) { return

Error loading tasks.

; } if (errorProjects) { return

Error loading projects.

; } return (
{/* Header */}

Today

{format(new Date(), "EEEE, MMMM d, yyyy")}
{/* Overview of Tasks */}
{/* Total Open Tasks */}

Backlog

{metrics.total_open_tasks}

{/* Tasks Pending Over a Month */}

Stale

{metrics.tasks_pending_over_month}

{/* Tasks In Progress */}

In Progress

{metrics.tasks_in_progress_count}

{/* Tasks Due Today */}

Due Today

{metrics.tasks_due_today.length}

{/* Tasks Due Today */} {metrics.tasks_due_today.length > 0 && ( <>

Tasks Due Today

)} {/* Tasks In Progress */} {metrics.tasks_in_progress.length > 0 && ( <>

Tasks In Progress

)} {/* Suggested Tasks */} {metrics.suggested_tasks.length > 0 && ( <>

Suggested Tasks

)} {/* Fallback Message */} {tasks.length === 0 && (

No tasks available for today.

)}
); }; export default TasksToday;