'use client'; import { use, useState } from 'react'; import Link from 'next/link'; import { useRouter } from 'next/navigation'; import { ArrowLeft, Plus, Edit, Trash2, Loader2, ListTodo, Calendar, Clock, } 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 } from '@/lib/hooks/use-projects'; import { useEpics, useDeleteEpic } from '@/lib/hooks/use-epics'; import { EpicForm } from '@/components/epics/epic-form'; import { formatDistanceToNow } from 'date-fns'; import { toast } from 'sonner'; import type { Epic, WorkItemStatus, WorkItemPriority } from '@/types/project'; interface EpicsPageProps { params: Promise<{ id: string }>; } export default function EpicsPage({ params }: EpicsPageProps) { const { id: projectId } = use(params); const router = useRouter(); const [isCreateDialogOpen, setIsCreateDialogOpen] = useState(false); const [editingEpic, setEditingEpic] = useState(null); const [deletingEpicId, setDeletingEpicId] = useState(null); const { data: project, isLoading: projectLoading } = useProject(projectId); const { data: epics, isLoading: epicsLoading, error } = useEpics(projectId); const deleteEpic = useDeleteEpic(); const handleDelete = async () => { if (!deletingEpicId) return; try { await deleteEpic.mutateAsync(deletingEpicId); setDeletingEpicId(null); } catch (error) { const message = error instanceof Error ? error.message : 'Failed to delete epic'; toast.error(message); } }; const getStatusColor = (status: WorkItemStatus) => { switch (status) { case 'Backlog': return 'secondary'; case 'Todo': return 'outline'; case 'InProgress': return 'default'; case 'Done': return 'success' as any; default: return 'secondary'; } }; const getPriorityColor = (priority: WorkItemPriority) => { switch (priority) { case 'Low': return 'bg-blue-100 text-blue-700 hover:bg-blue-100'; case 'Medium': return 'bg-yellow-100 text-yellow-700 hover:bg-yellow-100'; case 'High': return 'bg-orange-100 text-orange-700 hover:bg-orange-100'; case 'Critical': return 'bg-red-100 text-red-700 hover:bg-red-100'; default: return 'secondary'; } }; if (projectLoading || epicsLoading) { return (
{Array.from({ length: 6 }).map((_, i) => ( ))}
); } if (error || !project) { return (
Error Loading Epics {error instanceof Error ? error.message : 'Failed to load epics'}
); } return (
{/* Breadcrumb */}
Projects / {project.name} / Epics
{/* Header */}

Epics

Manage epics for {project.name}

{/* Epics Grid */} {epics && epics.length > 0 ? (
{epics.map((epic) => (
{epic.name}
{epic.status} {epic.priority}
{epic.description ? (

{epic.description}

) : (

No description

)}
{epic.estimatedHours && (
Estimated: {epic.estimatedHours}h {epic.actualHours && ( / Actual: {epic.actualHours}h )}
)}
Created {formatDistanceToNow(new Date(epic.createdAt), { addSuffix: true })}
))}
) : ( No epics yet Get started by creating your first epic to organize major features and initiatives )} {/* Create Epic Dialog */} Create New Epic Add a new epic to organize major features and initiatives setIsCreateDialogOpen(false)} onCancel={() => setIsCreateDialogOpen(false)} /> {/* Edit Epic Dialog */} setEditingEpic(null)}> Edit Epic Update the epic details {editingEpic && ( setEditingEpic(null)} onCancel={() => setEditingEpic(null)} /> )} {/* Delete Confirmation Dialog */} setDeletingEpicId(null)} > Are you sure? This action cannot be undone. This will permanently delete the epic and all its associated stories and tasks. Cancel {deleteEpic.isPending ? ( <> Deleting... ) : ( 'Delete Epic' )}
); }