From b52da79ec8a6ec073f9570030d5677bc9c46e6da Mon Sep 17 00:00:00 2001 From: agent Date: Sat, 24 Oct 2026 07:41:17 +0000 Subject: [PATCH] Slots: month calendar view with day panel /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 Claude-Session: https://claude.ai/code/session_01VaXE9U7AmW3dfD2w6cbLfk --- AGENTS.md | 7 +- README.md | 6 +- app-admin/src/routes/slots/+page.svelte | 213 ++++++++++++++++++++++-- 3 files changed, 206 insertions(+), 20 deletions(-) diff --git a/AGENTS.md b/AGENTS.md index d9281ce..5e7446d 100644 --- a/AGENTS.md +++ b/AGENTS.md @@ -14,7 +14,7 @@ packages/shared/src/ # Shared code (types, calendar utils, blocks, pb, app-admin/ # SvelteKit admin app (serves admin.) ├── src/ │ ├── lib/ -│ │ ├── admin/ # Admin UI components (BlockList, Modal, editors, confirm/unsaved helpers) +│ │ ├── admin/ # Admin UI components (BlockList, Modal, editors, confirm/unsaved helpers, slots/ bulk modals) │ │ ├── blocks/ # Re-exports from $shared/blocks (block renderers live in shared) │ │ ├── pb.ts # Re-exports from $shared/pb + app-specific uploadMedia │ │ ├── types.ts # Re-exports from $shared @@ -22,14 +22,14 @@ app-admin/ # SvelteKit admin app (serves admin.) │ │ ├── scrollReveal.ts # Re-exports from $shared │ │ ├── stripe-client.ts # Re-exports from $shared │ │ ├── basket.svelte.ts # Re-exports from $shared -│ │ └── server/ # Re-exports from $shared/server + admin helpers (actions.ts, pages.ts) +│ │ └── server/ # Re-exports from $shared/server + admin helpers (actions.ts, pages.ts, slots.ts) │ ├── routes/ │ │ ├── +layout.svelte # Root layout (admin shell: grouped sidebar; bare on /login and /preview) │ │ ├── login/ # Admin login │ │ ├── pages/ # Page CRUD + block editor │ │ ├── calendar/ # Event CRUD (menu label: Events) │ │ ├── items/ # Service/product CRUD (menu label: Services & products) -│ │ ├── slots/ # Bookable time slot CRUD +│ │ ├── slots/ # Bookable slots: month calendar (?month=YYYY-MM), CRUD, bulk generate/copy/clear │ │ ├── orders/ # Order list + booking-email status/resend │ │ ├── emails/ # Block-based booking email editor (live preview, test send) │ │ ├── globals/ # Header/footer/colors editor (menu label: Site design) @@ -118,6 +118,7 @@ To add an email block type: add to `EmailBlockType` in `packages/shared/src/type ### Shared Code - `packages/shared/src/types.ts` — all type definitions - `packages/shared/src/calendar.ts` — calendar utilities (used by admin calendar editor and public upcoming calendar block) +- `packages/shared/src/slots.ts` — pure slot planning (generate/copy-week maths on date keys + wall-clock times in `SITE_TIMEZONE`, DST-safe); the `/slots` actions use it via `$lib/slots`, PocketBase I/O is in `app-admin/src/lib/server/slots.ts` - Each app's `svelte.config.js` declares `kit.alias.$shared → '../packages/shared/src'` - Each app's `src/lib/types.ts` and `src/lib/calendar.ts` re-export from `$shared` so existing `$lib/types` and `$lib/calendar` imports work diff --git a/README.md b/README.md index 60e87fe..1d1a468 100644 --- a/README.md +++ b/README.md @@ -112,7 +112,7 @@ If schema import fails because of a PocketBase version mismatch, create these co Commerce collections (see the Stripe section above for context): -- `items` — `name` text, `description` text, `price` number, `image` relation→media, `type` select `item|item_with_time`, `stock` number (nullable), `duration` number (nullable, minutes), `active` bool +- `items` — `name` text, `description` text, `price` number, `image` relation→media, `type` select `item|item_with_time`, `stock` number (nullable), `duration` number (nullable, minutes), `bufferMinutes` number (nullable, get-ready minutes after each appointment), `active` bool - `slots` — `item` relation→items, `start` date, `end` date, `status` select `available|held|booked`, `heldUntil` date (nullable), `order` relation→orders (nullable), `notes` text - `baskets` — `status` select `active|completed|abandoned`, `expiresAt` date, `email` text, `customerDetails` json, `stripePaymentIntentId` text - `basket_lines` — `basket` relation→baskets, `item` relation→items, `slot` relation→slots (nullable), `quantity` number, `lineType` select `item|slot` @@ -120,7 +120,7 @@ Commerce collections (see the Stripe section above for context): - `order_lines` — `order` relation→orders, `item` relation→items, `slot` relation→slots (nullable), `quantity` number, `lineType` select `item|slot`, `name` text (snapshot), `price` number (snapshot), `start` date (nullable, snapshot) - `email_templates` — `key` text (unique: `customer_confirmation` | `client_alert`), `subject` text, `blocks` json, `recipients` text, `enabled` bool -> **Schema format note:** `pb_schema.json` targets PocketBase 0.23+ using the `fields` array (not the legacy `schema` array). Relation and select fields carry their config (`collectionId`, `cascadeDelete`, `maxSelect`, `values`) at the field top level, not nested under `options`. Importing the whole file via the PocketBase admin UI or `PUT /api/collections/import` creates or updates all collections in one pass. +> **Schema format note:** `pb_schema.json` targets PocketBase 0.23+ using the `fields` array (not the legacy `schema` array). Field config (`collectionId`, `cascadeDelete`, `maxSelect`, `values`, number `min`/`max`/`onlyInt`) belongs at the field top level — 0.23 silently ignores anything nested under `options`, so the older number/text fields that still use `options` get no min/max on a fresh install. Importing the whole file via the PocketBase admin UI or `PUT /api/collections/import` creates or updates all collections in one pass. ## Authentication @@ -138,7 +138,7 @@ All routes in `app-admin` except `/login` are guarded in `src/hooks.server.ts`. - `/pages/[slug]` — block editor with draft preview - `/calendar` — events shown by Upcoming Calendar blocks - `/items` — services and products shown in Shop blocks -- `/slots` — manually created bookable time slots for services +- `/slots` — bookable time slots: month calendar, single slots, and bulk tools — *Generate slots* (date range × weekdays × opening hours, spaced by the service's duration + get-ready time), *Copy a week* (repeat into the next 1–12 weeks) and *Clear slots* (free slots only). Bulk tools preview first, skip slots in the past or overlapping a slot of the same service, and never touch booked or in-basket slots. Different services may overlap — there is no cross-service collision check. - `/orders` — confirmed bookings and purchases, with booking-email status and resend buttons - `/emails` — block-based editor for the booking confirmation and new-booking alert emails (live preview, test send) - `/globals` — header/footer/colors editor diff --git a/app-admin/src/routes/slots/+page.svelte b/app-admin/src/routes/slots/+page.svelte index 4c5b1f1..65aafdf 100644 --- a/app-admin/src/routes/slots/+page.svelte +++ b/app-admin/src/routes/slots/+page.svelte @@ -1,13 +1,80 @@ @@ -57,19 +144,79 @@

