Skip to content

feat(booking): optional next available time above the slot picker (#254) - #275

Open
KishenG wants to merge 1 commit into
Calnode:mainfrom
KishenG:next-available
Open

KishenG wants to merge 1 commit into
Calnode:mainfrom
KishenG:next-available

Conversation

@KishenG

@KishenG KishenG commented Nov 25, 2026

Copy link
Copy Markdown

Adds an opt-in show_next_available event type setting, default off. When on, a button above the time list shows the soonest free time, such as "Next available: Wed, Dec 9, 10:00 AM", and opens that day when clicked. This is the change agreed in #254.

How it follows the points raised there:

  • Setting: migration 00073 follows 00057. Column, JSON field, create and PATCH handlers, the select lists, event_type_duplicate.go, and a checkbox in the event type editor next to the booked-times one.
  • Free times only: it never reads the merged free and taken view, so it cannot advertise a struck-through time.
  • Empty months: it walks forward month by month and stops at maxDate, so it cannot run past max_future_days.
  • Failed or degraded checks: a failed request or a degraded response shows nothing.
  • Timezone: the server already applies it to /slots. The page only formats, with the existing formatters. A timezone change restarts the search.
  • Markup: a real <button>, styled like a time button in booking.css.
  • Logic: earliestFreeSlot and monthsToProbe are in booking-logic.js with unit tests.
  • i18n: one English key, next_available_hint. The admin strings are en and fr.
  • Both pages: book.html and manage.html change together. On the reschedule page the booking's own current time is left out, so it offers the next time the booking could move to.
  • Embed widget: left for a follow-up PR, as you suggested. It does not load booking-logic.js, so it needs its own mirrored copy.

On narrow screens the calendar step hides the right column, so a second copy of the button sits above the calendar there, and booking.css shows one at a time.

ARCHITECTURE.md has a new subsection beside the booked-times one, and the CHANGELOG has an entry.

Checked:

  • go test ./..., go vet ./... and gofmt -l . are clean.
  • node --test internal/handler/assets/booking-logic.test.js: 20 pass.
  • Admin: pnpm check, pnpm check:i18n and pnpm build pass.
  • Chromium, booking and reschedule pages at desktop width and 390 px: the button shows, opens the right day, is hidden when the slots response is degraded, and there are no page errors.
  • Not run: pnpm test:visual (no change to the ui components, app.css or the theme) and the embed widget (untouched).
next-available-reschedule next-available-slot

…lnode#254)

A per-event-type setting, off by default, adds a button above the time list that opens the soonest free day. Worked out from the free slots only, bounded by max_future_days, and silent on a failed or degraded check. Shown on the booking and reschedule pages; the embed widget is left for a follow-up.
@github-actions

github-actions Bot commented Nov 25, 2026 •

Copy link
Copy Markdown
Contributor

All contributors have signed the CLA. ✅
Posted by the CLA Assistant Lite bot.

@KishenG

KishenG commented Nov 25, 2026

Copy link
Copy Markdown
Author

I have read the CLA Document and I hereby sign the CLA

github-actions Bot added a commit that referenced this pull request Nov 25, 2026

@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

The new button's label renders as the literal string next_available_hint on every non-English locale. t() on both pages is I18N[key] || key, and I18N is loc.JSON() — the resolved locale's strings only, with no English merge — so the missing key surfaces on the page instead of falling back to English.

Approach: sound — one opt-in column threaded through create/PATCH/duplicate and both server-rendered surfaces, with the search itself in the shared, unit-tested booking-logic.js rather than reimplemented per page, and the embed widget deferred until it can load that module.

Reviewed changes

  • Setting and API — migration 00073 (DEFAULT 0, mirroring 00057), the shared column list and row scan, create and PATCH, the duplicate copy, and the admin type/checkbox with en/fr copy.
  • Booking and reschedule pages — loadNextAvailable on both surfaces, the desktop/mobile pair of buttons, booking.css, and the one new public i18n key.
  • Shared helpers and tests — earliestFreeSlot, monthsToProbe and six node tests, plus Go tests for the opt-in round-trip and for both pages' markup.
  • Docs — CHANGELOG entry and the ARCHITECTURE subsection beside the booked-times one.

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

"date_picker_aria": "Date picker",
"timezone_aria": "Timezone",
"select_day_hint": "Select a day to see available times.",
"next_available_hint": "Next available: %[1]s, %[2]s",

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.

next_available_hint is only added here, and the page-side t() is I18N[key] || key with I18N built from loc.JSON() — the resolved locale's strings alone, no English merge. So on every other shipped catalogue the button shows the literal text next_available_hint; the Locale.T English fallback that makes partial locales safe is server-side only and does not extend to this blob.

Technical details
# Add `next_available_hint` to every locale file

## Affected sites
- `internal/i18n/locales/en.json:13` — the only file carrying the key
- missing from `de.json`, `de-x-neutral.json`, `el.json`, `es.json`, `fr.json`, `fr-CA.json`, `it.json`, `nl.json`, `pl.json`, `pt.json`, `sv.json`
- consumers: `internal/handler/templates/book.html:869` and `manage.html:579` (`BookingLogic.fmt(t('next_available_hint'), […])`); `t` falls back to the key, and `fmt` has no verbs to replace in the key, so the raw string is what lands in `textContent`

## Required outcome
Every locale file has the key, with the `%[1]s, %[2]s` indices preserved so a translation can reorder the day and the time.

## Suggested approach
LLM drafts are the repo convention for non-English files, so one pass over the 11 files is enough; alternatively the page could merge English into `I18NJSON`, but that is a cross-cutting change to every public-surface key and not worth doing inside this PR.

function earliestFreeSlot(slots, tz, excludeStart) {
var best = null;
(slots || []).forEach(function (s) {
if (excludeStart && s.start === excludeStart) return;

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.

excludeStart is compared as a raw string, but /slots returns starts formatted in the request's timezone (slotJSON.Start = s.Start.Format(time.RFC3339), slots_handler.go:326), so they carry an offset, while CURRENT_ISO comes from b.StartAt.UTC().Format(time.RFC3339) and ends in Z. Outside a UTC browser the two can never be equal, so the reschedule exclusion the PR describes is inert today — the booking's own start stays out of the list only because bookings are counted as busy upstream.

Technical details
# Compare instants, not strings, when excluding a slot

## Affected sites
- `internal/handler/assets/booking-logic.js:76` — `s.start === excludeStart`
- `internal/handler/templates/manage.html:576` — the caller that relies on it (`earliestFreeSlot(data.slots, TZ, CURRENT_ISO)`)
- `internal/handler/assets/booking-logic.js:35` — `groupSlotsByDay` has the same comparison; pre-existing, same failure mode

## Required outcome
The excluded start is dropped regardless of the offset spelling the server chose, and a test with mixed offsets (`Z` vs `-04:00`) pins it.

## Suggested approach
`if (excludeStart && Date.parse(s.start) === Date.parse(excludeStart)) return;` — the same argument `mergeDaySlots` above already makes for sorting ("slot times carry a UTC offset"). The existing tests only pass `Z` on both sides, which is why they do not catch this.

// ── Init ──────────────────────────────────────────────────────────────────
populateTzSelect();
loadMonthAvailability(navYear, navMonth);
loadNextAvailable();

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.

This fires a /slots request for the same month, with the same from/to/tz, two lines after loadMonthAvailability already requested it — so an opted-in event type doubles the cost of the heaviest public endpoint on every page view, and adds a further serial probe per month when the current one has nothing. Seeding the probe from the month the calendar already fetched would avoid the duplicate; manage.html:604 and manage.html:726 have the same overlap.

Technical details
# Avoid re-fetching the month the calendar already has

## Affected sites
- `internal/handler/templates/book.html:899` — `loadNextAvailable()` right after `loadMonthAvailability(navYear, navMonth)` (`:898`); also the tz-change handler at `:888` then `:889`
- `internal/handler/templates/manage.html:604` and `:726` — same pairing

## Required outcome
One `/slots` request per month range per load, not two, while keeping the "silent on failure/degraded" behaviour.

## Suggested approach
Have `loadNextAvailable` consume the already-cached `slotsByDay`/`availabilityLoaded` result for the visible month before probing later months, or have both callers await one shared in-flight promise per `(from, to, tz)`.

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