export const dynamic = 'force-dynamic' import { createClient } from '@/lib/supabase/server' import { IncidentList, type Incident } from '@/components/incidents/incident-list' import { Pagination } from '@/components/incidents/pagination' import { IncidentFilters, type SiteOption, type TruckOption } from '@/components/incidents/incident-filters' const PAGE_SIZE = 25 export default async function HseInboxPage({ searchParams, }: { searchParams: Promise<{ page?: string; q?: string; status?: string; type?: string; site_id?: string; truck_id?: string }> }) { const supabase = await createClient() const params = await searchParams const page = Math.max(1, Number.parseInt(params.page ?? '1', 10) || 1) const from = (page - 1) * PAGE_SIZE let query = supabase .from('incidents') .select(` id, reference_no, incident_type, status, severity, reported_at, sites (name), zones (name), trucks (truck_no), reporter:users!reported_by (name) `, { count: 'exact' }) .order('reported_at', { ascending: false }) if (params.q) { query = query.or(`reference_no.ilike.%${params.q}%,description.ilike.%${params.q}%`) } if (params.status) query = query.eq('status', params.status) if (params.type) query = query.eq('incident_type', params.type) if (params.site_id) query = query.eq('site_id', params.site_id) if (params.truck_id) query = query.eq('truck_id', params.truck_id) const [{ data: incidents, count }, { data: sites }, { data: trucks }] = await Promise.all([ query.range(from, from + PAGE_SIZE - 1), supabase.from('sites').select('id, name').order('name'), supabase.from('trucks').select('id, truck_no').eq('active', true).order('truck_no'), ]) const siteOptions: SiteOption[] = (sites ?? []).map(s => ({ id: s.id, name: s.name })) const truckOptions: TruckOption[] = (trucks ?? []).map(tk => ({ id: tk.id, truck_no: tk.truck_no })) return (

Incident Inbox

{count ?? incidents?.length ?? 0} incidents
) }