Slots

-

Create bookable time slots for your services. Times are in {data.timezone}.

+

Bookable time slots for your services. Times are in {data.timezone}.

+
+
+ + + +
-
{#if form?.message}{/if} + {#if bulkDone}
{bulkMessage(bulkDone)}
{/if} + {#if !items.length}
Add a bookable service under Services & products first.
{/if}
-
+
+ +

{monthLabel}

+ +
+ +
+ {#each WEEKDAYS as weekday (weekday.day)}
{weekday.label}
{/each} +
+
+ {#each gridKeys as key (key)} + {@const daySlotList = slotsByDay.get(key) ?? []} + {@const isToday = key === data.today} +
+ +
+ {#each daySlotList.slice(0, MAX_CHIPS) as slot (slot.id)} + + {/each} + {#if daySlotList.length > MAX_CHIPS} + + {/if} +
+
+ {/each} +
+ +
+ Available + In a basket + Booked +
+
+ + +
+ All slots in {monthLabel} ({monthSlots.length}) +
- {#each slots as slot (slot.id)} + {#each monthSlots as slot (slot.id)} @@ -87,18 +234,56 @@ {:else} - + {/each}
ServiceDateDurationStatus
{slot.itemName} {formatDateTime(slot.start, data.timezone)}
{items.length ? 'No slots yet — create one so customers can book.' : 'Add a bookable service under Services & products first.'}
No slots this month — use “Generate slots” to fill it.
-
+ + + + + + + {#if daySlots.length} +
    + {#each daySlots as slot (slot.id)} +
  • + {formatTime(slot.start, data.timezone)}{slot.end ? `–${formatTime(slot.end, data.timezone)}` : ''} + + {slot.itemName} + {#if slot.notes}{slot.notes}{/if} + + {slot.status} + +
  • + {/each} +
+ {:else} +

No slots on this day{serviceFilter ? ' for this service' : ''}.

+ {/if} + +
+ -
+ + {#if editorError}{/if} + {#if isHeld}
This slot is in a customer’s basket{draft.heldUntil ? ` until ${formatTime(draft.heldUntil, data.timezone)}` : ''} — only the notes can be changed.