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
7 changes: 7 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,13 @@ exact tag (`ghcr.io/calnode/calnode:0.1.0`) if you need stability between upgrad
The variant is never offered in the language switcher or matched from `Accept-Language`;
select it with `?lang=de-x-neutral` or `<calnode-booking lang="de-x-neutral">`.

- **Next available time on the booking page.** A per-event-type setting, off by default,
adds a button above the time list, such as "Next available: Wed, Nov 18, 10:00 AM", that
opens that day. It is worked out from the free times only, walks forward month by month
but never past `max_future_days`, and shows nothing when the availability check failed or
was degraded, rather than implying there is none. It appears on the booking and reschedule
pages. The embed widget does not have it yet. Proposed in discussion #254.

### Fixed

- **Buttons and inputs in the booking UI now use the surrounding font.** Form controls
Expand Down
23 changes: 23 additions & 0 deletions docs/ARCHITECTURE.md
Original file line number Diff line number Diff line change
Expand Up @@ -363,6 +363,29 @@ in discussion #14, issue #19.
having something available. Fully booked days *are* still openable, deliberately - a
list of struck-through times explains itself better than a dead date.

### Showing the next available time

`event_types.show_next_available` (migration 00073, **default off**) opts one event type
into a button above the time list that opens the soonest free day. Requested in
discussion #254.

- **Worked out in the browser from the free list.** `loadNextAvailable` in book.html and
manage.html reads `/slots` month by month from today and stops at the first free
slot. It never reads `taken`, which would advertise a struck-through time, and it never
walks past `maxDate`, so it cannot run beyond `max_future_days`. `monthsToProbe` and
`earliestFreeSlot` live in `assets/booking-logic.js` and are unit tested.
- **Silent when unsure.** A failed request or a `degraded` response shows nothing: a
check that fell over is not the same as "nothing is available".
- **Timezone.** The server already applies the requested timezone to `/slots`, so the
page only formats. Changing the timezone restarts the search.
- **Reschedule.** manage.html leaves out the booking's own current start, so the button
offers the next time the booking could move to.
- **Two copies of the button.** On narrow screens the calendar step hides the right
column, so a second copy sits above the calendar there and `booking.css` shows one
at a time.
- **Not in the embed widget yet.** It does not load `booking-logic.js`, so it would need
its own mirrored copy of the two helpers.

### Explaining an empty day, and the minimum-notice gap

