Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 8 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -61,6 +61,14 @@ exact tag (`ghcr.io/calnode/calnode:0.1.0`) if you need stability between upgrad
the attribute to its primary subtag before sending it, so `lang="fr-CA"` loaded France
French. The attribute is now sent whole and the server falls back to the primary
language when there is no exact match, so `lang="de-DE"` still selects German.
- **A confirmed booking is final on the booking page, the embed widget and the manage
page.** After confirming, the booking page left its calendar clickable and re-enabled the
submit button, which invited a second booking under a different email (the per-invitee cap
cannot catch that). Now the calendar, month navigation, timezone and form stop responding,
a second submit sends nothing (including a double click while the first is in flight), and
a "Book another time" link starts over from a fresh page. The widget does the same without
ever navigating the host page, and the manage page's rescheduled and cancelled screens no
longer lead back to actions on a booking that has changed.

## [0.14.0] - 2026-11-08

Expand Down
2 changes: 2 additions & 0 deletions docs/ARCHITECTURE.md
Original file line number Diff line number Diff line change
Expand Up @@ -413,6 +413,8 @@ Google Meet and Teams event types can opt into `allow_phone_call`. Their booking

The `phone_outbound` location type ("we'll call you") is the outbound counterpart: the host calls the attendee. The event type carries no number (`validateLocation` requires none); the booking page and widget show a required `phone` field instead, and `CreateBooking` refuses a missing or invalid number with HTTP 400 rather than falling back to another meeting type. A valid number is stored exactly like the `allow_phone_call` path (`bookings.location_type = "phone"`, `location_value = "tel:<number>"`), so calendar events, emails, webhooks and the manage page treat it as an ordinary telephone appointment. The manage page needs no field of its own: a reschedule keeps the booking's stored number. The shared booking core (`createBookingForSlug`) refuses these event types, because the assistant and MCP cannot collect the number, and the booking page and widget hide the assistant for them.

