feat: transport incidents with truck number support

- DB: trucks table + incidents.truck_id FK + transport enum value
- Validation: transport type requires truck_id
- Create API: validates truck exists/active, persists truck_id
- Report form: truck dropdown shown when type=transport (required)
- Admin: TruckManager CRUD + /api/admin/trucks route
- Detail: trucks join surfaced in incident-detail + detail page query
- Inbox (HSE + supervisor): truck filter, transport in TYPE_OPTIONS,
  fixed stale enum values (dropped dangerous_occurrence/mhe_asset/occupational_disease)
- List: transport label + truck number badge in rows
- i18n: transport + truckLabel/truckPlaceholder in en/ms/zh

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 10:56:07 +08:00
co-authored by Claude Sonnet 4.6
parent 6c1ad71643
commit f90bf4ed03
16 changed files with 266 additions and 26 deletions
+10
View File
@@ -47,6 +47,7 @@ export async function POST(request: Request) {
injury_involved: body.injury_involved === 'true' || body.injury_involved === true,
asset_involved: body.asset_involved === 'true' || body.asset_involved === true,
medical_status: body.medical_status as MedicalStatus | undefined || undefined,
truck_id: (body.truck_id as string) || null,
}
const validation = validateIncidentInput(input)
@@ -54,6 +55,14 @@ export async function POST(request: Request) {
return NextResponse.json({ error: 'Validation failed', details: validation.errors }, { status: 422 })
}
let truckId: string | null = null
if (input.incident_type === 'transport') {
const { data: truck } = await supabase
.from('trucks').select('id').eq('id', input.truck_id).eq('active', true).single()
if (!truck) return NextResponse.json({ error: 'Validation failed', details: ['truck not found or inactive'] }, { status: 422 })
truckId = truck.id
}
let rawDetails: Record<string, unknown> | undefined
if (typeof body.type_details === 'string' && body.type_details) {
try {
@@ -91,6 +100,7 @@ export async function POST(request: Request) {
asset_involved: input.asset_involved,
medical_status: input.injury_involved ? (input.medical_status ?? 'none') : null,
type_details: detailsCheck.sanitized,
truck_id: truckId,
})
.select('id, reference_no')
.single()