Slots: bulk tools, get-ready time, group places, and bookings block overlapping slots #3

Merged
reudy merged 11 commits from session/redo-slots-and-add-get-ready-tim into main 2026-10-24 12:15:35 +02:00
Member

This reworks how slots are created and booked:

  1. Bulk slot creation (making a month of slots was tedious), with a per-service get-ready time.
  2. Group sessions: slots have places (capacity); a group session is just a service with more than 1 place.
  3. One practitioner: several services can be offered at the same time, and once one is booked (or in a basket) the overlapping ones disappear, get-ready time included.

How booking state works now

Nothing about bookings is stored on a slot any more. slotStates() in pocketbase/pb_hooks/shop/lib.js is the only place the rules live:

  • Places taken = places in paid orders + places in baskets whose hold hasn't expired. Holds move from the slot to the basket line (basket_lines.heldUntil). An expired hold stops counting immediately; the once-a-minute job only tidies up.
  • Blocking: a slot with any place taken blocks every other slot it overlaps, whatever the service, including each service's get-ready time. A group class with one place booked blocks massages at that time but stays bookable itself until full, and vice versa.
  • GET /api/shop/slots returns the bookable future slots to the public shop (full and blocked ones hidden). With ?detail=1, a signed-in admin gets every slot in a range with places booked/held and what blocks it.
  • Adding to the basket (add_slot, now with seats) and changing a group line's places re-check capacity and blocking in the same database transaction that writes the hold. PocketBase runs transactions one at a time, so two customers can't both get the last place or two overlapping times.

