Shop block: places left for group sessions, refresh after booking
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
This commit is contained in:
parent
d7765fe605
commit
5c6dff9e18
2 changed files with 15 additions and 7 deletions
|
|
@ -240,7 +240,8 @@
|
||||||
<p class="text-sm text-fg-body/70">{currency.format(line.itemPrice ?? 0)}</p>
|
<p class="text-sm text-fg-body/70">{currency.format(line.itemPrice ?? 0)}</p>
|
||||||
</div>
|
</div>
|
||||||
|
|
||||||
{#if line.lineType === 'item'}
|
<!-- Products, and places in a group session (capacity > 1); the server checks what's left. -->
|
||||||
|
{#if line.lineType === 'item' || (line.slotCapacity ?? 1) > 1}
|
||||||
<div class="flex items-center gap-2">
|
<div class="flex items-center gap-2">
|
||||||
<button
|
<button
|
||||||
type="button"
|
type="button"
|
||||||
|
|
|
||||||
|
|
@ -1,4 +1,5 @@
|
||||||
<script lang="ts">
|
<script lang="ts">
|
||||||
|
import { invalidateAll } from '$app/navigation';
|
||||||
import type { ShopBlockData, ItemRecord, SlotRecord } from '$shared/types';
|
import type { ShopBlockData, ItemRecord, SlotRecord } from '$shared/types';
|
||||||
import { getBasketContext } from '$shared/basket.svelte';
|
import { getBasketContext } from '$shared/basket.svelte';
|
||||||
import { getCurrentAndNextMonths } from '$shared/calendar';
|
import { getCurrentAndNextMonths } from '$shared/calendar';
|
||||||
|
|
@ -112,6 +113,9 @@
|
||||||
try {
|
try {
|
||||||
await basket.addSlotLine(slotId);
|
await basket.addSlotLine(slotId);
|
||||||
state.justAdded = true;
|
state.justAdded = true;
|
||||||
|
// A booking can block other times (one practitioner) or fill a
|
||||||
|
// group session — reload the listing so the picker shows that.
|
||||||
|
await invalidateAll();
|
||||||
} catch (e) {
|
} catch (e) {
|
||||||
state.errorMsg = errorMessage(e, 'Could not book this time slot.');
|
state.errorMsg = errorMessage(e, 'Could not book this time slot.');
|
||||||
} finally {
|
} finally {
|
||||||
|
|
@ -281,13 +285,16 @@
|
||||||
<p class="mt-4 mb-2 text-sm font-medium text-charcoal/70">Available times</p>
|
<p class="mt-4 mb-2 text-sm font-medium text-charcoal/70">Available times</p>
|
||||||
<div class="flex flex-wrap gap-2">
|
<div class="flex flex-wrap gap-2">
|
||||||
{#each daySlots as slot (slot.id)}
|
{#each daySlots as slot (slot.id)}
|
||||||
{@const slotInBasket = basket.lines.some((l) => l.slot === slot.id)}
|
{@const seatsInBasket = basket.lines.find((l) => l.slot === slot.id)?.quantity ?? 0}
|
||||||
|
{@const slotInBasket = seatsInBasket > 0}
|
||||||
|
{@const isGroup = slot.capacity > 1}
|
||||||
<button
|
<button
|
||||||
type="button"
|
type="button"
|
||||||
disabled={slotInBasket || ui.adding}
|
disabled={(slotInBasket && !isGroup) || ui.adding}
|
||||||
|
title={isGroup && slotInBasket ? 'Add another place' : undefined}
|
||||||
onclick={() => addSlot(item.id, slot.id)}
|
onclick={() => addSlot(item.id, slot.id)}
|
||||||
class="inline-flex items-center gap-1.5 rounded-full border px-3.5 py-1.5 text-sm transition {slotInBasket
|
class="inline-flex items-center gap-1.5 rounded-full border px-3.5 py-1.5 text-sm transition {slotInBasket
|
||||||
? 'cursor-not-allowed border-transparent bg-sage/15 text-sage-dark'
|
? `border-transparent bg-sage/15 text-sage-dark ${isGroup ? 'hover:bg-sage/30' : 'cursor-not-allowed'}`
|
||||||
: 'border-charcoal/15 bg-white text-charcoal hover:border-sage hover:bg-sage/10'} disabled:opacity-60 {ui.adding &&
|
: 'border-charcoal/15 bg-white text-charcoal hover:border-sage hover:bg-sage/10'} disabled:opacity-60 {ui.adding &&
|
||||||
!slotInBasket
|
!slotInBasket
|
||||||
? 'cursor-wait'
|
? 'cursor-wait'
|
||||||
|
|
@ -296,9 +303,9 @@
|
||||||
{#if ui.pendingSlotId === slot.id}
|
{#if ui.pendingSlotId === slot.id}
|
||||||
<span class="loading loading-spinner loading-xs"></span>
|
<span class="loading loading-spinner loading-xs"></span>
|
||||||
{/if}
|
{/if}
|
||||||
{formatTime(slot.start)}{item.duration != null ? ` · ${item.duration} min` : ''}{slotInBasket
|
{formatTime(slot.start)}{item.duration != null ? ` · ${item.duration} min` : ''}{isGroup
|
||||||
? ' · In basket'
|
? ` · ${slot.free} ${slot.free === 1 ? 'place' : 'places'} left`
|
||||||
: ''}
|
: ''}{slotInBasket ? (isGroup ? ` · ${seatsInBasket} in basket` : ' · In basket') : ''}
|
||||||
</button>
|
</button>
|
||||||
{/each}
|
{/each}
|
||||||
</div>
|
</div>
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue