export const dynamic = 'force-dynamic' import { redirect } from 'next/navigation' import { asAdmin } from '@/lib/db/with-user' import { getSession } from '@/lib/auth/get-session' import { zones, sites, trucks } from '@/lib/db/schema' import { eq, asc } from 'drizzle-orm' import { ReportForm } from '@/components/incidents/report-form' import { LanguageSwitcher } from '@/components/language-switcher' import { OfflineSync } from '@/components/incidents/offline-sync' interface Props { searchParams: Promise<{ zone?: string; truck_id?: string }> } export default async function ReportPage({ searchParams }: Props) { const { zone, truck_id } = await searchParams const session = await getSession() if (!session) redirect(`/login?redirect=/report${zone ? `?zone=${zone}` : ''}`) let zoneName: string | null = null let siteName: string | null = null if (zone) { const [zd] = await asAdmin(db => db.select({ name: zones.name, siteName: sites.name, }) .from(zones) .leftJoin(sites, eq(zones.siteId, sites.id)) .where(eq(zones.qrCodeToken, zone)) .limit(1) ) if (zd) { zoneName = zd.name siteName = zd.siteName ?? null } } const truckRows = await asAdmin(db => db.select({ id: trucks.id, truckNo: trucks.truckNo, carrier: trucks.carrier, }) .from(trucks) .where(eq(trucks.active, true)) .orderBy(asc(trucks.truckNo)) ) const truckList = truckRows.map(t => ({ id: t.id, truck_no: t.truckNo, carrier: t.carrier ?? null, })) return (

{/* will be translated via ReportForm */}Report an Incident

{zoneName ? (

{siteName ?? 'Unknown Site'} — {zoneName}

) : (

No zone detected — zone will not be recorded

)}
) }