From 370b985375102c4aafe92233b8ed643e8a6cb871 Mon Sep 17 00:00:00 2001 From: weeihan Date: Mon, 13 Jul 2026 11:49:56 +0800 Subject: [PATCH] feat(admin): truck report link + pre-fill form via ?truck_id= Scanning truck QR opens /ims/report?truck_id=, which pre-selects incident_type=transport and the truck in the form. TruckManager shows "Report link / QR target" per truck, mirroring zones. Co-Authored-By: Claude Sonnet 4.6 Claude-Session: https://claude.ai/code/session_01CPf5Rc8QPx6V8KLEEgfKEQ --- app/report/page.tsx | 5 +++-- components/admin/truck-manager.tsx | 29 ++++++++++++++++++---------- components/incidents/report-form.tsx | 7 ++++--- 3 files changed, 26 insertions(+), 15 deletions(-) diff --git a/app/report/page.tsx b/app/report/page.tsx index 580481a..1934f82 100644 --- a/app/report/page.tsx +++ b/app/report/page.tsx @@ -7,11 +7,11 @@ import { LanguageSwitcher } from '@/components/language-switcher' import { OfflineSync } from '@/components/incidents/offline-sync' interface Props { - searchParams: Promise<{ zone?: string }> + searchParams: Promise<{ zone?: string; truck_id?: string }> } export default async function ReportPage({ searchParams }: Props) { - const { zone } = await searchParams + const { zone, truck_id } = await searchParams const supabase = await createClient() const { data, error: authError } = await supabase.auth.getUser() @@ -58,6 +58,7 @@ export default async function ReportPage({ searchParams }: Props) { zoneName={zoneName} siteName={siteName} trucks={(trucks ?? []) as Array<{ id: string; truck_no: string; carrier: string | null }>} + initialTruckId={truck_id ?? null} /> diff --git a/components/admin/truck-manager.tsx b/components/admin/truck-manager.tsx index eb4f68f..d6ecd8c 100644 --- a/components/admin/truck-manager.tsx +++ b/components/admin/truck-manager.tsx @@ -89,16 +89,25 @@ export function TruckManager({ trucks }: Props) { ) : (
    {trucks.map(tk => ( -
  • - {tk.truck_no} - {tk.carrier && ( - {tk.carrier} - )} - {!tk.active && ( - - Inactive - - )} +
  • +
    + {tk.truck_no} + {tk.carrier && ( + {tk.carrier} + )} + {!tk.active && ( + + Inactive + + )} +
    + + Report link / QR target +
  • ))}
diff --git a/components/incidents/report-form.tsx b/components/incidents/report-form.tsx index 1e481d7..9a33e11 100644 --- a/components/incidents/report-form.tsx +++ b/components/incidents/report-form.tsx @@ -11,9 +11,10 @@ interface Props { zoneName: string | null siteName: string | null trucks: Array<{ id: string; truck_no: string; carrier: string | null }> + initialTruckId?: string | null } -export function ReportForm({ zoneToken, trucks }: Props) { +export function ReportForm({ zoneToken, trucks, initialTruckId }: Props) { const router = useRouter() const t = useTranslations('ReportForm') const itLabels = useTranslations('IncidentType') @@ -52,12 +53,12 @@ export function ReportForm({ zoneToken, trucks }: Props) { const [overrideQuality, setOverrideQuality] = useState(false) const [form, setForm] = useState({ - incident_type: '' as IncidentType | '', + incident_type: (initialTruckId ? 'transport' : '') as IncidentType | '', description: '', injury_involved: false, medical_status: '' as MedicalStatus | '', asset_involved: false, - truck_id: '', + truck_id: initialTruckId ?? '', }) const [typeDetails, setTypeDetails] = useState>({})