What changes for the client (admin)

  • Services & products: Get-ready time and Places per slot (the default for new slots).
  • Slots:
    • Month calendar (?month=YYYY-MM) with a service filter and a day panel.
    • Statuses: available / in a basket / booked / full / blocked ("Blocked by 18:00 A Group class"), plus places taken, e.g. 2/4.
    • Generate slots: date range × weekdays × opening hours, spaced by duration + get-ready time, with places. Copy a week: into the next 1–12 weeks. Clear slots: deletes only slots with no places taken.
    • Each bulk action previews first and skips past slots and overlaps with the same service.
    • Once any place is taken, only the number of places (not below what's taken) and the notes can change. Slots with places taken can't be deleted.

What changes for customers

  • Shop block: group times show "3 places left"; clicking again adds another place. The listing reloads after adding, so times that just became blocked disappear.
  • Checkout: quantity stepper for group-session lines. The server refuses more places than are left, with a clear message.

Migrations

1792800000_items_buffer_minutes adds items.bufferMinutes.

1792800100_slot_capacity_and_line_holds:

  • Adds items.capacity and slots.capacity (existing slots get 1).
  • Adds basket_lines.heldUntil, copied from the slot each line was holding.
  • Replaces the unique index on basket_lines.slot with a plain one, and indexes order_lines.slot.
  • Removes slots.status / heldUntil / order. Bookings already live in order_lines.
  • Makes slots readable only when signed in; the public shop goes through the route.

pb_schema.json mirrors both (new fields in the 0.23 format). Rolling back restores the schema, but not old holds or bookings on slots; restore a backup for that. Take a backup before deploying.

Tested

  • svelte-check, admin and public: 0 errors. All warnings were already there.
  • Migrations on PocketBase 0.23.12, on a database built from main's schema with an old-style held slot (plus its basket line) and a booked slot (plus a paid order). The hold moved to the basket line, slots got capacity 1, and the indexes, fields and rules all ended up as intended. Fresh install: migrations + importing pb_schema.json gave the same schema.
  • Booking rules, 36 scripted checks against the real hooks, including:
    • Other services and times inside the get-ready window are hidden while one is held, and come back when it's removed.
    • Group: 2 + 1 of 3 places; "Only 1 place left"; shrinking/growing a line; adding the same slot again adds a place.
    • Races: 20 parallel customers on one slot → exactly 1 wins; 20 on two overlapping slots of different services → exactly 1 wins.
    • Payment webhook (signed test events): held places become booked, retries don't book twice, and an expired hold frees its places at once.
    • The detail view requires sign-in.
  • Admin form actions: generate/copy/clear, places default vs override, refusing to drop places below what's taken, edits limited once booked, delete refused while held, copy keeps places and notes.
  • Headless Chromium:
    • Public shop: "4 places left" → add → "3 places left · 1 in basket", and the overlapping massage's day greys out.
    • Basket: the group stepper goes 1 → 2.
    • Admin day panel: "2/4 places · In a basket" and "Blocked by 18:00 A Group class". No console errors.
  • Not tested: real Stripe checkout (no key here; the payment-intent step is unchanged except for the per-line hold check), and booking emails with more than 1 place (the templates already print 2× …).

Notes for later

  • If a hold expires and someone else takes the place while the first customer is still paying, the webhook still records the first payment, so the slot is overbooked. The 30-minute checkout hold makes this unlikely; the order is recorded either way. It worked the same way before this PR.
  • Most older number/text fields in pb_schema.json nest min/max under "options". PocketBase 0.23 ignores that on fresh installs (noted in the README).
  • docker-compose.yml publishes Caddy as a bare 8080:8080. The pinned spectado/pocketbase:0.23.12 image can no longer be pulled from Docker Hub.
  • The contract also mentions a minimum lead time per service; that's not in this PR.

Follow-up fixes from review

  • Admin: a one-person slot in a customer's basket now reads "In a basket" instead of "Full". "Full" now only means a group session filled by paid bookings.
  • Shop calendar: ‹ › arrows to move through months. When the shown months have no free days, a note gives the first available date ("Monday 11 January 2027") with a button that goes to it.
  • Group places: once a time is in the basket, the shop shows − n + instead of letting people click the time again. Times whose last places are in your own basket stay visible so you can lower the number.
  • Places come back: removing or changing a basket line reloads the listing. The public layout also reloads on every navigation, so places freed on /book appear on the home page.
  • Reservation countdown at checkout: in the last 3 minutes it offers "Keep it 10 more minutes" (new basket action renew_holds; holds are extended, never shortened). When a hold runs out, the customer is told which time was removed.
  • Dates: everything shown to people uses en-GB (day-month-year, 24-hour clock) and the studio's SITE_TIMEZONE, through $shared/calendar helpers. The server's default locale was en-US. Native date pickers still follow the visitor's browser language.

Tested in headless Chromium with an en-US / New York browser, no console errors: jump to January 2027; 1 → 3 places with + disabled at full; back to 0 and the places return; remove on /book, then home shows 3 places left; countdown 10:00; at 1:29 the renew button appears and resets it to 10:00; a 4-second hold ends with the "ran out" message; admin shows "In a basket". Both apps type-check with 0 errors.

🤖 Generated with Claude Code

https://claude.ai/code/session_01VaXE9U7AmW3dfD2w6cbLfk

This reworks how slots are created and booked: 1. **Bulk slot creation** (making a month of slots was tedious), with a per-service **get-ready time**. 2. **Group sessions:** slots have **places** (capacity); a group session is just a service with more than 1 place. 3. **One practitioner:** several services can be offered at the same time, and once one is booked (or in a basket) the overlapping ones disappear, get-ready time included. ## How booking state works now Nothing about bookings is stored on a slot any more. `slotStates()` in `pocketbase/pb_hooks/shop/lib.js` is the only place the rules live: - **Places taken** = places in paid orders + places in baskets whose hold hasn't expired. Holds move from the slot to the basket line (`basket_lines.heldUntil`). An expired hold stops counting immediately; the once-a-minute job only tidies up. - **Blocking:** a slot with *any* place taken blocks every other slot it overlaps, *whatever the service*, including each service's get-ready time. A group class with one place booked blocks massages at that time but stays bookable itself until full, and vice versa. - **`GET /api/shop/slots`** returns the bookable future slots to the public shop (full and blocked ones hidden). With `?detail=1`, a signed-in admin gets every slot in a range with places booked/held and what blocks it. - **Adding to the basket** (`add_slot`, now with `seats`) and changing a group line's places re-check capacity and blocking in the same database transaction that writes the hold. PocketBase runs transactions one at a time, so two customers can't both get the last place or two overlapping times. ## What changes for the client (admin) - **Services & products:** *Get-ready time* and *Places per slot* (the default for new slots). - **Slots:** - Month calendar (`?month=YYYY-MM`) with a service filter and a day panel. - Statuses: available / in a basket / booked / full / blocked ("Blocked by 18:00 A Group class"), plus places taken, e.g. `2/4`. - *Generate slots:* date range × weekdays × opening hours, spaced by duration + get-ready time, with places. *Copy a week:* into the next 1–12 weeks. *Clear slots:* deletes only slots with no places taken. - Each bulk action previews first and skips past slots and overlaps with the same service. - Once any place is taken, only the number of places (not below what's taken) and the notes can change. Slots with places taken can't be deleted. ## What changes for customers - **Shop block:** group times show "3 places left"; clicking again adds another place. The listing reloads after adding, so times that just became blocked disappear. - **Checkout:** quantity stepper for group-session lines. The server refuses more places than are left, with a clear message. ## Migrations **`1792800000_items_buffer_minutes`** adds `items.bufferMinutes`. **`1792800100_slot_capacity_and_line_holds`**: - Adds `items.capacity` and `slots.capacity` (existing slots get 1). - Adds `basket_lines.heldUntil`, copied from the slot each line was holding. - Replaces the unique index on `basket_lines.slot` with a plain one, and indexes `order_lines.slot`. - Removes `slots.status` / `heldUntil` / `order`. Bookings already live in `order_lines`. - Makes slots readable only when signed in; the public shop goes through the route. `pb_schema.json` mirrors both (new fields in the 0.23 format). Rolling back restores the schema, but not old holds or bookings on slots; restore a backup for that. **Take a backup before deploying.** ## Tested - `svelte-check`, admin and public: 0 errors. All warnings were already there. - **Migrations** on PocketBase 0.23.12, on a database built from `main`'s schema with an old-style held slot (plus its basket line) and a booked slot (plus a paid order). The hold moved to the basket line, slots got capacity 1, and the indexes, fields and rules all ended up as intended. **Fresh install:** migrations + importing `pb_schema.json` gave the same schema. - **Booking rules**, 36 scripted checks against the real hooks, including: - Other services and times inside the get-ready window are hidden while one is held, and come back when it's removed. - Group: 2 + 1 of 3 places; "Only 1 place left"; shrinking/growing a line; adding the same slot again adds a place. - **Races:** 20 parallel customers on one slot → exactly 1 wins; 20 on two overlapping slots of different services → exactly 1 wins. - **Payment webhook** (signed test events): held places become booked, retries don't book twice, and an expired hold frees its places at once. - The detail view requires sign-in. - **Admin form actions:** generate/copy/clear, places default vs override, refusing to drop places below what's taken, edits limited once booked, delete refused while held, copy keeps places and notes. - **Headless Chromium:** - Public shop: "4 places left" → add → "3 places left · 1 in basket", and the overlapping massage's day greys out. - Basket: the group stepper goes 1 → 2. - Admin day panel: "2/4 places · In a basket" and "Blocked by 18:00 A Group class". No console errors. - **Not tested:** real Stripe checkout (no key here; the payment-intent step is unchanged except for the per-line hold check), and booking emails with more than 1 place (the templates already print `2× …`). ## Notes for later - If a hold expires and someone else takes the place *while* the first customer is still paying, the webhook still records the first payment, so the slot is overbooked. The 30-minute checkout hold makes this unlikely; the order is recorded either way. It worked the same way before this PR. - Most older number/text fields in `pb_schema.json` nest `min`/`max` under `"options"`. PocketBase 0.23 ignores that on fresh installs (noted in the README). - `docker-compose.yml` publishes Caddy as a bare `8080:8080`. The pinned `spectado/pocketbase:0.23.12` image can no longer be pulled from Docker Hub. - The contract also mentions a minimum lead time per service; that's not in this PR. ## Follow-up fixes from review - **Admin:** a one-person slot in a customer's basket now reads "In a basket" instead of "Full". "Full" now only means a group session filled by paid bookings. - **Shop calendar:** ‹ › arrows to move through months. When the shown months have no free days, a note gives the first available date ("Monday 11 January 2027") with a button that goes to it. - **Group places:** once a time is in the basket, the shop shows − n + instead of letting people click the time again. Times whose last places are in your own basket stay visible so you can lower the number. - **Places come back:** removing or changing a basket line reloads the listing. The public layout also reloads on every navigation, so places freed on /book appear on the home page. - **Reservation countdown at checkout:** in the last 3 minutes it offers "Keep it 10 more minutes" (new basket action `renew_holds`; holds are extended, never shortened). When a hold runs out, the customer is told which time was removed. - **Dates:** everything shown to people uses `en-GB` (day-month-year, 24-hour clock) and the studio's `SITE_TIMEZONE`, through `$shared/calendar` helpers. The server's default locale was en-US. Native date pickers still follow the visitor's browser language. Tested in headless Chromium with an **en-US / New York** browser, no console errors: jump to January 2027; 1 → 3 places with + disabled at full; back to 0 and the places return; remove on /book, then home shows 3 places left; countdown 10:00; at 1:29 the renew button appears and resets it to 10:00; a 4-second hold ends with the "ran out" message; admin shows "In a basket". Both apps type-check with 0 errors. 🤖 Generated with [Claude Code](https://claude.com/claude-code) https://claude.ai/code/session_01VaXE9U7AmW3dfD2w6cbLfk
agent added 3 commits 2026-10-24 09:41:39 +02:00
Migration adds the field to existing databases; pb_schema.json mirrors it
in the 0.23 top-level format (min/onlyInt under "options" is ignored).
Edited next to Duration in Services & products.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01VaXE9U7AmW3dfD2w6cbLfk
Generate fills a date range (weekdays x opening hours) spaced by the
service's duration + get-ready time (overridable). Copy repeats a week
into the next 1-12 weeks; Clear deletes free slots in a range. Each
previews first, skips past slots and overlaps with the same service, and
never touches booked or in-basket slots. Planning is pure and DST-safe in
$shared/slots.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01VaXE9U7AmW3dfD2w6cbLfk
/slots?month=YYYY-MM loads only that month's grid; chips coloured by
status, service filter, a day panel with add/copy/clear, and the month's
list collapsed below. The single-slot form is enhanced so saving keeps
the month. Docs updated.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01VaXE9U7AmW3dfD2w6cbLfk
agent changed title from Slots: bulk generate/copy/clear, per-service get-ready time, calendar view to Slots: bulk tools, get-ready time, group places, and bookings block overlapping slots 2026-10-24 10:27:04 +02:00
agent added 4 commits 2026-10-24 10:27:04 +02:00
Slots get a capacity (items.capacity is the service default). Booking
state is no longer stored on the slot: slotStates() in the shop hooks
counts places from paid order lines and live basket holds (heldUntil
moves to the basket line), and a slot with any place taken blocks every
overlapping slot of any service, including get-ready time.

GET /api/shop/slots lists bookable slots (public) or full detail for a
signed-in admin. add_slot takes seats and adds to an existing line;
group lines can change quantity. Checks and writes share one
transaction. Migration moves existing holds, drops the unique index and
slot status/heldUntil/order, and makes slots signed-in only.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01VaXE9U7AmW3dfD2w6cbLfk
Group times show places left and can be added again for another place;
the listing reloads after adding, since one booking can block other
times. Checkout gets a quantity stepper for group lines.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01VaXE9U7AmW3dfD2w6cbLfk
Calendar, day panel and list show available / in a basket / booked /
full / blocked (with what blocks it) and places taken. Services, Generate
and single slots take places (default from the service); Copy keeps
them. Once any place is taken only places (not below taken) and notes
can change. All reads go through the shop hook's slot details.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01VaXE9U7AmW3dfD2w6cbLfk
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01VaXE9U7AmW3dfD2w6cbLfk
agent added 4 commits 2026-10-24 11:32:59 +02:00
Formatting with the default locale rendered US dates (MM/DD/YYYY, 12-hour)
on the server. Everything shown to people now uses DISPLAY_LOCALE (en-GB)
and booking times use SITE_TIMEZONE. The public layout reloads on every
navigation so places left are never stale.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01VaXE9U7AmW3dfD2w6cbLfk
'Full' is now only for a group session filled by paid bookings.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01VaXE9U7AmW3dfD2w6cbLfk
Basket changes that free or take places reload the page data, so places
removed from the basket show up in the shop again.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01VaXE9U7AmW3dfD2w6cbLfk
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01VaXE9U7AmW3dfD2w6cbLfk
reudy merged commit 148b07253e into main 2026-10-24 12:15:35 +02:00
Sign in to join this conversation.
No reviewers
No labels
No milestone
No project
No assignees
1 participant
Notifications
Due date
The due date is invalid or out of range. Please use the format "yyyy-mm-dd".

No due date set.

Dependencies

No dependencies set.

Reference: reudy-net/domaino#3
No description provided.