'use client' import { useState } from 'react' import Link from 'next/link' import { PriorityTag } from '@/components/ui/status-tag' type CapaStatus = 'open' | 'in_progress' | 'overdue' | 'pending_verification' | 'verified' | 'reopened' | 'closed' type CapaAction = { id: string incident_id: string description: string department: string due_date: string priority: 'low' | 'med' | 'high' status: CapaStatus incidents: { reference_no: string | null } | null owner: { name: string } | null } const STATUS_ORDER: CapaStatus[] = ['open', 'in_progress', 'overdue', 'pending_verification', 'verified', 'closed'] const STATUS_LABELS: Record = { open: 'Open', in_progress: 'In Progress', overdue: 'Overdue', pending_verification: 'Pending Verification', verified: 'Verified', reopened: 'Reopened', closed: 'Closed', } const COLUMN_BORDER: Record = { open: 'border-divider', in_progress: 'border-divider', overdue: 'border-accent', pending_verification: 'border-divider', verified: 'border-divider', reopened: 'border-accent', closed: 'border-divider', } interface Props { capas: CapaAction[] } export function CapaBoard({ capas }: Props) { const [view, setView] = useState<'board' | 'table'>('board') const byStatus = STATUS_ORDER.reduce>((acc, s) => { acc[s] = capas.filter(c => c.status === s) return acc }, {} as Record) if (view === 'table') { return (
{capas.map(c => ( ))}
Ref Action Owner Due Priority Status
{(c.incidents as { reference_no: string | null } | null)?.reference_no ?? '—'} {c.description} {(c.owner as { name: string } | null)?.name ?? '—'} {c.due_date} {STATUS_LABELS[c.status]}
) } return (
{STATUS_ORDER.filter(s => s !== 'reopened').map(status => (

{STATUS_LABELS[status]} ({byStatus[status].length})

{byStatus[status].map(c => (

{c.description}

{(c.owner as { name: string } | null)?.name ?? '—'}

Due {c.due_date}

))} {byStatus[status].length === 0 && (

Empty

)}
))}
) }