import Link from 'next/link' import { redirect } from 'next/navigation' import { createClient } from '@/lib/supabase/server' import type { Incident, IncidentStatus } from '@/lib/types' export const dynamic = 'force-dynamic' const STATUS_STYLE: Record = { received: 'text-orange-600 bg-orange-50', under_review: 'text-blue-600 bg-blue-50', decided: 'text-primary bg-primary/10', appealed: 'text-purple-600 bg-purple-50', closed: 'text-muted-foreground bg-muted', } export default async function IncidentsPage() { const supabase = await createClient() const { data: { user } } = await supabase.auth.getUser() if (!user) redirect('/login') const { data: member } = await supabase .from('space_members') .select('space_id, role') .eq('user_id', user.id) .in('status', ['current', 'unverified', 'late']) .maybeSingle() if (!member?.space_id) redirect('/signup') const isAdminOrBoard = member.role === 'admin' || member.role === 'board' // RLS filters to admin/board view or reporter view automatically. const { data: incidents } = await supabase .from('incidents') .select('*') .eq('space_id', member.space_id) .order('created_at', { ascending: false }) const list = (incidents ?? []) as unknown as Incident[] const open = list.filter(i => ['received', 'under_review'].includes(i.status)) const decided = list.filter(i => ['decided', 'appealed'].includes(i.status)) const closed = list.filter(i => i.status === 'closed') return (

Incidents

File a report
{!isAdminOrBoard && (

You see incidents you have reported here. Admins and board members see all incidents in their space.

)}
) } function Section({ title, empty, rows }: { title: string; empty: string; rows: Incident[] }) { return (

{title}

{rows.length === 0 ? (
{empty}
) : ( rows.map(i => (

{i.title}

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

{i.category} · {i.severity} {i.is_anonymous ? ' · anonymous' : ''} {' · '} filed {new Date(i.created_at).toLocaleDateString('en-US', { month: 'short', day: 'numeric' })}

{i.sla_response_by && i.status === 'received' && ( response by {new Date(i.sla_response_by).toLocaleDateString('en-US', { month: 'short', day: 'numeric' })} )}
)) )}
) }