Two silences on the booker-facing surfaces, issue #20. A day with nothing on it used to
Expand Down
3 changes: 3 additions & 0 deletions frontend/src/lib/api.ts
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,9 @@ export type EventType = {
* them. Off by default: the slots endpoint is public, so this makes the host's
* booked hours visible to anyone with the link. */
show_taken_slots: boolean;
/** Show the next free time above the booking page's time list, as a button that
* opens that day. Off by default. */
show_next_available: boolean;
/** Who sends the booker's calendar invite. 'calendar': each host's connected calendar,
* from the host's own address. 'calnode': Calnode's own invite, from the email sender
* in Settings → Email, so no host's personal address reaches the booker. 'none': no
Expand Down
2 changes: 2 additions & 0 deletions frontend/src/lib/i18n/en.json
Original file line number Diff line number Diff line change
Expand Up @@ -1631,6 +1631,8 @@
"showTaken": "Show booked times as unavailable",
"showTakenHint": "Booked times appear struck through on the booking page instead of being hidden, so visitors can see the calendar filling up. Only times inside your working hours are shown, never the rest of your day.",
"showTakenWarning": "Anyone with the booking link can see which hours are taken.",
"showNextAvailable": "Show the next available time",
"showNextAvailableHint": "Adds a button above the time list, such as \"Next available: Wed, Nov 18, 10:00 AM\", that opens that day. It uses the same times a visitor can already see.",
"allowPhoneCall": "Let invitees choose a phone call by entering their number"
},
"location": {
Expand Down
2 changes: 2 additions & 0 deletions frontend/src/lib/i18n/fr.json
Original file line number Diff line number Diff line change
Expand Up @@ -1631,6 +1631,8 @@
"showTaken": "Afficher les horaires réservés comme indisponibles",
"showTakenHint": "Les horaires réservés apparaissent barrés sur la page de réservation au lieu d'être masqués, afin que les visiteurs voient le calendrier se remplir. Seuls les horaires dans vos heures de travail sont affichés, jamais le reste de votre journée.",
"showTakenWarning": "Quiconque dispose du lien de réservation peut voir quels horaires sont pris.",
"showNextAvailable": "Afficher le prochain horaire disponible",
"showNextAvailableHint": "Ajoute au-dessus de la liste des horaires un bouton, par exemple « Prochain créneau disponible : mer. 18 nov., 10:00 », qui ouvre ce jour. Il utilise les mêmes horaires que ceux déjà visibles par un visiteur.",
"allowPhoneCall": "Permettre aux invités de choisir un appel téléphonique en saisissant leur numéro"
},
"location": {
Expand Down
12 changes: 11 additions & 1 deletion frontend/src/routes/event-types/[slug]/+page.svelte
Original file line number Diff line number Diff line change
Expand Up @@ -86,7 +86,7 @@
let form = $state({
display_order: 0,
name: '', slug: '', description: '', duration_minutes: 30, slot_interval_minutes: 30,
is_active: true, is_public: true, show_taken_slots: false,
is_active: true, is_public: true, show_taken_slots: false, show_next_available: false,
invite_delivery: 'calendar' as EventType['invite_delivery'],
location_type: 'link', location_value: '',
buffer_before_minutes: 0, buffer_after_minutes: 0,
Expand Down Expand Up @@ -335,6 +335,7 @@
is_active: et.is_active,
is_public: et.is_public,
show_taken_slots: et.show_taken_slots ?? false,
show_next_available: et.show_next_available ?? false,
invite_delivery: et.invite_delivery ?? 'calendar',
location_type: et.location_type,
location_value: et.location_value ?? '',
Expand Down Expand Up @@ -396,6 +397,7 @@
is_active: form.is_active,
is_public: form.is_public,
show_taken_slots: form.show_taken_slots,
show_next_available: form.show_next_available,
invite_delivery: form.invite_delivery,
allow_phone_call: allowPhoneCall,
location_type: form.location_type,
Expand Down Expand Up @@ -703,6 +705,14 @@
</p>
</div>

<div class="mt-4 space-y-1.5">
<div class="flex items-center gap-2">
<Checkbox id="show-next-available" bind:checked={form.show_next_available} />
<Label for="show-next-available" class="cursor-pointer font-normal">{$t('eventTypeEditor.general.showNextAvailable')}</Label>
</div>
<p class="text-xs text-muted-foreground">{$t('eventTypeEditor.general.showNextAvailableHint')}</p>
</div>

{#if isOnlineMeeting(form.location_type)}
<label class="flex items-center gap-3 text-sm"><input type="checkbox" bind:checked={allowPhoneCall} />{$t('eventTypeEditor.general.allowPhoneCall')}</label>
{/if}
Expand Down
12 changes: 12 additions & 0 deletions internal/db/migrations/00073_event_type_show_next_available.sql
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
-- +goose Up
-- Whether the booking page shows the next available time above the time list, as a
-- button that jumps to that day. Proposed in discussion #254.
--
-- Default 0, so nothing changes for an existing event type. It follows
-- show_taken_slots (00057) rather than being always on: the button is computed from the
-- same public slots endpoint a visitor can already read, so it discloses nothing new,
-- but a host whose page is meant to be browsed day by day may not want it.
ALTER TABLE event_types ADD COLUMN show_next_available INTEGER NOT NULL DEFAULT 0;

-- +goose Down
ALTER TABLE event_types DROP COLUMN show_next_available;
28 changes: 28 additions & 0 deletions internal/handler/assets/booking-logic.js
Original file line number Diff line number Diff line change
Expand Up @@ -65,6 +65,32 @@
}


// earliestFreeSlot — the soonest bookable slot in `slots` (the FREE list from /slots, never
// the merged free+taken view: that would advertise a struck-through time), with the
// "YYYY-MM-DD" it falls on in the selected tz. `excludeStart` drops one slot (reschedule
// excludes the booking's own time). Null when there is none. Does not re-derive the
// timezone: the server already applied the requested one, and dateKeyFromISO formats in it.
function earliestFreeSlot(slots, tz, excludeStart) {
var best = null;
(slots || []).forEach(function (s) {
if (excludeStart && Date.parse(s.start) === Date.parse(excludeStart)) return;
if (best === null || Date.parse(s.start) < Date.parse(best.start)) best = s;
});
return best === null ? null : { slot: best, day: dateKeyFromISO(best.start, tz) };
}

// monthsToProbe — the months, oldest first, that a search for the next available day should
// walk: from `now`'s month up to and including `maxDate`'s month, so it can never run past
// the event type's max_future_days. maxDate null means no limit is set, so `capMonths`
// (default 12) bounds the walk instead.
function monthsToProbe(now, maxDate, capMonths) {
var out = [];
var first = now.getFullYear() * 12 + now.getMonth();
var last = maxDate ? maxDate.getFullYear() * 12 + maxDate.getMonth() : first + (capMonths || 12) - 1;
for (var idx = first; idx <= last; idx++) out.push({ year: Math.floor(idx / 12), month: idx % 12 });
return out;
}

// formatTime — "1:30 PM" in the selected tz.
function formatTime(iso, tz, locale) {
return new Intl.DateTimeFormat(locale || [], {
Expand Down Expand Up @@ -143,6 +169,8 @@
ymd: ymd,
groupSlotsByDay: groupSlotsByDay,
mergeDaySlots: mergeDaySlots,
earliestFreeSlot: earliestFreeSlot,
monthsToProbe: monthsToProbe,
fmt: fmt,
formatTime: formatTime,
formatDay: formatDay,
Expand Down
59 changes: 59 additions & 0 deletions internal/handler/assets/booking-logic.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -106,3 +106,62 @@ test('fmt leaves a string with no verbs untouched', () => {
assert.equal(B.fmt('No available times.', ['unused']), 'No available times.');
assert.equal(B.fmt('Inga lediga tider.'), 'Inga lediga tider.');
});

test('earliestFreeSlot picks the soonest slot and the day it falls on in the selected tz', () => {
const slots = [
{ start: '2026-06-16T09:00:00Z' },
{ start: '2026-06-15T02:00:00Z' }, // NY → 06-14 22:00
{ start: '2026-06-15T20:00:00Z' }
];
const ny = B.earliestFreeSlot(slots, 'America/New_York');
assert.equal(ny.slot.start, '2026-06-15T02:00:00Z');
assert.equal(ny.day, '2026-06-14'); // the day key follows the selected tz, not UTC
assert.equal(B.earliestFreeSlot(slots, 'UTC').day, '2026-06-15');
});

test('earliestFreeSlot orders by instant, not by string, across offsets', () => {
// As strings "…T10:00:00+02:00" sorts after "…T09:30:00Z", but it is the earlier instant.
const slots = [{ start: '2026-06-15T09:30:00Z' }, { start: '2026-06-15T10:00:00+02:00' }];
assert.equal(B.earliestFreeSlot(slots, 'UTC').slot.start, '2026-06-15T10:00:00+02:00');
});

test('earliestFreeSlot skips the excluded slot and returns null when nothing is left', () => {
const slots = [{ start: '2026-06-15T09:00:00Z' }, { start: '2026-06-15T10:00:00Z' }];
assert.equal(B.earliestFreeSlot(slots, 'UTC', '2026-06-15T09:00:00Z').slot.start, '2026-06-15T10:00:00Z');
assert.equal(B.earliestFreeSlot([], 'UTC'), null);
assert.equal(B.earliestFreeSlot(undefined, 'UTC'), null);
assert.equal(B.earliestFreeSlot([{ start: '2026-06-15T09:00:00Z' }], 'UTC', '2026-06-15T09:00:00Z'), null);
});

test('earliestFreeSlot excludes by instant, so an offset spelling that differs does not defeat it', () => {
// /slots spells starts in the requested timezone ("+02:00"); the booking's own start is UTC ("Z").
const slots = [{ start: '2026-06-15T11:00:00+02:00' }, { start: '2026-06-15T10:00:00Z' }];
assert.equal(B.earliestFreeSlot(slots, 'UTC', '2026-06-15T09:00:00Z').slot.start, '2026-06-15T10:00:00Z');
});

test('earliestFreeSlot ignores a taken slot because it is only ever given the free list', () => {
// The caller passes data.slots (free), never mergeDaySlots output. If it did pass merged
// entries, a taken one would win; this pins that the free list is the contract.
const free = [{ start: '2026-06-15T11:00:00Z' }];
const taken = [{ start: '2026-06-15T09:00:00Z' }];
assert.equal(B.earliestFreeSlot(free, 'UTC').slot.start, '2026-06-15T11:00:00Z');
assert.equal(B.earliestFreeSlot(B.mergeDaySlots(free, taken), 'UTC').slot.start, '2026-06-15T09:00:00Z');
});

test('monthsToProbe walks from this month to maxDate\'s month and never past it', () => {
const now = new Date(2026, 10, 18); // 18 Nov 2026
const max = new Date(2027, 0, 20); // 20 Jan 2027
assert.deepEqual(B.monthsToProbe(now, max), [
{ year: 2026, month: 10 }, { year: 2026, month: 11 }, { year: 2027, month: 0 }
]);
});

test('monthsToProbe is one month when maxDate falls in this month', () => {
assert.deepEqual(B.monthsToProbe(new Date(2026, 10, 18), new Date(2026, 10, 30)), [{ year: 2026, month: 10 }]);
});

test('monthsToProbe is bounded by the cap when there is no maxDate', () => {
const m = B.monthsToProbe(new Date(2026, 10, 18), null, 3);
assert.deepEqual(m, [{ year: 2026, month: 10 }, { year: 2026, month: 11 }, { year: 2027, month: 0 }]);
assert.equal(B.monthsToProbe(new Date(2026, 10, 18), null).length, 12);
});
7 changes: 5 additions & 2 deletions internal/handler/book.go
Original file line number Diff line number Diff line change
Expand Up @@ -72,6 +72,7 @@ type bookPageData struct {
PriceCents int // raw price for the dataLayer conversion value (0 = free)
Currency string // ISO 4217, lowercase
MaxFutureDays int
NextAvailable bool // show the "next available" button above the time list (#254)
Questions []bookQuestion
// AssistantEnabled shows the conversational-booking chat panel when the LLM layer is on.
AssistantEnabled bool
Expand Down Expand Up @@ -464,16 +465,17 @@ func (h *Handler) BookPage(w http.ResponseWriter, r *http.Request) {
msgGreeting sql.NullString
allowPhoneCall bool
accentColor string
showNext bool
)
err := h.db.QueryRowContext(r.Context(), `
SELECT et.id, et.name, COALESCE(et.description, ''),
et.duration_minutes, et.location_type, COALESCE(et.location_value, ''),
et.max_future_days, et.min_notice_minutes, et.routing_mode, u.name, COALESCE(u.avatar_url, ''),
et.price_cents, et.currency, et.msg_greeting, et.allow_phone_call, u.booking_accent
et.price_cents, et.currency, et.msg_greeting, et.allow_phone_call, u.booking_accent, et.show_next_available
FROM event_types et
JOIN users u ON u.id = et.user_id
WHERE et.slug = ? AND et.is_active = 1 AND et.is_public = 1`,
slug).Scan(&etID, &name, &description, &durMins, &locType, &locValue, &maxDays, &minNotice, &routingMode, &hostName, &avatarURL, &priceCents, &currency, &msgGreeting, &allowPhoneCall, &accentColor)
slug).Scan(&etID, &name, &description, &durMins, &locType, &locValue, &maxDays, &minNotice, &routingMode, &hostName, &avatarURL, &priceCents, &currency, &msgGreeting, &allowPhoneCall, &accentColor, &showNext)

if errors.Is(err, sql.ErrNoRows) {
http.Error(w, "Page not found", http.StatusNotFound)
Expand Down Expand Up @@ -559,6 +561,7 @@ func (h *Handler) BookPage(w http.ResponseWriter, r *http.Request) {
PriceCents: priceCents,
Currency: currency,
MaxFutureDays: maxDays,
NextAvailable: showNext,
Questions: questions,
BookingLogicJS: template.JS(bookingLogicJS), // #nosec G203 -- our own bundled JS source constant, not user input
AssistantEnabled: h.getLLM() != nil,
Expand Down
Loading
Loading