Skip to content

fix(booking): a confirmed booking is a final state on all three surfaces (#268) - #284

Open
dominik-myszkowski wants to merge 2 commits into
Calnode:mainfrom
dominik-myszkowski:fix/final-confirmation-state
Open

dominik-myszkowski wants to merge 2 commits into
Calnode:mainfrom
dominik-myszkowski:fix/final-confirmation-state

Conversation

@dominik-myszkowski

Copy link
Copy Markdown
Contributor

The bug half of #268, on all three surfaces as you asked. After a booking is confirmed, the confirmation is a final state: nothing leads back into the form, and "Book another time" starts over cleanly. The redirect_url half will follow as its own PR.

Booking page (book.html)

  • finalize() runs on success and on the return from Stripe Checkout (?paid=1).
    • It disables the calendar, month navigation, timezone and submit button, and resets the form.
    • Every handler (day, slot, back, month, timezone, submit) checks the finalized flag, rather than relying on the markup alone.
  • The success path no longer re-enables the submit button, which was the actual cause.
  • A submitting flag also drops a second submit while the first request is in flight (double click, Enter).
  • Book another time is a link to a fresh load of the page, without paid/session_id but keeping other params such as lang. A reload is the only reset where no picked day, slot or host state can survive.

Embed widget (embed.js)

  • In the confirm view the calendar renders with its days and month navigation disabled, and the card gets is-final.
  • The submit handler refuses while in flight or once confirmed.
  • Book another time is a button that resets the widget's own state and reloads the month, so the slot just taken is gone. As you suggested, it never navigates the host page.

Manage page (manage.html)

You flagged this one, and here is how I read it. Its success views (rescheduled, cancelled) were already almost final: the calendar column hides, and the views have no buttons. What was missing was a guard. The page's CURRENT_ISO and picked slot describe the booking as it was, so acting on them again would be wrong. Now:

  • showView no longer leaves a success view;
  • neither confirm handler can send again.

I deliberately did not add a "book another time" link here: in a reschedule context there is nothing sensible for it to mean, and a reload shows the booking as it now is.

Shared bits

  • booking.css: .book-another, styled once for the page link and the widget button, plus .card.is-final .cal-col { opacity: .5 }.
  • New booker key book_another_time in all 12 locale files (the non-English ones are drafts, like the rest).
  • ARCHITECTURE §9 and a CHANGELOG Fixed entry.

Tests

  • TestBookPage_confirmationIsFinal is the "second submit is refused" test you asked for. It renders the real book.html, extracts the page script, and runs it under node against a small fake DOM (testdata/book_final_state.js). It skips without node, like the CLDR cross-check, and node is in the CI job. Two scenarios:
    • submit: pick a day and slot, double-submit while the request is in flight (one POST), confirm, then try a calendar day, a slot and another submit (still one POST, nothing reopens). It also checks that the form is reset and that the "Book another time" href is clean.
    • paid: land on ?paid=1&session_id=…&lang=pl. The page is final with zero POSTs, and the link drops the Stripe params but keeps lang.
    • It fails against current main. Removing only the finalized guard from the submit handler fails it too.
  • TestEmbedJS_confirmationIsFinal and TestManagePage_successIsFinal pin the widget and manage guards at source level, the same way as the other widget tests. The widget test also checks that bookAnother never touches location.

gofmt, go vet ./..., go build ./..., go test ./..., go run ./cmd/i18n-coverage and make build pass locally.

I also checked against a running binary in Chromium (Playwright) at 1280×800 and 390×844, plus the widget on a page served from another origin. On each, a double-click on submit sent one POST. After confirmation, no day button was enabled, and a forced day click and a scripted requestSubmit() changed nothing. "Book another time" restored a working calendar, and the widget never changed the host page's URL. I did not exercise the manage page in a browser.

…ces (Calnode#268)

book.html left its calendar clickable after confirming and re-enabled the
submit button, inviting a second booking under a different email, which
max_active_bookings cannot catch.

- book.html: finalize() on success and on the Stripe return disables the
  calendar, month navigation, timezone and submit and resets the form; every
  handler checks the flag. A submitting flag drops a second submit while the
  first is in flight. "Book another time" is a fresh load without the Stripe
  return parameters.
- embed.js: the calendar renders disabled in the confirm view and a second
  submit is refused. "Book another time" resets the widget's own state and
  reloads the month; it never navigates the host page.
- manage.html: the rescheduled and cancelled views are final; showView no
  longer leaves them and neither action can be sent again.

New booker key book_another_time in every locale. TestBookPage_confirmationIsFinal
runs book.html's real page script under node against a small fake DOM and
checks that a second submit sends nothing; the widget and manage page are
pinned at source level.

@pullfrog pullfrog Bot left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Important

One user-facing regression in the mobile Stripe-return path: the confirmation is hidden and the page is inert. Details inline.

Approach: sound — the guard lives in each surface's own script (finalized / submitting / state.view === 'confirm') rather than only in markup, so every handler is covered, and the book.html half is exercised by running the real rendered script under node instead of asserting on source strings. The one gap is where the page's step-flow and the new final state disagree.

Reviewed changes

  • book.html — finalize() runs on the free submit success path and on the ?paid=1 return: calendar, month nav, timezone and submit are disabled, the form is reset, the card gets is-final, and every handler early-returns on finalized. A submitting flag drops a double submit while the first request is in flight (the success path no longer re-enables the button), and "Book another time" is a fresh load that keeps other query params but drops paid / session_id.
  • embed.js — state.view === 'confirm' renders days, prev and next disabled, nav() and the submit handler refuse, and "Book another time" resets the widget in place and reloads the month instead of navigating the host page.
  • manage.html — the rescheduled and cancelled views are terminal: showView will not leave them and neither confirm handler can send twice.
  • booking.css / i18n — one shared .book-another style for the page link and the widget button, .card.is-final dimming, and book_another_time in all 12 booker locales.
  • Tests / docs — TestBookPage_confirmationIsFinal drives the real page script through the submit and paid scenarios against a fake DOM; the widget and manage halves are pinned at source level. ARCHITECTURE §9 and the CHANGELOG entry describe the new invariant.

ℹ️ A booking made through the assistant still leaves the page fully live

Both surfaces gained a "confirmed is final" state, but the conversational path that also creates bookings never enters it. After the assistant reports done with a booking (book.html:976, embed.js:415), only the chat transcript and the analytics event change — the calendar, slots and form stay interactive, so the visitor can still book again from the page the PR just declared final. That is the same duplicate-under-a-different-email hazard, reachable through a different entry point on the same screen. Worth deciding explicitly: call finalize() on the done booking in book.html (and set the widget's view accordingly) or record why the chat is allowed to stay live.

Technical details
# Assistant bookings bypass the final state

## Affected sites
- `internal/handler/templates/book.html:976` — `obj.type === 'done'` only stores `booking`; nothing touches `finalized` or the views.
- `internal/handler/templates/book.html:1006` — the only post-booking side effect is the dataLayer push.
- `internal/handler/embed.js:415` — the widget's `done` handler likewise only records `booking`; the form path (`embed.js:699`) sets `state.view = 'confirm'`, the assistant path does not.

## Required outcome
- Either a booking completed in chat puts its surface into the same final state as the form path, or the deferral is deliberate and documented (ARCHITECTURE §9 / the assistant section), so the next person does not read "final on all three surfaces" as covering every booking route.

## Suggested approach (optional)
- `book.html`: on `done` with a booking, set `#confirm-time` from the booking and call `finalize()`.
- `embed.js`: the assistant drawer lives inside the widget, so switching to `confirm` needs a slot to render; the returned booking carries `start_at`, or fall back to leaving the chat as the deliberate "book again" path and say so.

Pullfrog  | Fix all ➔ | Fix 👍s ➔ | View workflow run | Using deepseek-v4.1-flash | 𝕏

Comment thread internal/handler/templates/book.html Resolved
On the return from Stripe Checkout finalize() shows the confirmation,
but the step-flow init then set the calendar step, which on a narrow
viewport hides the right pane: a disabled calendar and no confirmation.
The init now opens a final page on the right pane.
dominik-myszkowski added a commit to dominik-myszkowski/calnode that referenced this pull request Dec 1, 2026
event_types.redirect_url and redirect_with_booking_id (migration 00077):
where the booker goes once a booking is confirmed, typically the operator's
thank-you page, optionally with ?booking_id= appended (off by default; the
booking id is a lookup key).

The value is an open-redirect surface, so it is checked three times:
validRedirectURL on save (absolute https, a host, no credentials, no
whitespace or control characters, <= 2000 chars), servedRedirectURL when a
page or the widget is given it (an invalid stored value is served as none
and logged), and BookingLogic.redirectTarget in the browser before use,
mirrored in embed.js.

- book.html: finalize() shows "Continue" and navigates after 1.5 s, leaving
  time for the conversion push. Covers the Stripe return too: the success
  URL now carries booking_id.
- embed.js: never navigates the host page; "Continue" opens the redirect in
  a new tab (noopener).
- manage.html: no redirect; a reschedule or cancel is not a conversion.
- Admin: URL field and booking-id checkbox in the General tab (en/fr).
- New booker key "continue" in every locale.

Builds on the final confirmation state from the previous commit (Calnode#284).

@pullfrog pullfrog Bot left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

✅ No new issues found.

Approach: right — the init step-flow is guarded on finalized rather than calling setStep() from the paid IIFE, which keeps cardEl out of the TDZ.

Reviewed changes

  • Guarded the mobile step-flow so a page that is already final opens on the right pane: the init call is now setStep(finalized ? 'right' : 'cal') (book.html:444), replacing the unconditional setStep('cal') that left the Stripe return on the calendar step where .card.m-cal .right-col { display: none } hid #confirm-view.
  • Extended the node paid scenario in testdata/book_final_state.js to assert the card carries m-right and not m-cal, so the CSS-driven regression is now covered rather than only the hidden class.

The inline thread on the mobile Stripe return is addressed by 0b24ebf and has been resolved. TestBookPage_confirmationIsFinal (both scenarios), TestManagePage_successIsFinal and TestEmbedJS_confirmationIsFinal pass locally with node 24 and go 1.26.

Pullfrog  | View workflow run | Using deepseek-v4.1-flash | 𝕏

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant