/** * @file app/(app)/dashboard/modal/TaskModal.tsx * @description Client component rendering a detailed modal overlay for viewing task metadata, status, assignees, and quick actions with ESC key support. */ "use client"; import { useEffect } from "react"; import { Task, PRIORITY_CONFIG } from "@/lib/types/task"; import { getFullName, getStatusColor } from "@/lib/utils/user"; import { X, CalendarDays, AlertCircle, User, Users, FileText, Pencil, Trash2, } from "lucide-react"; import { useRouter } from "next/navigation"; /** * Properties for the TaskModal component. * * @interface TaskModalProps * @property {Task | null} task - The selected task object to display, or null if hidden. * @property {() => void} onClose - Callback handler to close the modal dialog. * @property {(taskId: string) => void} [onDelete] - Optional callback function triggered when deleting the task. */ interface TaskModalProps { task: Task | null; onClose: () => void; onDelete?: (taskId: string) => void; } /** * Renders a full task detail modal with status indicators, priority details, description, assignees, and creator-only action buttons. * Integrates keydown listeners to dismiss the modal on pressing the Escape key. * * @param {TaskModalProps} props - The component props. * @returns {JSX.Element | null} The rendered modal component or null when no task is selected. */ export default function TaskModal({ task, onClose, onDelete }: TaskModalProps) { const router = useRouter(); useEffect(() => { /** * Keyboard event handler closing the modal dialog when pressing the Escape key. * * @param {KeyboardEvent} e - The global window keydown event. */ const handleKeyDown = (e: KeyboardEvent) => { if (e.key === "Escape") { onClose(); } }; window.addEventListener("keydown", handleKeyDown); return () => { window.removeEventListener("keydown", handleKeyDown); }; }, [onClose]); if (!task) return null; const priorityConfig = task.priority && PRIORITY_CONFIG[task.priority]; const isOverdue = task.dueDate && new Date(task.dueDate) < new Date() && task.status !== "done"; return (
Creator
{getFullName(task.creator.firstName, task.creator.lastName)}
{isOverdue ? "Overdue Due Date" : "Due Date"}
{task.dueDate ? `${new Date(task.dueDate).toLocaleDateString("de-DE", { day: "2-digit", month: "short", year: "numeric", })} (${new Date(task.dueDate).toLocaleTimeString( "de-DE", { hour: "2-digit", minute: "2-digit", }, )})` : "No due date"}
No assignees assigned to this task.
)}