export const dynamic = 'force-dynamic' import Link from 'next/link' import { createClient } from '@/lib/supabase/server' import { redirect, notFound } from 'next/navigation' import { getSession } from '@/lib/auth/get-session' const STATUS_LABELS: Record = { reported: 'Reported', triaged: 'Triaged', investigating: 'Investigating', capa_pending: 'CAPA Pending', verification: 'Verification', closed: 'Closed', } const STATUS_COLORS: Record = { reported: 'bg-gray-100 text-gray-600', triaged: 'bg-yellow-100 text-yellow-800', investigating: 'bg-blue-100 text-blue-700', capa_pending: 'bg-orange-100 text-orange-700', verification: 'bg-purple-100 text-purple-700', closed: 'bg-green-100 text-green-700', } export default async function ReporterIncidentDetail({ params, }: { params: Promise<{ id: string }> }) { const { id } = await params const session = await getSession() if (!session) redirect('/login') const supabase = await createClient() const { data: inc } = await supabase .from('incidents') .select(` id, reference_no, incident_type, status, severity, reported_at, closed_at, description, injury_involved, medical_status, lost_days, sites (name), zones (name), capa_actions (id, description, status, due_date) `) .eq('id', id) .eq('reported_by', session.sub) .single() if (!inc) notFound() const siteName = (inc.sites as unknown as { name: string } | null)?.name const zoneName = (inc.zones as unknown as { name: string } | null)?.name const capas = (inc.capa_actions as unknown as Array<{ id: string; description: string; status: string; due_date: string | null }>) ?? [] return (
← My Reports

{inc.reference_no ?? inc.id.slice(0, 8)}

{inc.incident_type?.replace(/_/g, ' ')}

{STATUS_LABELS[inc.status] ?? inc.status}
{siteName &&

Site

{siteName}

} {zoneName &&

Zone

{zoneName}

} {inc.severity &&

Severity

{inc.severity} / 5

} {inc.reported_at && (

Reported

{new Date(inc.reported_at as string).toLocaleDateString('en-MY')}

)} {inc.closed_at && (

Closed

{new Date(inc.closed_at as string).toLocaleDateString('en-MY')}

)}
{inc.description && (

Description

{inc.description}

)}
{capas.length > 0 && (

Corrective Actions ({capas.length})

{capas.map(c => (

{c.description}

{c.status.replace(/_/g, ' ')}
))}
)}
) }