Files
ims/app/(protected)/hse/incidents/[id]/triage/page.tsx
T
adminandClaude Sonnet 4.6 f591c0be18 feat(db): phase 4 group 6 — server component pages to Drizzle
Converts all 18 server component page files from Supabase client queries
to Drizzle ORM using asAdmin. Adds getSession() + redirect to the three
pages (hse/incidents, hse/incidents/[id], hse/dashboard) that lacked it.
Maps snake_case component prop shapes explicitly where required.

Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
2026-07-23 17:29:22 +08:00

50 lines
1.5 KiB
TypeScript

export const dynamic = 'force-dynamic'
import { notFound, redirect } from 'next/navigation'
import Link from 'next/link'
import { asAdmin } from '@/lib/db/with-user'
import { getSession } from '@/lib/auth/get-session'
import { incidents } from '@/lib/db/schema'
import { eq } from 'drizzle-orm'
import { TriageForm } from '@/components/incidents/triage-form'
interface Props {
params: Promise<{ id: string }>
}
export default async function TriagePage({ params }: Props) {
const { id } = await params
const session = await getSession()
if (!session) redirect(`/login?redirect=/hse/incidents/${id}/triage`)
if (!['hse', 'admin'].includes(session.role)) redirect('/hse/incidents')
const [incident] = await asAdmin(db =>
db.select({
id: incidents.id,
referenceNo: incidents.referenceNo,
status: incidents.status,
severity: incidents.severity,
})
.from(incidents)
.where(eq(incidents.id, id))
.limit(1)
)
if (!incident) notFound()
if (incident.status !== 'reported') redirect(`/hse/incidents/${id}`)
return (
<main className="max-w-lg mx-auto px-4 py-6">
<Link href={`/hse/incidents/${id}`} className="text-sm text-blue-600 hover:underline mb-4 inline-block">
Back to incident
</Link>
<h1 className="text-xl font-bold text-gray-900 mb-1">Triage Incident</h1>
<p className="text-sm text-gray-500 mb-6">{incident.referenceNo ?? id}</p>
<TriageForm
incidentId={id}
currentSeverity={incident.severity}
/>
</main>
)
}