export const dynamic = 'force-dynamic' import { notFound, redirect } from 'next/navigation' import Link from 'next/link' import { createClient } from '@/lib/supabase/server' import { getSession } from '@/lib/auth/get-session' import { VerifyForm } from '@/components/capa/verify-form' import { CloseCapaButton } from '@/components/capa/close-capa-button' interface Props { params: Promise<{ id: string }> } const PRIORITY_BADGE: Record = { low: 'bg-gray-100 text-gray-600', med: 'bg-yellow-100 text-yellow-700', high: 'bg-red-100 text-red-700', } export default async function CapaDetailPage({ params }: Props) { const { id } = await params const session = await getSession() if (!session) redirect(`/login?redirect=/hse/capa/${id}`) const supabase = await createClient() const { data: capa } = await supabase .from('capa_actions') .select(` id, incident_id, root_cause_ref, description, department, due_date, priority, status, completed_at, verified_by, verified_at, created_at, owner_notes, incidents (reference_no, incident_type), owner:users!owner_user_id (name, email) `) .eq('id', id) .single() if (!capa) notFound() const isHse = session && ['hse', 'admin'].includes(session.role) const status = (capa as { status: string }).status return (
← CAPA Board

Incident: {(capa.incidents as unknown as { reference_no: string | null } | null)?.reference_no ?? '—'}

{(capa as { description: string }).description}

{(capa as { priority: string }).priority}

Owner

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

Department

{(capa as { department: string }).department}

Due Date

{(capa as { due_date: string }).due_date}

Status

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

{(capa as { owner_notes: string | null }).owner_notes && (

Owner Notes

{(capa as { owner_notes: string }).owner_notes}

)}
{(capa as { root_cause_ref: string | null }).root_cause_ref && (

Root Cause Reference

{(capa as { root_cause_ref: string }).root_cause_ref}

)} {(capa as { completed_at: string | null }).completed_at && (

Completed: {new Date((capa as { completed_at: string }).completed_at).toLocaleString('en-MY', { timeZone: 'Asia/Kuala_Lumpur' })}

)}
{isHse && status === 'pending_verification' && ( )} {isHse && status === 'verified' && ( )}
) }