'use client'; import { use, useState } from 'react'; import Link from 'next/link'; import { useRouter } from 'next/navigation'; import { ArrowLeft, Edit, Trash2, FolderKanban, Calendar, Loader2, ListTodo, } from 'lucide-react'; import { Button } from '@/components/ui/button'; import { Badge } from '@/components/ui/badge'; import { Skeleton } from '@/components/ui/skeleton'; import { Card, CardContent, CardDescription, CardHeader, CardTitle, } from '@/components/ui/card'; import { Dialog, DialogContent, DialogDescription, DialogHeader, DialogTitle, } from '@/components/ui/dialog'; import { AlertDialog, AlertDialogAction, AlertDialogCancel, AlertDialogContent, AlertDialogDescription, AlertDialogFooter, AlertDialogHeader, AlertDialogTitle, } from '@/components/ui/alert-dialog'; import { useProject, useDeleteProject } from '@/lib/hooks/use-projects'; import { useEpics } from '@/lib/hooks/use-epics'; import { ProjectForm } from '@/components/projects/project-form'; import { formatDistanceToNow, format } from 'date-fns'; import { toast } from 'sonner'; interface ProjectDetailPageProps { params: Promise<{ id: string }>; } export default function ProjectDetailPage({ params }: ProjectDetailPageProps) { const { id } = use(params); const router = useRouter(); const [isEditDialogOpen, setIsEditDialogOpen] = useState(false); const [isDeleteDialogOpen, setIsDeleteDialogOpen] = useState(false); const { data: project, isLoading, error } = useProject(id); const { data: epics, isLoading: epicsLoading } = useEpics(id); const deleteProject = useDeleteProject(); const handleDelete = async () => { try { await deleteProject.mutateAsync(id); toast.success('Project deleted successfully'); router.push('/projects'); } catch (error) { const message = error instanceof Error ? error.message : 'Failed to delete project'; toast.error(message); } }; if (isLoading) { return (
); } if (error || !project) { return (
Error Loading Project {error instanceof Error ? error.message : 'Project not found'}
); } return (
{/* Breadcrumb / Back button */} {/* Header */}

{project.name}

{project.key}
Created {formatDistanceToNow(new Date(project.createdAt), { addSuffix: true })}
{/* Content */}
{/* Main content */}
{/* Project details */} Project Details

Description

{project.description ? (

{project.description}

) : (

No description provided

)}

Created

{format(new Date(project.createdAt), 'PPP')}

Last Updated

{format(new Date(project.updatedAt), 'PPP')}

{/* Epics preview */}
Epics
Track major features and initiatives in this project
{epicsLoading ? (
{Array.from({ length: 3 }).map((_, i) => ( ))}
) : epics && epics.length > 0 ? (
{epics.slice(0, 5).map((epic) => (

{epic.title}

{epic.status} {epic.priority}
))} {epics.length > 5 && (

And {epics.length - 5} more...

)}
) : (

No epics yet

)}
{/* Sidebar */}
{/* Quick actions */} Quick Actions {/* Project stats */} Statistics
Total Epics {epics?.length || 0}
Active {epics?.filter((e) => e.status === 'InProgress').length || 0}
Completed {epics?.filter((e) => e.status === 'Done').length || 0}
{/* Edit Project Dialog */} Edit Project Update your project details setIsEditDialogOpen(false)} onCancel={() => setIsEditDialogOpen(false)} /> {/* Delete Confirmation Dialog */} Are you sure? This action cannot be undone. This will permanently delete the project {project.name} and all its associated data (epics, stories, and tasks). Cancel Delete Project
); }