"use client"; import { useEffect, useState } from "react"; import { useParams, useRouter } from "next/navigation"; import Link from "next/link"; import { ArrowLeft, Trash2, CheckCircle, Clock, Circle } from "lucide-react"; import { Button } from "@/components/ui/button"; import { Card, CardContent, CardDescription, CardHeader, CardTitle, } from "@/components/ui/card"; import { Badge } from "@/components/ui/badge"; import { Dialog, DialogContent, DialogDescription, DialogFooter, DialogHeader, DialogTitle, DialogTrigger, } from "@/components/ui/dialog"; import { Task, fetchTask, deleteTask } from "@/lib/api"; const statusIcons = { pending: Circle, in_progress: Clock, completed: CheckCircle, }; const statusColors = { pending: "bg-yellow-500/20 text-yellow-400 border-yellow-500/30", in_progress: "bg-blue-500/20 text-blue-400 border-blue-500/30", completed: "bg-green-500/20 text-green-400 border-green-500/30", }; const priorityColors = { low: "bg-slate-500/20 text-slate-400 border-slate-500/30", medium: "bg-orange-500/20 text-orange-400 border-orange-500/30", high: "bg-red-500/20 text-red-400 border-red-500/30", }; export default function TaskDetail() { const params = useParams(); const router = useRouter(); const [task, setTask] = useState(null); const [loading, setLoading] = useState(true); const [error, setError] = useState(null); const [deleteDialogOpen, setDeleteDialogOpen] = useState(false); useEffect(() => { const loadTask = async () => { try { setLoading(true); const id = parseInt(params.id as string); const data = await fetchTask(id); setTask(data); setError(null); } catch (err) { setError(err instanceof Error ? err.message : "Failed to load task"); } finally { setLoading(false); } }; if (params.id) { loadTask(); } }, [params.id]); const handleDelete = async () => { if (!task) return; try { await deleteTask(task.id); router.push("/"); } catch (err) { setError(err instanceof Error ? err.message : "Failed to delete task"); } }; const formatDate = (dateString: string) => { return new Date(dateString).toLocaleString("en-US", { dateStyle: "medium", timeStyle: "short", }); }; if (loading) { return (
Loading task...
); } if (error || !task) { return (
Back to Dashboard

{error || "Task not found"}

); } const StatusIcon = statusIcons[task.status]; return (
Back to Dashboard
{task.title} Created {formatDate(task.createdAt)}
Delete Task Are you sure you want to delete this task? This action cannot be undone.
{task.status.replace("_", " ")} {task.priority} priority
{task.description && (

Description

{task.description}

)}

Created

{formatDate(task.createdAt)}

Last Updated

{formatDate(task.updatedAt)}

); }