feat(admin): truck report link + pre-fill form via ?truck_id=

Scanning truck QR opens /ims/report?truck_id=<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 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01CPf5Rc8QPx6V8KLEEgfKEQ
This commit is contained in:
2026-07-13 11:49:56 +08:00
co-authored by Claude Sonnet 4.6
parent f90bf4ed03
commit 370b985375
3 changed files with 26 additions and 15 deletions
+3 -2
View File
@@ -7,11 +7,11 @@ import { LanguageSwitcher } from '@/components/language-switcher'
import { OfflineSync } from '@/components/incidents/offline-sync' import { OfflineSync } from '@/components/incidents/offline-sync'
interface Props { interface Props {
searchParams: Promise<{ zone?: string }> searchParams: Promise<{ zone?: string; truck_id?: string }>
} }
export default async function ReportPage({ searchParams }: Props) { export default async function ReportPage({ searchParams }: Props) {
const { zone } = await searchParams const { zone, truck_id } = await searchParams
const supabase = await createClient() const supabase = await createClient()
const { data, error: authError } = await supabase.auth.getUser() const { data, error: authError } = await supabase.auth.getUser()
@@ -58,6 +58,7 @@ export default async function ReportPage({ searchParams }: Props) {
zoneName={zoneName} zoneName={zoneName}
siteName={siteName} siteName={siteName}
trucks={(trucks ?? []) as Array<{ id: string; truck_no: string; carrier: string | null }>} trucks={(trucks ?? []) as Array<{ id: string; truck_no: string; carrier: string | null }>}
initialTruckId={truck_id ?? null}
/> />
<OfflineSync /> <OfflineSync />
</main> </main>
+19 -10
View File
@@ -89,16 +89,25 @@ export function TruckManager({ trucks }: Props) {
) : ( ) : (
<ul className="divide-y divide-gray-100"> <ul className="divide-y divide-gray-100">
{trucks.map(tk => ( {trucks.map(tk => (
<li key={tk.id} className="flex items-center gap-3 py-2"> <li key={tk.id} className="flex items-center justify-between py-2">
<span className="text-sm font-medium text-gray-900">{tk.truck_no}</span> <div className="flex items-center gap-3">
{tk.carrier && ( <span className="text-sm font-medium text-gray-900">{tk.truck_no}</span>
<span className="text-xs text-gray-500">{tk.carrier}</span> {tk.carrier && (
)} <span className="text-xs text-gray-500">{tk.carrier}</span>
{!tk.active && ( )}
<span className="ml-auto text-xs font-medium px-2 py-0.5 rounded-full bg-gray-100 text-gray-500"> {!tk.active && (
Inactive <span className="text-xs font-medium px-2 py-0.5 rounded-full bg-gray-100 text-gray-500">
</span> Inactive
)} </span>
)}
</div>
<a
href={`/ims/report?truck_id=${tk.id}`}
target="_blank"
className="text-xs text-blue-600 hover:underline"
>
Report link / QR target
</a>
</li> </li>
))} ))}
</ul> </ul>
+4 -3
View File
@@ -11,9 +11,10 @@ interface Props {
zoneName: string | null zoneName: string | null
siteName: string | null siteName: string | null
trucks: Array<{ id: string; truck_no: string; carrier: 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 router = useRouter()
const t = useTranslations('ReportForm') const t = useTranslations('ReportForm')
const itLabels = useTranslations('IncidentType') const itLabels = useTranslations('IncidentType')
@@ -52,12 +53,12 @@ export function ReportForm({ zoneToken, trucks }: Props) {
const [overrideQuality, setOverrideQuality] = useState(false) const [overrideQuality, setOverrideQuality] = useState(false)
const [form, setForm] = useState({ const [form, setForm] = useState({
incident_type: '' as IncidentType | '', incident_type: (initialTruckId ? 'transport' : '') as IncidentType | '',
description: '', description: '',
injury_involved: false, injury_involved: false,
medical_status: '' as MedicalStatus | '', medical_status: '' as MedicalStatus | '',
asset_involved: false, asset_involved: false,
truck_id: '', truck_id: initialTruckId ?? '',
}) })
const [typeDetails, setTypeDetails] = useState<Record<string, string | boolean>>({}) const [typeDetails, setTypeDetails] = useState<Record<string, string | boolean>>({})