Files
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

45 lines
1.3 KiB
TypeScript

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 { CapaForm } from '@/components/capa/capa-form'
interface Props {
params: Promise<{ id: string }>
}
export default async function NewCapaPage({ params }: Props) {
const { id } = await params
const session = await getSession()
if (!session) redirect(`/login?redirect=/hse/incidents/${id}/capa/new`)
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()
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">Add CAPA Action</h1>
<p className="text-sm text-gray-500 mb-6">
{incident.referenceNo ?? id}
</p>
<CapaForm incidentId={id} />
</main>
)
}