A confirmed booking is a **final state** on all three booking surfaces (#268). A page that kept its calendar live and re-enabled its submit button after confirming invited a second booking under a different email, which `max_active_bookings` cannot catch. On `book.html`, `finalize()` (on success, and on the return from Stripe Checkout) disables the calendar, month navigation, timezone and submit, resets the form, and every handler checks the `finalized` flag rather than relying on the markup alone; a `submitting` flag also drops a second submit while the first request is in flight. "Book another time" is a fresh load of the page without the Stripe return parameters, so no picked day, slot or host state survives. The embed widget renders its calendar disabled while `state.view === 'confirm'` and refuses a second submit; its "Book another time" resets the widget's own state and reloads the month, never navigating the host page. On `manage.html` the success views (rescheduled, cancelled) are final: `showView` no longer leaves them and neither action can be sent again, because the page's times describe the booking as it was; a reload shows it as it now is. `TestBookPage_confirmationIsFinal` runs book.html's real page script under node against a small fake DOM (`testdata/book_final_state.js`) to check that a second submit sends nothing; the widget and manage page are pinned at source level.

`internal/booking/service.go` (transactions) + `internal/handler/booking_handler.go`
(HTTP + async side effects).

Expand Down
128 changes: 128 additions & 0 deletions internal/handler/booking_final_state_test.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,128 @@
package handler

import (
"bytes"
"html/template"
"net/http"
"net/http/httptest"
"os"
"os/exec"
"path/filepath"
"regexp"
"strings"
"testing"

"github.com/calnode/calnode/internal/i18n"
)

// bookPageScript renders book.html and returns its main page script: the inline
// <script> that defines SLUG, as the browser would run it.
func bookPageScript(t *testing.T) string {
t.Helper()
var buf bytes.Buffer
if err := bookTmpl.Execute(&buf, bookPageData{
T: i18n.Default().T,
Slug: "intro",
Locale: "en",
BookingLogicJS: template.JS(bookingLogicJS), // #nosec G203 -- our own bundled JS constant
}); err != nil {
t.Fatalf("render book.html: %v", err)
}
for _, m := range regexp.MustCompile(`(?s)<script>(.*?)</script>`).FindAllStringSubmatch(buf.String(), -1) {
if strings.Contains(m[1], "const SLUG") {
return m[1]
}
}
t.Fatal("book.html has no page script defining SLUG")
return ""
}

// TestBookPage_confirmationIsFinal runs book.html's real page script under node against a
// small fake DOM (testdata/book_final_state.js) and checks the harm #268 is about: once a
// booking is confirmed, a second submit sends nothing and the calendar no longer leads
// back into the form. Both entry points to the confirmation are covered: a booking made
// through the form, and the return from Stripe Checkout. Skips without node, like the
// CLDR cross-check.
func TestBookPage_confirmationIsFinal(t *testing.T) {
node, err := exec.LookPath("node")
if err != nil {
t.Skip("node not available; skipping the book.html behaviour test")
}
dir := t.TempDir()
page := filepath.Join(dir, "page.js")
logic := filepath.Join(dir, "booking-logic.js")
if err := os.WriteFile(page, []byte(bookPageScript(t)), 0o600); err != nil {
t.Fatal(err)
}
if err := os.WriteFile(logic, []byte(bookingLogicJS), 0o600); err != nil {
t.Fatal(err)
}
harness, err := filepath.Abs(filepath.Join("testdata", "book_final_state.js"))
if err != nil {
t.Fatal(err)
}
for _, scenario := range []string{"submit", "paid"} {
t.Run(scenario, func(t *testing.T) {
out, err := exec.Command(node, harness, page, logic, scenario).CombinedOutput() // #nosec G204 -- fixed test inputs
if err != nil {
t.Fatalf("%s\n%v", out, err)
}
// node exits 0 when its event loop drains with a promise still pending, so a
// hung step would otherwise pass silently. The harness prints ok only at the end.
if strings.TrimSpace(string(out)) != "ok" {
t.Fatalf("harness did not finish (want \"ok\"):\n%s", out)
}
})
}
}

// TestManagePage_successIsFinal pins manage.html's half: after a reschedule or a cancel
// succeeds, the page cannot navigate away from the success view or send either action
// again, since the times it holds describe the booking as it was (#268).
func TestManagePage_successIsFinal(t *testing.T) {
var buf bytes.Buffer
if err := manageTmpl.Execute(&buf, managePageData{T: i18n.Default().T}); err != nil {
t.Fatalf("render manage.html: %v", err)
}
src := buf.String()
for _, want := range []string{
"function showView(id) {\n if (finalized) return;",
"if (finalized || !pickedSlot) return;", // confirm reschedule
"finalize('success-reschedule-view');", // reschedule success
"finalize('success-cancel-view');", // cancel success
"$('confirm-cancel-btn').addEventListener('click', async () => {\n if (finalized) return;",
} {
if !strings.Contains(src, want) {
t.Errorf("manage.html no longer contains %q - the success view may not be final any more", want)
}
}
}

// TestEmbedJS_confirmationIsFinal pins the widget's half. It builds its own calendar and
// form, so book.html's guards don't cover it: once confirmed, the calendar renders
// disabled, a second submit is refused, and "Book another time" resets the widget in
// place rather than navigating the host page.
func TestEmbedJS_confirmationIsFinal(t *testing.T) {
h := &Handler{}
rec := httptest.NewRecorder()
h.EmbedJS(rec, httptest.NewRequest(http.MethodGet, "/embed.js", nil))
body := rec.Body.String()
for _, want := range []string{
"var isFinal = st.view === 'confirm';",
"if (!has || isFinal) btn.disabled = true;",
"next.disabled = isFinal;",
"if (cta.disabled || self.state.view === 'confirm') return;",
"t(this.i18n, 'book_another_time')",
"bookAnother() {",
} {
if !strings.Contains(body, want) {
t.Errorf("embed.js no longer contains %q - the confirmation may not be final in the widget", want)
}
}
// "Book another time" must not navigate: the widget lives on someone else's page.
start := strings.Index(body, "bookAnother() {")
if end := strings.Index(body[start:], "\n }"); start < 0 || end < 0 ||
strings.Contains(body[start:start+end], "location") {
t.Error("bookAnother must reset the widget's own state, never navigate the host page")
}
}
26 changes: 23 additions & 3 deletions internal/handler/embed.js
Original file line number Diff line number Diff line change
Expand Up @@ -464,6 +464,9 @@

calPane() {
var self = this, st = this.state, first = st.month;
// A confirmed booking is final (#268): the calendar renders but no longer responds,
// so a second booking cannot start from it. "Book another time" is the way back.
var isFinal = st.view === 'confirm';
var grid = el('div', { class: 'cal-grid' });
this.dow.forEach(function (d) { grid.appendChild(el('div', { class: 'ch', text: d })); });
for (var i = 0; i < mondayIndex(first); i++) grid.appendChild(el('div', { class: 'cd', text: '' }));
Expand All @@ -473,14 +476,15 @@
var has = !!st.slotsByDay[key] && key >= todayKey;
var cls = 'cd' + (has ? ' available' : '') + (st.day === key ? ' sel' : '') + (key === todayKey ? ' today' : '');
var btn = el('button', { class: cls, text: String(d) });
if (!has) btn.disabled = true;
if (!has || isFinal) btn.disabled = true;
else btn.addEventListener('click', (function (k) { return function () { self.state.day = k; self.state.view = 'pick'; self.render(); }; })(key));
grid.appendChild(btn);
}
var prev = el('button', { 'aria-label': t(this.i18n, 'prev_month_aria'), html: SVG_PREV });
prev.disabled = !(startOfMonth(first) > startOfMonth(new Date()));
prev.disabled = isFinal || !(startOfMonth(first) > startOfMonth(new Date()));
prev.addEventListener('click', function () { self.nav(-1); });
var next = el('button', { 'aria-label': t(this.i18n, 'next_month_aria'), html: SVG_NEXT });
next.disabled = isFinal;
next.addEventListener('click', function () { self.nav(1); });
var nav = el('div', { class: 'cal-nav' }, [
el('span', { class: 'month-label', text: first.toLocaleDateString(this.locale, { month: 'long', year: 'numeric' }) }),
Expand Down Expand Up @@ -656,6 +660,8 @@
form.appendChild(errBox); form.appendChild(cta);
form.addEventListener('submit', function (e) {
e.preventDefault();
// In flight already (double click, Enter), or already booked: never send twice.
if (cta.disabled || self.state.view === 'confirm') return;
errBox.textContent = '';
if (phoneRequired && !phone.value.trim()) {
errBox.textContent = t(self.i18n, 'required_fields_error');
Expand Down Expand Up @@ -700,18 +706,32 @@
return el('div', {}, [back, el('p', { class: 'slot-label', text: shortDay(slot.start, this.locale) + ' · ' + timeLabel(slot.start, this.locale) }), form]);
}

// confirmView is the final state (#268). The widget never navigates the host page, so
// "Book another time" resets the widget's own state instead, and reloads the month,
// which no longer offers the slot just taken.
confirmView(slot) {
var self = this;
var again = el('button', { class: 'book-another', type: 'button', text: t(this.i18n, 'book_another_time') });
again.addEventListener('click', function () { self.bookAnother(); });
return el('div', {}, [
el('div', { class: 'confirm-icon', html: SVG_CHECK }),
el('div', { class: 'confirm-view' }, [
el('h3', { text: t(this.i18n, 'booking_confirmed') }),
el('p', { class: 'when', text: shortDay(slot.start, this.locale) + ' · ' + timeLabel(slot.start, this.locale) }),
el('p', { class: 'sub', text: t(this.i18n, 'confirmation_email_sent') }),
again,
]),
]);
}

bookAnother() {
this.state.day = null; this.state.slot = null; this.state.view = 'pick';
var self = this;
this.loadMonth().then(function () { self.render(); });
}

nav(delta) {
if (this.state.view === 'confirm') return;
this.state.month = addMonths(this.state.month, delta);
this.state.day = null; this.state.view = 'pick';
var self = this;
Expand All @@ -732,7 +752,7 @@
render() {
var self = this;
this.wrap.innerHTML = '';
this.card = el('div', { class: 'card' }, [this.infoPane(), this.calPane(), this.rightPane()]);
this.card = el('div', { class: 'card' + (this.state.view === 'confirm' ? ' is-final' : '') }, [this.infoPane(), this.calPane(), this.rightPane()]);
// In step-flow, a slots/form view needs a back-to-calendar affordance.
if (this.narrow && (this.state.view === 'pick' && this.state.day)) {
var rc = this.card.querySelector('.right-col');
Expand Down
Loading
Loading