Job Management
This guide covers the Admin ▸ Jobs page implemented in src/pages/AdminJobs.tsx. It explains how the table is populated, what each control does, and how changes persist to Supabase.
Filters
All filters are applied through Supabase queries before results reach the UI:
- Search – Uses the
orhelper to match the entered text againstjob_numberandoperator_name_snapshot(ilikequery). - Status – Maps the dropdown value through
mapFilterToDbStatus. The "Cancelled" option targets thevoidstatus. - Dates –
startDateandendDatefeedgte/ltefilters on thecreated_atcolumn.
React Query caches the result set for five minutes (staleTime: 5 * 60 * 1000) and keeps data available while filtering.
Assigning inspectors
- The Assigned To column renders a
<Select>populated from theinspectorstable joined with matchingprofilesentries. - Choosing a value calls
supabase.from('inspections').update({ inspector_id })and writes a freshupdated_attimestamp. - While the update runs the dropdown is disabled to prevent double submissions (
updatingInspectorIdlocal state). - Selecting Unassigned passes
null, clearing the relationship.
Status updates
- The overflow menu offers actions for Mark as In Progress and Mark as Complete.
- Each action updates the
statuscolumn andupdated_attimestamp. No automatic completeness checks are enforced; administrators decide when to promote the status.
Deleting a job
- Delete Job opens a confirmation dialog. Confirming calls
supabase.from('inspections').delete().eq('id', jobId). - Deleting removes the inspection row and any dependent records through database constraints. There is no undo.
Completeness & issues columns
- After the base query runs the component fetches completed form responses to calculate a percentage (
Math.round(completed / 10 * 100)). has_failurescurrently defaults tofalse. Extend the logic insideAdminJobs.tsxif you need to flag failing responses.
Operator snapshot backfill
If operator_name_snapshot is empty, the component looks up the risk assessment form (form_responses table with template_id = TEMPLATE_IDS.RISK_ASSESSMENT). When it finds a vehicle_operator_name, it updates the inspection row so future queries include the value.
Quick actions
- View Details – Navigates to
/admin/jobs/:jobNumber(read-only dossier). - Edit Job – Navigates to
/admin/jobs/:jobNumber/edit(full edit interface). - New Inspection button – Links to
/inspect/new/wizardto create fresh jobs.
Error handling
- Any Supabase error triggers a destructive toast (
useToast) and logs to the console. - After successful mutations the page calls
adminJobsQuery.refetch()to refresh data.
Pair this guide with the Administration guide to cover the full administrator workflow.