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>
58 lines
1.8 KiB
TypeScript
58 lines
1.8 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, investigations } from '@/lib/db/schema'
|
|
import { eq, desc } from 'drizzle-orm'
|
|
import { InvestigationForm } from '@/components/incidents/investigation-form'
|
|
|
|
interface Props {
|
|
params: Promise<{ id: string }>
|
|
}
|
|
|
|
export default async function InvestigationPage({ params }: Props) {
|
|
const { id } = await params
|
|
const session = await getSession()
|
|
if (!session) redirect(`/login?redirect=/hse/incidents/${id}/investigation`)
|
|
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,
|
|
})
|
|
.from(incidents)
|
|
.where(eq(incidents.id, id))
|
|
.limit(1)
|
|
)
|
|
|
|
if (!incident) notFound()
|
|
if (!['triaged', 'investigating'].includes(incident.status))
|
|
redirect(`/hse/incidents/${id}`)
|
|
|
|
const [existing] = await asAdmin(db =>
|
|
db.select({ id: investigations.id })
|
|
.from(investigations)
|
|
.where(eq(investigations.incidentId, id))
|
|
.orderBy(desc(investigations.createdAt))
|
|
.limit(1)
|
|
)
|
|
|
|
return (
|
|
<main className="max-w-2xl 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">Investigation Workspace</h1>
|
|
<p className="text-sm text-gray-500 mb-6">{incident.referenceNo ?? id}</p>
|
|
<InvestigationForm
|
|
incidentId={id}
|
|
existingInvestigationId={existing?.id ?? null}
|
|
/>
|
|
</main>
|
|
)
|
|
}
|