Notify chauffeurs when an accepted job's details change #3
Loading…
Add table
Add a link
Reference in a new issue
No description provided.
Delete branch "chauffeur-updates"
Deleting a branch is permanent. Although the deleted branch may continue to exist for a short time before it actually gets removed, it CANNOT be undone in most cases. Continue?
If office staff edits pickup time, address, vehicle, or similar details on a job a chauffeur has already accepted, the chauffeur now gets a simple email linking to their updated chauffeur PDF, instead of finding out on the day.
Scope, deliberately kept tight:
BookingCarrows that arechauffeurStatus === "ACCEPTED"both before and after the edit, with the same chauffeur throughout.Implementation:
"job-updated-chauffeur"email template (src/lib/email-templates.ts) — simple body, links toBooking.chauffeurSheetUrl. Editable under Settings → Email Templates like the others.src/lib/job-change-notification.ts— pure trigger-detection (findAcceptedCarsWithChanges, unit tested) plus the fire-and-forget sender, mirroring the existing accept/decline notification pattern inoffer-response.ts.PUT /api/bookings/[id], right after the transaction resolves, never awaited into the response.Verified: build/lint clean, 186/186 tests passing (12 new). Also confirmed live in a running dev server — an ACCEPTED job's pickup time change correctly triggered a send attempt (only failed on the sandbox's missing SMTP server, logged cleanly, save unaffected), and an unrelated internal-field-only edit (
carCost) correctly triggered nothing.Follow-up commit (v1.87.1): the trigger now watches every field the chauffeur PDF actually renders, not a hand-picked subset.
dropoffTime/routefrom the per-car watch list —generateChauffeurPdfnever shows them, only a computed pickup+duration finish time.specialInstructions-only edit correctly notified the accepted chauffeur; anotes-only edit (not on the PDF) correctly triggered nothing.Bug found. If a booking has 2 accepted cars going to the same chauffeur (or even the same booking with 2 different accepted chauffeurs, which is correct — but if it was the same person on both cars, they'd get 2 near-identical emails for one edit)
Bug fix (v1.87.2), found via real testing: editing specialInstructions on a booking with 2 accepted cars sent 2 emails instead of 1, because the booking-level trigger flagged each accepted
BookingCarrow independently with no dedup — if both rows belong to the same chauffeur, they got the email twice.notifyChauffeursOfJobChangesnow dedupes recipients by chauffeur email before sending (newdedupeRecipientsByEmail, unit tested), so one edit now produces exactly one email per chauffeur regardless of how many of their accepted cars were affected. Two different chauffeurs on the same booking still each get their own email, correctly.Unrelated: the audit-log entry for that same save also showed
payments: — → [object Object]. That's not from anything in this PR — it's pre-existingcomputePaymentsDiffaudit code insrc/lib/audit.ts. Flagging separately, not fixed here.new instead of auto email. have a option to enable it or disable or when click update booking ask if to send email to chauffeur
Notify chauffeurs when an accepted job's details changeto WIP: Notify chauffeurs when an accepted job's details changeNew commit (v1.88.0), addressing the request for an enable/disable/ask option: added a "Notify chauffeurs when an accepted job changes" setting under Settings → Email Templates, with three modes:
POST /api/bookings/[id]/notify-chauffeursendpoint to actually send.New
SystemSettings.chauffeurJobChangeNotifyModecolumn (migration included), select control inEmailSettingsForm.tsx, and mode branching in thePUT /api/bookings/[id]handler.Also fixed a real build break found while implementing this:
schemas.tsis imported by client components (form validation), and pulling the new mode constant fromjob-change-notification.tsdragged the whole server-onlynodemailerstack into the client bundle, breakingnpm run build. Moved the constant to a dependency-freesrc/lib/notify-mode.tsleaf module.Verified: 199 tests passing, build/lint clean, and all three modes tested live against the running API — Auto sends immediately, Ask correctly defers and the confirm endpoint sends on request, Off suppresses entirely with no pending notification and no send attempt.
This job's details changed for a chauffeur who already accepted it. Send an update email to Stewart Test?
cancel or send email
when click cancel the job does not save till you click update booking again.
change cancel to don't send and update booking
UX fix (v1.88.1) for the "the job does not save till you click update booking again" report: that wasn't actually a save bug — the booking is fully saved before the notify dialog ever appears (the dialog only decides whether to also email the chauffeur). The generic "Cancel" label just read as "cancel the save," so people re-clicked Update Booking thinking nothing had happened.
Dialog now opens with "Booking saved. ..." and its cancel button reads "Don't send" instead of "Cancel" (new optional
cancelLabelprop onConfirmDialog). No change to the actual save/send logic — confirmed via the earlier API-level testing that the PUT already commits before the dialog is shown, independent of what the office clicks next.All Test ok
WIP: Notify chauffeurs when an accepted job's details changeto Notify chauffeurs when an accepted job's details change