import Link from 'next/link' import { redirect, notFound } from 'next/navigation' import { createClient } from '@/lib/supabase/server' import type { Incident, IncidentUpdateRow } from '@/lib/types' import { IncidentActions } from './incident-actions' import { MarkdownBody } from '@/components/markdown' import { CommentThread } from '@/components/comments/comment-thread' import { loadComments } from '@/components/comments/load-comments' export const dynamic = 'force-dynamic' export default async function IncidentDetailPage({ params }: { params: Promise<{ id: string }> }) { const { id } = await params const supabase = await createClient() const { data: { user } } = await supabase.auth.getUser() if (!user) redirect('/login') const { data: member } = await supabase .from('space_members') .select('id, space_id, role, display_name') .eq('user_id', user.id) .in('status', ['current', 'unverified', 'late']) .maybeSingle() if (!member?.space_id) redirect('/signup') const { data: incidentRaw } = await supabase .from('incidents') .select('*') .eq('id', id) .eq('space_id', member.space_id) .maybeSingle() if (!incidentRaw) notFound() const incident = incidentRaw as unknown as Incident const isAdminOrBoard = member.role === 'admin' || member.role === 'board' const isReporter = incident.reporter_id === member.id const comments = await loadComments(supabase, 'incident', incident.id) const { data: updatesRaw } = await supabase .from('incident_updates') .select('*') .eq('incident_id', incident.id) .order('created_at', { ascending: true }) const updates = (updatesRaw ?? []) as unknown as IncidentUpdateRow[] const decisionMakers = incident.decision_maker_ids.length ? await supabase .from('space_members') .select('id, display_name') .in('id', incident.decision_maker_ids) : { data: [] as Array<{ id: string; display_name: string | null }> } return (
{incident.category} · {incident.severity} · status: {incident.status.replace(/_/g, ' ')} {incident.is_anonymous ? ' · filed anonymously' : ''} {' · '} filed {new Date(incident.created_at).toLocaleString()}
Disposition
Decision: {decisionMakers.data.map(m => m.display_name ?? 'Unknown').join(', ')} {incident.decided_at ? ` · ${new Date(incident.decided_at).toLocaleString()}` : ''}
)}Updates ({updates.length})
{updates.length === 0 ? (No updates posted yet.
) : (