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>
This commit is contained in:
@@ -2,8 +2,10 @@ export const dynamic = 'force-dynamic'
|
||||
|
||||
import { notFound, redirect } from 'next/navigation'
|
||||
import Link from 'next/link'
|
||||
import { createClient } from '@/lib/supabase/server'
|
||||
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 {
|
||||
@@ -16,13 +18,17 @@ export default async function TriagePage({ params }: Props) {
|
||||
if (!session) redirect(`/login?redirect=/hse/incidents/${id}/triage`)
|
||||
if (!['hse', 'admin'].includes(session.role)) redirect('/hse/incidents')
|
||||
|
||||
const supabase = await createClient()
|
||||
|
||||
const { data: incident } = await supabase
|
||||
.from('incidents')
|
||||
.select('id, reference_no, incident_type, status, severity')
|
||||
.eq('id', id)
|
||||
.single()
|
||||
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}`)
|
||||
@@ -33,10 +39,10 @@ export default async function TriagePage({ params }: Props) {
|
||||
← 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.reference_no ?? id}</p>
|
||||
<p className="text-sm text-gray-500 mb-6">{incident.referenceNo ?? id}</p>
|
||||
<TriageForm
|
||||
incidentId={id}
|
||||
currentSeverity={(incident as { severity: number | null }).severity}
|
||||
currentSeverity={incident.severity}
|
||||
/>
|
||||
</main>
|
||||
)
|
||||
|
||||
Reference in New Issue
Block a user