feat(report): site and zone picker when no QR zone is detected
Co-Authored-By: Claude Sonnet 5.5 <noreply@anthropic.com>
This commit is contained in:
+27
-6
@@ -3,8 +3,9 @@ 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 { zones, sites, trucks, users } from '@/lib/db/schema'
|
||||
import { eq, asc, and } from 'drizzle-orm'
|
||||
import { groupSites } from '@/lib/report/zones'
|
||||
import { ReportForm } from '@/components/incidents/report-form'
|
||||
import { LanguageSwitcher } from '@/components/language-switcher'
|
||||
import { OfflineSync } from '@/components/incidents/offline-sync'
|
||||
@@ -55,6 +56,26 @@ export default async function ReportPage({ searchParams }: Props) {
|
||||
carrier: t.carrier ?? null,
|
||||
}))
|
||||
|
||||
const zoneRows = await asAdmin(db =>
|
||||
db.select({
|
||||
siteId: sites.id,
|
||||
siteName: sites.name,
|
||||
zoneId: zones.id,
|
||||
zoneName: zones.name,
|
||||
token: zones.qrCodeToken,
|
||||
})
|
||||
.from(zones)
|
||||
.innerJoin(sites, eq(zones.siteId, sites.id))
|
||||
.where(and(eq(zones.active, true), eq(sites.active, true)))
|
||||
.orderBy(asc(sites.name), asc(zones.name))
|
||||
)
|
||||
const siteOptions = groupSites(zoneRows)
|
||||
|
||||
const [me] = await asAdmin(db =>
|
||||
db.select({ siteId: users.siteId }).from(users).where(eq(users.id, session.sub)).limit(1)
|
||||
)
|
||||
const defaultSiteId = me?.siteId ?? ''
|
||||
|
||||
return (
|
||||
<main className="min-h-screen bg-gray-50 py-6 px-4 max-w-lg mx-auto">
|
||||
<div className="mb-6">
|
||||
@@ -62,18 +83,18 @@ export default async function ReportPage({ searchParams }: Props) {
|
||||
<h1 className="text-2xl font-bold text-gray-900">{/* will be translated via ReportForm */}Report an Incident</h1>
|
||||
<LanguageSwitcher />
|
||||
</div>
|
||||
{zoneName ? (
|
||||
{zoneName && (
|
||||
<p className="text-sm text-gray-600 mt-1">
|
||||
{siteName ?? 'Unknown Site'} — {zoneName}
|
||||
</p>
|
||||
) : (
|
||||
<p className="text-sm text-accent-700 mt-1">No zone detected — zone will not be recorded</p>
|
||||
)}
|
||||
</div>
|
||||
<ReportForm
|
||||
zoneToken={zone ?? null}
|
||||
zoneToken={zoneName ? (zone ?? null) : null}
|
||||
zoneName={zoneName}
|
||||
siteName={siteName}
|
||||
sites={siteOptions}
|
||||
defaultSiteId={defaultSiteId}
|
||||
trucks={truckList}
|
||||
initialTruckId={truck_id ?? null}
|
||||
/>
|
||||
|
||||
Reference in New Issue
Block a user