export const dynamic = 'force-dynamic' import Link from 'next/link' import { createClient } from '@/lib/supabase/server' import { StatCard } from '@/components/dashboard/stat-card' const TYPE_LABELS: Record = { injury: 'Injury', near_miss: 'Near Miss', hazard: 'Hazard', asset_damage: 'Asset Damage', environmental: 'Environmental', security: 'Security', fire: 'Fire', } export default async function HseDashboardPage() { const supabase = await createClient() const { data: incidents } = await supabase .from('incidents') .select('id, status, incident_type, sites (name)') const rows = incidents ?? [] const total = rows.length const closed = rows.filter(r => r.status === 'closed').length const open = total - closed const by_type: Record = {} for (const r of rows) { by_type[r.incident_type] = (by_type[r.incident_type] ?? 0) + 1 } const siteMap: Record = {} for (const r of rows) { const name = (r.sites as { name: string } | null)?.name ?? 'Unknown' siteMap[name] = (siteMap[name] ?? 0) + 1 } const by_site = Object.entries(siteMap).map(([name, count]) => ({ name, count })) .sort((a, b) => b.count - a.count) return (

Dashboard

View all incidents →

By Incident Type

{Object.entries(by_type).sort((a, b) => b[1] - a[1]).map(([type, count]) => (
{TYPE_LABELS[type] ?? type}
0 ? `${(count / total) * 100}%` : '0%' }} />
{count}
))} {Object.keys(by_type).length === 0 && (

No incidents yet

)}

By Site

{by_site.map(({ name, count }) => (
{name} {count}
))} {by_site.length === 0 &&

No data

}
) }