Prestart CRUD
Create, view, edit, publish, and delete prestart checklists. Prestarts start as drafts and can be published to lock core fields.
Create Prestart
- User navigates to
/admin/prestarts/newor/dashboard/prestarts/new - RSC page reads
org_idandproject_idfrom cookies, fetchescurrentUserIdviagetCurrentUser() <PrestartForm mode="create">renders with:- Supervisor dropdown — project members with role
supervisor,senior_supervisor,master_admin, ororganisational_manager. Auto-selects current user if they’re a supervisor. - Date & Time —
datetime-localinput, defaults to now - Toolbox Talk Duration — select: 0/15/30/60 minutes
- Shift Type — select: Day/Afternoon/Night
- Site Location — free-text input
- Supervisor dropdown — project members with role
- On “Create Draft”, the server action validates via Zod, calls
POST /v1/orgs/{orgId}/projects/{projectId}/prestarts - Go handler validates membership + supervisor role, inserts into
prestartstable - On success, user is redirected to the detail page (
/admin/prestarts/{id})
List Prestarts
The prestart list page (/admin/prestarts or /dashboard/prestarts) is a React Server Component that fetches data server-side:
- RSC calls
listPrestarts(orgId, projectId, { status, page, page_size })via server action - Go handler executes
ListProjectPrestartsquery with filters and pagination <PrestartTableV2>renders with columns: Status (badge), Date, Shift (badge), Supervisor, Location, Duration, Activities count, Sign-Ons count- URL-based filtering via status dropdown (All/Draft/Published)
- Pagination controls at the bottom
- Row click navigates to detail page
List Query
SELECT p.id, u.name AS supervisor_name, p.prestart_datetime, p.duration,
p.shift_type, p.site_location, p.status,
(SELECT COUNT(*) FROM activities a WHERE a.prestart_id = p.id AND a.deleted_at IS NULL) AS activity_count,
(SELECT COUNT(*) FROM prestart_sign_ons s WHERE s.prestart_id = p.id) AS sign_on_count,
p.created_at
FROM prestarts p
JOIN users u ON u.id = p.supervisor_id
WHERE p.org_id = $1 AND p.project_id = $2 AND p.deleted_at IS NULL
ORDER BY p.prestart_datetime DESC
LIMIT $3 OFFSET $4View Prestart Detail
The detail page (/admin/prestarts/[prestartId]) renders <PrestartDetail>, a client component that fetches the full prestart via useQuery:
- Details tab — Draft: inline edit form; Published: read-only field grid
- Activities tab — Activity cards with description, resource chips, add/edit/delete
- Sign-Ons tab — List of signed-on users with role badges, add/remove
- Comments tab —
<PrestartComments>component with input + history
The detail query returns the prestart with all nested data (activities with resources, sign-ons with user info, comments, files) assembled in the Go service from multiple queries.
Beside Back to Prestarts, the previous and next day buttons step to the same supervisor’s prestart on the nearest earlier or later day, on the same shift — see Previous & Next Day.
Update Prestart (Draft Only)
Draft prestarts can be edited inline on the Details tab:
- User modifies fields in the
<DraftDetailsEditor>section - On “Save Changes”, calls
updatePrestartserver action - Go handler checks
status = 'draft', usesCOALESCEpattern for partial updates:
UPDATE prestarts SET
supervisor_id = COALESCE(sqlc.narg('supervisor_id'), supervisor_id),
prestart_datetime = COALESCE(sqlc.narg('prestart_datetime'), prestart_datetime),
...
WHERE id = $1 AND org_id = $2 AND status = 'draft' AND deleted_at IS NULLPublish Prestart
- User clicks “Publish” button (visible only on draft prestarts)
- Confirmation dialog: “Core fields will be locked”
- Server action calls
POST /prestarts/{id}/publish - Go handler sets
status = 'published'andpublished_at = NOW() - TanStack Query invalidation refreshes the detail view with locked fields
Delete Prestart
- User clicks “Delete” button
- Confirmation dialog
- Server action calls
DELETE /prestarts/{id} - Go handler sets
deleted_at = NOW()(soft delete) - User redirected back to the prestart list
Security
- Create: Only supervisors, senior supervisors, and admins can create prestarts
- Edit/Publish/Delete: Only the prestart creator or an admin
- View: Any project member can view any prestart in their project
- All queries include
AND org_id = $org_idfor tenant isolation
Key Files
| File | Purpose |
|---|---|
backend/db/queries/prestarts.sql | SQL queries for CRUD + publish |
backend/api/internal/prestart/service.go | Business logic, assembly |
backend/api/internal/prestart/handler.go | HTTP handlers |
apps/web/src/actions/prestarts.ts | Server actions with Zod validation |
apps/web/src/app/_components/prestart-form.tsx | Create/edit form |
apps/web/src/app/_components/prestart-detail.tsx | Detail view with tabs |
apps/web/src/app/admin/prestarts/_components/prestart-table-v2.tsx | List table |