Compare commits
No commits in common. "0b5cddb655e23e56f33c01e69f2bf437ea74552e" and "1f6d4806f9063479b830289e9c09cd58faa963e8" have entirely different histories.
0b5cddb655
...
1f6d4806f9
3 changed files with 21 additions and 11 deletions
|
|
@ -139,7 +139,7 @@ All routes in `app-admin` except `/login` are guarded in `src/hooks.server.ts`.
|
||||||
- `/pages/[slug]` — block editor with draft preview. Text is edited visually (headings, bold, italic, strikethrough, links, lists, pull quotes, lines; alignment and a small *footnote* size per block). Layouts have their own blocks: **Cards** (pictures or numbered steps, optionally linked — e.g. *Who I work with*, *Read next*, *How it works*) and **FAQ** (questions that open to show the answer). An **HTML** block takes raw HTML for embeds and one-offs (inline styles only; anything it loads from another site shares visitors' IPs). Every block has an *Anchor*, so a button or link to `#prices` jumps to it.
|
- `/pages/[slug]` — block editor with draft preview. Text is edited visually (headings, bold, italic, strikethrough, links, lists, pull quotes, lines; alignment and a small *footnote* size per block). Layouts have their own blocks: **Cards** (pictures or numbered steps, optionally linked — e.g. *Who I work with*, *Read next*, *How it works*) and **FAQ** (questions that open to show the answer). An **HTML** block takes raw HTML for embeds and one-offs (inline styles only; anything it loads from another site shares visitors' IPs). Every block has an *Anchor*, so a button or link to `#prices` jumps to it.
|
||||||
- `/calendar` — events shown by Upcoming Calendar blocks
|
- `/calendar` — events shown by Upcoming Calendar blocks
|
||||||
- `/items` — services, products and bundles shown in Shop blocks
|
- `/items` — services, products and bundles shown in Shop blocks
|
||||||
- `/slots` — when the practitioner can be booked: **windows** (e.g. 09:00–12:00, with the services bookable in it and where bookings may start — in fixed steps (every 10–60 min, default 30), or only at the start/end of the free time) and **group sessions** (one service at one of its lengths, fixed time, places). Month calendar, a day view with free time and bookings, and bulk tools — *Generate slots* (date range × weekdays × hours → windows, or sessions spaced by length + get-ready time), *Copy a week* (repeat into the next 1–12 weeks) and *Clear slots* (slots with nothing booked). No two slots may overlap (windows and group sessions alike); bulk tools preview first and skip past or overlapping slots. A window can't shrink past a booking in it.
|
- `/slots` — when the practitioner can be booked: **windows** (e.g. 09:00–12:00, with the services bookable in it and where bookings may start — in fixed steps (every 10–60 min, default 30), or only at the start/end of the free time) and **group sessions** (one service at one of its lengths, fixed time, places). Month calendar, a day view with free time and bookings, and bulk tools — *Generate slots* (date range × weekdays × hours → windows, or sessions spaced by length + get-ready time), *Copy a week* (repeat into the next 1–12 weeks) and *Clear slots* (slots with nothing booked). Windows may not overlap each other, nor sessions of the same service; bulk tools preview first and skip past or overlapping slots. A window can't shrink past a booking in it.
|
||||||
- `/items` lists each service's lengths and prices (*Lengths and prices* rows); the Shop block shows a slider between them.
|
- `/items` lists each service's lengths and prices (*Lengths and prices* rows); the Shop block shows a slider between them.
|
||||||
- `/passes` — *Vouchers & codes*: search codes (code, email, recipient, bundle), see what each has used/held/left and each part's share of the price, change the expiry, void/reactivate, and issue a code without a purchase
|
- `/passes` — *Vouchers & codes*: search codes (code, email, recipient, bundle), see what each has used/held/left and each part's share of the price, change the expiry, void/reactivate, and issue a code without a purchase
|
||||||
- `/orders` — confirmed bookings and purchases, with booking-email status and resend buttons
|
- `/orders` — confirmed bookings and purchases, with booking-email status and resend buttons
|
||||||
|
|
|
||||||
|
|
@ -26,7 +26,7 @@
|
||||||
<p class="font-semibold">Nothing to {deleting ? 'delete' : 'create'}.</p>
|
<p class="font-semibold">Nothing to {deleting ? 'delete' : 'create'}.</p>
|
||||||
{/if}
|
{/if}
|
||||||
<ul class="mt-1 list-inside list-disc text-base-content/70 empty:hidden">
|
<ul class="mt-1 list-inside list-disc text-base-content/70 empty:hidden">
|
||||||
{#if preview.skippedOverlap}<li>{plural(preview.skippedOverlap, 'slot')} skipped — it would overlap another slot.</li>{/if}
|
{#if preview.skippedOverlap}<li>{plural(preview.skippedOverlap, 'slot')} skipped — it would overlap another window, or a session of the same service.</li>{/if}
|
||||||
{#if preview.skippedPast}<li>{plural(preview.skippedPast, 'slot')} skipped — in the past.</li>{/if}
|
{#if preview.skippedPast}<li>{plural(preview.skippedPast, 'slot')} skipped — in the past.</li>{/if}
|
||||||
{#if preview.kept}<li>{plural(preview.kept, 'slot')} kept — something in it is booked, or in a customer’s basket right now.</li>{/if}
|
{#if preview.kept}<li>{plural(preview.kept, 'slot')} kept — something in it is booked, or in a customer’s basket right now.</li>{/if}
|
||||||
</ul>
|
</ul>
|
||||||
|
|
|
||||||
|
|
@ -123,19 +123,26 @@ function sessionFields(data: FormData, services: Service[]): SlotFields | { erro
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* A slot that `fields` would overlap (ignoring `exceptId`), or null — or undefined if PocketBase can't be read.
|
* Slots that may not overlap: windows with any other window (one
|
||||||
* No two slots may overlap, whatever their kind or service: one practitioner works them all.
|
* practitioner, one opening time), a group session with another session of
|
||||||
|
* the same service. A session may overlap a window — whichever is booked
|
||||||
|
* first blocks the other (see the README's Slot availability).
|
||||||
*/
|
*/
|
||||||
|
function clashKey(slot: Pick<SlotFields, 'kind' | 'items'>) {
|
||||||
|
return slot.kind === 'window' ? 'window' : `session:${slot.items[0] ?? ''}`;
|
||||||
|
}
|
||||||
|
|
||||||
|
/** A slot that `fields` would overlap (ignoring `exceptId`), or null — or undefined if PocketBase can't be read. */
|
||||||
async function clashingSlot(pb: Pb, fields: SlotFields, exceptId = '') {
|
async function clashingSlot(pb: Pb, fields: SlotFields, exceptId = '') {
|
||||||
const key = toZonedDatetimeInput(fields.start, siteTimezone()).slice(0, 10);
|
const key = toZonedDatetimeInput(fields.start, siteTimezone()).slice(0, 10);
|
||||||
const existing = await slotsForDays(pb, addDaysToKey(key, -1), addDaysToKey(key, 1));
|
const existing = await slotsForDays(pb, addDaysToKey(key, -1), addDaysToKey(key, 1));
|
||||||
if (!existing) return undefined;
|
if (!existing) return undefined;
|
||||||
return existing.slots.find((slot) => slot.id !== exceptId && overlapsAny(fields, [slot])) ?? null;
|
return existing.slots.find((slot) => slot.id !== exceptId && clashKey(slot) === clashKey(fields) && overlapsAny(fields, [slot])) ?? null;
|
||||||
}
|
}
|
||||||
|
|
||||||
function clashMessage(slot: SlotDetail) {
|
function clashMessage(slot: SlotDetail) {
|
||||||
const time = `${toZonedDatetimeInput(slot.start, siteTimezone()).replace('T', ' ')}–${toZonedDatetimeInput(slot.end, siteTimezone()).slice(11)}`;
|
const time = `${toZonedDatetimeInput(slot.start, siteTimezone()).replace('T', ' ')}–${toZonedDatetimeInput(slot.end, siteTimezone()).slice(11)}`;
|
||||||
return slot.kind === 'window' ? `This overlaps the window ${time}. Change or delete that one first.` : `This overlaps the ${slot.itemNames[0] ?? ''} group session ${time}. Change or delete that one first.`;
|
return slot.kind === 'window' ? `This overlaps the window ${time}. Change that one instead.` : `This overlaps another ${slot.itemNames[0] ?? ''} session (${time}).`;
|
||||||
}
|
}
|
||||||
|
|
||||||
/** Validated `from`/`to` date keys from a bulk form, or an error message. */
|
/** Validated `from`/`to` date keys from a bulk form, or an error message. */
|
||||||
|
|
@ -157,12 +164,13 @@ function slotsForDays(pb: Pb, fromKey: string, toKey: string, item = '') {
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Drop candidates that start in the past or overlap another slot (existing,
|
* Drop candidates that start in the past or overlap a slot they may not
|
||||||
* or accepted earlier in this run — see clashingSlot).
|
* overlap (existing, or accepted earlier in this run — see clashKey).
|
||||||
*/
|
*/
|
||||||
function filterCandidates(candidates: SlotFields[], existing: SlotDetail[]) {
|
function filterCandidates(candidates: SlotFields[], existing: SlotDetail[]) {
|
||||||
const now = Date.now();
|
const now = Date.now();
|
||||||
const taken: PlannedSlot[] = [...existing];
|
const taken = new Map<string, PlannedSlot[]>();
|
||||||
|
for (const slot of existing) taken.set(clashKey(slot), [...(taken.get(clashKey(slot)) ?? []), slot]);
|
||||||
|
|
||||||
const accepted: SlotFields[] = [];
|
const accepted: SlotFields[] = [];
|
||||||
let skippedPast = 0;
|
let skippedPast = 0;
|
||||||
|
|
@ -172,11 +180,13 @@ function filterCandidates(candidates: SlotFields[], existing: SlotDetail[]) {
|
||||||
skippedPast++;
|
skippedPast++;
|
||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
if (overlapsAny(candidate, taken)) {
|
const ranges = taken.get(clashKey(candidate)) ?? [];
|
||||||
|
if (overlapsAny(candidate, ranges)) {
|
||||||
skippedOverlap++;
|
skippedOverlap++;
|
||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
taken.push(candidate);
|
ranges.push(candidate);
|
||||||
|
taken.set(clashKey(candidate), ranges);
|
||||||
accepted.push(candidate);
|
accepted.push(candidate);
|
||||||
}
|
}
|
||||||
accepted.sort((a, b) => instantMs(a.start) - instantMs(b.start));
|
accepted.sort((a, b) => instantMs(a.start) - instantMs(b.start));
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue