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:
2026-07-23 17:29:22 +08:00
co-authored by Claude Sonnet 4.6
parent c2db693d9f
commit f591c0be18
18 changed files with 932 additions and 450 deletions
@@ -1,7 +1,9 @@
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 { CapaForm } from '@/components/capa/capa-form'
interface Props {
@@ -14,10 +16,17 @@ export default async function NewCapaPage({ params }: Props) {
if (!session) redirect(`/login?redirect=/hse/incidents/${id}/capa/new`)
if (!['hse', 'admin'].includes(session.role)) redirect('/hse/incidents')
const supabase = await createClient()
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)
)
const { data: incident } = await supabase
.from('incidents').select('id, reference_no, status').eq('id', id).single()
if (!incident) notFound()
return (
@@ -27,7 +36,7 @@ export default async function NewCapaPage({ params }: Props) {
</Link>
<h1 className="text-xl font-bold text-gray-900 mb-1">Add CAPA Action</h1>
<p className="text-sm text-gray-500 mb-6">
{(incident as { reference_no: string | null }).reference_no ?? id}
{incident.referenceNo ?? id}
</p>
<CapaForm incidentId={id} />
</main>