Compare commits

..

6 commits

Author SHA1 Message Date
95a3c6d6b3 Merge pull request 'Optional basket page; Button blocks follow the site colour; Site design tidy-up' (#9) from booking-basket-pages into main
Reviewed-on: #9
2026-10-26 13:09:24 +01:00
29bbdf267c Site design: fading "Saved.", tooltips, CTA page check, home page first
- "Saved." slides in and collapses away after 2.5 s (no motion with
  prefers-reduced-motion); errors stay until the next save.
- The CTA and basket hints are short tooltips on an info button
  (hover or keyboard focus) instead of paragraphs.
- A CTA address like "/book" is checked like the basket slug: warns
  when no page has that slug or it isn't published.
- Home page moves above Navigation.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01Hy2vMnHJYP7QGsiH21zHxW
2026-10-26 12:07:15 +00:00
68c67d7e96 Site design: type the basket page's slug instead of picking it
Like the CTA's address, the basket page is now a text box. Slashes and
spaces around the slug are ignored, and Site design warns when no page
has that slug.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01Hy2vMnHJYP7QGsiH21zHxW
2026-10-26 11:50:53 +00:00
f20d6777ab Site design: the CTA keeps its address, the basket page is optional
Instead of a separate booking page setting, booking links lead to the
header button's own address again, and the basket page falls back to
that address when it isn't set. Site design warns when the basket's
page isn't published or has no Checkout block.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01Hy2vMnHJYP7QGsiH21zHxW
2026-10-26 11:44:03 +00:00
ec1156b1fa Button block: primary buttons take the site colour
The variant class was built as `btn-${variant}`. Tailwind only generates
classes written out in the source, and nothing in the public app spells
out `btn-primary`, so primary Button blocks rendered as plain grey
buttons on the live site (the admin preview, which uses btn-primary
elsewhere, looked right).

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01Hy2vMnHJYP7QGsiH21zHxW
2026-10-26 11:44:03 +00:00
c3c10229b0 Site design: separate booking page and basket page
The header button, the basket indicator, the shop's "view basket" links,
hero buttons and the payment return page all pointed at a hard-coded
/book. Site design now has a Booking page (where the CTA leads) and a
Basket page (where the basket leads; empty = the booking page), and
warns when the page picked is unpublished or lacks its Shop / Checkout
block. On a basket page of its own, an empty basket links to the
booking page instead of saying "pick a service above".

Sites saved before this keep their links: the booking page falls back
to the CTA's old address, then /book.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01Hy2vMnHJYP7QGsiH21zHxW
2026-10-26 11:19:54 +00:00
13 changed files with 131 additions and 33 deletions

View file

@ -154,6 +154,8 @@ To add an email block type: add to `EmailBlockType` in `packages/shared/src/type
### Routing ### Routing
- **Admin app** (`app-admin`): All routes except `/login` are auth-guarded in `hooks.server.ts` (which also refreshes the token per request and sets the cookie's `Secure` flag from the real scheme). The root layout renders the admin shell (grouped sidebar) except on `/login` and `/preview`. The `/preview` route reads `sessionStorage` set by the page editor (same-origin, so it works). - **Admin app** (`app-admin`): All routes except `/login` are auth-guarded in `hooks.server.ts` (which also refreshes the token per request and sets the cookie's `Secure` flag from the real scheme). The root layout renders the admin shell (grouped sidebar) except on `/login` and `/preview`. The `/preview` route reads `sessionStorage` set by the page editor (same-origin, so it works).
- **Public app** (`app-public`): No auth guard. The root layout always renders Header/Footer. `+layout.server.ts` fetches header/footer/colors globals + basket/items/slots for every page. - **Public app** (`app-public`): No auth guard. The root layout always renders Header/Footer. `+layout.server.ts` fetches header/footer/colors globals + basket/items/slots for every page.
- **Booking and basket links**: booking = the header CTA's address, basket = the optional basket page slug typed in Site design (`header.basketPage`; '' = the CTA's address), both from `shopLinks(header)` in `packages/shared/src/types.ts` (blocks read `page.data.header`) — never hard-code `/book`.
- **Class names in components are written out whole** (`'btn-primary'`, not `` `btn-${variant}` ``): Tailwind only generates classes it finds in the source, so a built-up name silently gets no style.
- `+page.server.ts` for home fetches `slug = "home" && published = true` - `+page.server.ts` for home fetches `slug = "home" && published = true`
- `[slug]/+page.server.ts` fetches by dynamic slug - `[slug]/+page.server.ts` fetches by dynamic slug

View file

@ -172,7 +172,7 @@ Setup:
``` ```
Copy the printed `whsec_…` signing secret into `STRIPE_WEBHOOK_SECRET`. Copy the printed `whsec_…` signing secret into `STRIPE_WEBHOOK_SECRET`.
4. Import the updated `pb_schema.json` (adds `items`, `slots`, `baskets`, `basket_lines`, `orders`, `order_lines`). Two visitors can't take the same place: holds are checked and written in one PocketBase transaction (see *Slot availability*). 4. Import the updated `pb_schema.json` (adds `items`, `slots`, `baskets`, `basket_lines`, `orders`, `order_lines`). Two visitors can't take the same place: holds are checked and written in one PocketBase transaction (see *Slot availability*).
5. Create a published page (e.g. slug `book`) with a `shop` block and a `checkout` block, and point the header CTA at it. 5. Create a published page (e.g. slug `book`) with a `shop` block and point the header CTA at it (*Site design → Header*); hero buttons without an address and *Book another* after paying lead there too. Put a `checkout` block on the same page, or on a page of its own whose slug you type as the optional *Basket page*: the basket in the header and *view basket* in the shop lead there (empty = the CTA's address). Site design warns when the basket's page isn't published or has no `checkout` block.
## Bundles and codes ## Bundles and codes

View file

@ -33,7 +33,7 @@ export function createBlock(type: BlockType): ContentBlock {
heading: 'Holistic and Experiential Learning about Happiness', heading: 'Holistic and Experiential Learning about Happiness',
subheading: 'Individual sessions, workshops and events in Oslo', subheading: 'Individual sessions, workshops and events in Oslo',
buttonLabel: 'BOOK NOW', buttonLabel: 'BOOK NOW',
buttonUrl: '/book' buttonUrl: ''
}; };
break; break;
case 'button': case 'button':

View file

@ -101,7 +101,7 @@
{@render field('Subheading', block.data.subheading || '', (subheading) => updateData({ subheading }))} {@render field('Subheading', block.data.subheading || '', (subheading) => updateData({ subheading }))}
<div class="grid gap-x-4 md:grid-cols-2"> <div class="grid gap-x-4 md:grid-cols-2">
{@render field('Button label', block.data.buttonLabel || '', (buttonLabel) => updateData({ buttonLabel }))} {@render field('Button label', block.data.buttonLabel || '', (buttonLabel) => updateData({ buttonLabel }))}
{@render field('Button URL', block.data.buttonUrl || '', (buttonUrl) => updateData({ buttonUrl }), '/page or https://…')} {@render field('Button URL', block.data.buttonUrl || '', (buttonUrl) => updateData({ buttonUrl }), 'Empty = the CTA button’s address')}
</div> </div>
{:else if block.type === 'button'} {:else if block.type === 'button'}
<div class="grid gap-x-4 md:grid-cols-2"> <div class="grid gap-x-4 md:grid-cols-2">

View file

@ -27,8 +27,13 @@ export const load: PageServerLoad = async ({ locals }) => {
getGlobal(locals.pb, 'colors', defaultColors) getGlobal(locals.pb, 'colors', defaultColors)
]); ]);
// Fetch all pages for the home page selector // All pages for the page selectors, with what the basket setting warns
const pages = await locals.pb.collection('pages').getFullList({ sort: 'slug', fields: 'id,slug,title' }); // about (unpublished, no Checkout block).
const records = await locals.pb.collection('pages').getFullList({ sort: 'slug', fields: 'id,slug,title,published,blocks' });
const pages = records.map((page) => {
const types = new Set(((page.blocks as { type?: string }[]) || []).map((block) => block.type));
return { id: page.id, slug: page.slug, title: page.title, published: !!page.published, hasCheckout: types.has('checkout') };
});
return { header, footer, colors, pages }; return { header, footer, colors, pages };
}; };

View file

@ -1,7 +1,10 @@
<script lang="ts"> <script lang="ts">
import { browser } from '$app/environment';
import { enhance } from '$app/forms'; import { enhance } from '$app/forms';
import { fly, slide } from 'svelte/transition';
import ImageUploader from '$lib/admin/editors/ImageUploader.svelte'; import ImageUploader from '$lib/admin/editors/ImageUploader.svelte';
import { PRIVACY_PAGE_SLUG } from '$lib/admin/privacyTemplate'; import { PRIVACY_PAGE_SLUG } from '$lib/admin/privacyTemplate';
import { shopLinks } from '$lib/types';
import type { SubmitFunction } from '@sveltejs/kit'; import type { SubmitFunction } from '@sveltejs/kit';
let { data, form } = $props(); let { data, form } = $props();
@ -9,8 +12,9 @@
let footer = $state(structuredClone(data.footer.data)); let footer = $state(structuredClone(data.footer.data));
let colors = $state(structuredClone(data.colors.data)); let colors = $state(structuredClone(data.colors.data));
let saving = $state(''); let saving = $state('');
// Older records may predate the CTA button; the inputs below need an object. // Older records may predate the CTA button and the basket page; the inputs below need values.
header.ctaButton ??= { label: '', href: '' }; header.ctaButton ??= { label: '', href: '' };
header.basketPage ??= '';
footer.privacyPage ??= ''; footer.privacyPage ??= '';
function addHeaderLink() { header.navLinks = [...(header.navLinks || []), { label: '', href: '' }]; } function addHeaderLink() { header.navLinks = [...(header.navLinks || []), { label: '', href: '' }]; }
@ -34,10 +38,45 @@
{ key: 'accent', label: 'Accent', hint: 'Highlights' } { key: 'accent', label: 'Accent', hint: 'Highlights' }
]; ];
const pageBySlug = (slug: string) => data.pages.find((page) => page.slug === slug);
// Only addresses like "/book" are checked: the CTA may also point to "/" or another site.
function ctaProblem() {
const slug = header.ctaButton.href?.trim().match(/^\/([^/?#]+)\/?$/)?.[1];
if (!slug) return '';
const page = pageBySlug(slug);
if (!page) return `There is no page with the slug “${slug}”.`;
if (!page.published) return `“${page.title}” isn’t published yet.`;
return '';
}
// The page the basket links lead to: the basket page, else the CTA's address when that is a page here.
function basketProblem() {
const slug = shopLinks(header).basket.replace(/^\/|\/$/g, '');
const page = pageBySlug(slug);
// The CTA may point anywhere (even another site); a typed basket slug must be a page here.
if (!page) return header.basketPage?.trim() ? `There is no page with the slug “${slug}”.` : '';
if (!page.published) return `“${page.title}” isn’t published yet.`;
if (!page.hasCheckout) return `“${page.title}” has no Checkout block, so people can’t pay from it.`;
return '';
}
const isHex = (value: unknown) => typeof value === 'string' && /^#[0-9a-f]{6}$/i.test(value); const isHex = (value: unknown) => typeof value === 'string' && /^#[0-9a-f]{6}$/i.test(value);
// "Saved." goes away by itself after a moment; an error stays until the next save.
let statusShown = $state('');
$effect(() => {
if (!form?.section || !form.message) return;
statusShown = form.section;
if (!form.ok) return;
const timer = setTimeout(() => (statusShown = ''), 2500);
return () => clearTimeout(timer);
});
const motion = (ms: number) => (browser && matchMedia('(prefers-reduced-motion: reduce)').matches ? 0 : ms);
const submit: SubmitFunction = ({ formData }) => { const submit: SubmitFunction = ({ formData }) => {
saving = String(formData.get('section')); saving = String(formData.get('section'));
statusShown = '';
return async ({ update }) => { return async ({ update }) => {
// Re-run loads so the admin theme picks up saved colours immediately. // Re-run loads so the admin theme picks up saved colours immediately.
await update({ reset: false }); await update({ reset: false });
@ -49,11 +88,23 @@
<svelte:head><title>Site design | CMS</title></svelte:head> <svelte:head><title>Site design | CMS</title></svelte:head>
{#snippet status(section: string)} {#snippet status(section: string)}
{#if form?.section === section && form.message} {#if statusShown === section && form?.section === section && form.message}
<div class="alert mt-4 py-2 text-sm" class:alert-success={form.ok} class:alert-error={!form.ok} role="status">{form.message}</div> <div class="alert mt-4 py-2 text-sm" class:alert-success={form.ok} class:alert-error={!form.ok} role="status" in:fly={{ y: 8, duration: motion(200) }} out:slide={{ duration: motion(350) }}>
{form.message}
</div>
{/if} {/if}
{/snippet} {/snippet}
{#snippet info(text: string)}
<span class="tooltip tooltip-right font-sans font-normal before:max-w-48" data-tip={text}>
<button class="btn btn-circle btn-ghost btn-xs text-base-content/60" type="button" aria-label={text}>
<svg xmlns="http://www.w3.org/2000/svg" class="h-4 w-4" fill="none" viewBox="0 0 24 24" stroke="currentColor" stroke-width="2" aria-hidden="true">
<circle cx="12" cy="12" r="9" /><path stroke-linecap="round" d="M12 11v5M12 8h.01" />
</svg>
</button>
</span>
{/snippet}
{#snippet saveButton(section: string, label: string)} {#snippet saveButton(section: string, label: string)}
<div class="flex-grow"></div> <div class="flex-grow"></div>
{@render status(section)} {@render status(section)}
@ -76,6 +127,14 @@
<h2 class="mb-4 text-2xl font-bold">Header</h2> <h2 class="mb-4 text-2xl font-bold">Header</h2>
<h3 class="mb-2 font-bold">Logo</h3> <h3 class="mb-2 font-bold">Logo</h3>
<ImageUploader url={header.logo?.url} alt={header.logo?.alt} onChange={(image) => (header.logo = image)} /> <ImageUploader url={header.logo?.url} alt={header.logo?.alt} onChange={(image) => (header.logo = image)} />
<h3 class="mt-6 mb-2 font-bold">Home page</h3>
<select class="select w-full" aria-label="Home page" bind:value={header.homePage}>
<option value="">— Select a page —</option>
{#each data.pages as page (page.id)}
<option value={page.slug}>{page.title} [{page.slug}]</option>
{/each}
</select>
<p class="mt-1 text-sm text-base-content/60">The page that "/" will redirect to.</p>
<h3 class="mt-6 font-bold">Navigation</h3> <h3 class="mt-6 font-bold">Navigation</h3>
{#each header.navLinks || [] as link, i} {#each header.navLinks || [] as link, i}
<div class="my-2 grid grid-cols-[1fr_1fr_auto] gap-2"> <div class="my-2 grid grid-cols-[1fr_1fr_auto] gap-2">
@ -85,19 +144,18 @@
</div> </div>
{/each} {/each}
<button class="btn btn-sm mt-1" type="button" onclick={addHeaderLink}>Add link</button> <button class="btn btn-sm mt-1" type="button" onclick={addHeaderLink}>Add link</button>
<h3 class="mt-6 mb-2 font-bold">CTA button</h3> <h3 class="mt-6 mb-2 flex items-center gap-1 font-bold">CTA button {@render info('Hero buttons without a link and “Book another” after paying go here too.')}</h3>
<div class="grid grid-cols-2 gap-2"> <div class="grid grid-cols-2 gap-2">
<input class="input w-full" aria-label="Button label" bind:value={header.ctaButton.label} placeholder="Label" /> <input class="input w-full" aria-label="Button label" bind:value={header.ctaButton.label} placeholder="Label" />
<input class="input w-full" aria-label="Button address" bind:value={header.ctaButton.href} placeholder="/book" /> <input class="input w-full" aria-label="Button address" bind:value={header.ctaButton.href} placeholder="/book" />
</div> </div>
<h3 class="mt-6 mb-2 font-bold">Home page</h3> {#if ctaProblem()}<p class="mt-1 text-sm font-semibold">⚠ {ctaProblem()}</p>{/if}
<select class="select w-full" aria-label="Home page" bind:value={header.homePage}> <h3 class="mt-6 mb-2 flex items-center gap-1 font-bold">
<option value="">— Select a page —</option> Basket page <span class="font-normal text-base-content/50">(optional)</span>
{#each data.pages as page (page.id)} {@render info('Slug of the page with the Checkout block. Empty = the CTA button’s page.')}
<option value={page.slug}>{page.title} [{page.slug}]</option> </h3>
{/each} <input class="input w-full" aria-label="Basket page" bind:value={header.basketPage} placeholder="e.g. basket" />
</select> {#if basketProblem()}<p class="mt-1 text-sm font-semibold">⚠ {basketProblem()}</p>{/if}
<p class="mt-1 text-sm text-base-content/60">The page that "/" will redirect to.</p>
{@render saveButton('header', 'Save header')} {@render saveButton('header', 'Save header')}
</form> </form>

View file

@ -1,7 +1,7 @@
<script lang="ts"> <script lang="ts">
import { afterNavigate } from '$app/navigation'; import { afterNavigate } from '$app/navigation';
import { page } from '$app/state'; import { page } from '$app/state';
import type { HeaderGlobal } from '$lib/types'; import { shopLinks, type HeaderGlobal } from '$lib/types';
import { getBasketContext } from '$lib/basket.svelte'; import { getBasketContext } from '$lib/basket.svelte';
import { DEFAULT_CURRENCY, formatPrice } from '$shared/calendar'; import { DEFAULT_CURRENCY, formatPrice } from '$shared/calendar';
@ -9,6 +9,7 @@
const basket = getBasketContext(); const basket = getBasketContext();
let hasItems = $derived(basket.count > 0); let hasItems = $derived(basket.count > 0);
let links = $derived(shopLinks(header));
// Phone menu: a native modal <dialog> sliding in from the right, so focus // Phone menu: a native modal <dialog> sliding in from the right, so focus
// trapping, Escape and the inert page behind come from the browser. // trapping, Escape and the inert page behind come from the browser.
@ -64,7 +65,7 @@
{#if hasItems} {#if hasItems}
<a <a
class="relative flex items-center gap-2 rounded-full border border-charcoal/10 px-3 py-2 text-sm font-semibold text-charcoal/80 transition hover:border-sage hover:text-sage-dark md:px-4" class="relative flex items-center gap-2 rounded-full border border-charcoal/10 px-3 py-2 text-sm font-semibold text-charcoal/80 transition hover:border-sage hover:text-sage-dark md:px-4"
href="/book" href={links.basket}
aria-label="View your basket ({basket.count})" aria-label="View your basket ({basket.count})"
> >
{@render basketIcon()} {@render basketIcon()}
@ -73,7 +74,7 @@
</a> </a>
{/if} {/if}
{#if header.ctaButton?.label} {#if header.ctaButton?.label}
<a class="cta btn hidden rounded-full border-0 px-6 hover:opacity-90 md:inline-flex" href={header.ctaButton.href}>{header.ctaButton.label}</a> <a class="cta btn hidden rounded-full border-0 px-6 hover:opacity-90 md:inline-flex" href={links.booking}>{header.ctaButton.label}</a>
{/if} {/if}
<button <button
class="grid h-10 w-10 place-items-center rounded-full text-charcoal/80 transition hover:bg-charcoal/5 md:hidden" class="grid h-10 w-10 place-items-center rounded-full text-charcoal/80 transition hover:bg-charcoal/5 md:hidden"
@ -118,7 +119,7 @@
</ul> </ul>
{#if hasItems} {#if hasItems}
<a class="mx-1 mt-6 flex items-center gap-3 rounded-xl border border-charcoal/10 px-4 py-3 font-semibold text-charcoal/80 transition hover:border-sage" href="/book"> <a class="mx-1 mt-6 flex items-center gap-3 rounded-xl border border-charcoal/10 px-4 py-3 font-semibold text-charcoal/80 transition hover:border-sage" href={links.basket}>
{@render basketIcon()} {@render basketIcon()}
<span class="flex-1">Basket ({basket.count})</span> <span class="flex-1">Basket ({basket.count})</span>
<span class="text-charcoal/60">{formatTotal(basket.total)}</span> <span class="text-charcoal/60">{formatTotal(basket.total)}</span>
@ -128,7 +129,7 @@
{#if header.ctaButton?.label} {#if header.ctaButton?.label}
<div class="border-t border-charcoal/10 p-6"> <div class="border-t border-charcoal/10 p-6">
<a class="cta btn btn-block rounded-full border-0 hover:opacity-90" href={header.ctaButton.href}>{header.ctaButton.label}</a> <a class="cta btn btn-block rounded-full border-0 hover:opacity-90" href={links.booking}>{header.ctaButton.label}</a>
</div> </div>
{/if} {/if}
</div> </div>

View file

@ -2,8 +2,10 @@
import { onMount } from 'svelte'; import { onMount } from 'svelte';
import { formatInstant, formatPrice } from '$shared/calendar'; import { formatInstant, formatPrice } from '$shared/calendar';
import { formatDuration } from '$shared/items'; import { formatDuration } from '$shared/items';
import { shopLinks } from '$lib/types';
let { data } = $props(); let { data } = $props();
let links = $derived(shopLinks(data.header));
// "Friday 15 January, 10:00" in the studio's timezone. // "Friday 15 January, 10:00" in the studio's timezone.
function formatSlotDate(iso?: string | null) { function formatSlotDate(iso?: string | null) {
@ -68,7 +70,7 @@
</div> </div>
{/if} {/if}
<a class="btn mt-8 rounded-full border-0 px-8 text-primary-content" style="background-color: var(--color-primary, #8a9a7b);" href="/">Book another</a> <a class="btn mt-8 rounded-full border-0 px-8 text-primary-content" style="background-color: var(--color-primary, #8a9a7b);" href={links.booking}>Book another</a>
{:else if data.state === 'processing'} {:else if data.state === 'processing'}
<h1 class="font-serif text-4xl">Processing your payment…</h1> <h1 class="font-serif text-4xl">Processing your payment…</h1>
<p class="mt-3 text-charcoal/70"> <p class="mt-3 text-charcoal/70">
@ -80,10 +82,10 @@
{:else if data.state === 'canceled' || data.state === 'failed'} {:else if data.state === 'canceled' || data.state === 'failed'}
<h1 class="font-serif text-4xl">Payment not completed</h1> <h1 class="font-serif text-4xl">Payment not completed</h1>
<p class="mt-3 text-charcoal/70">Your payment didn't go through — no money was captured. Please try again.</p> <p class="mt-3 text-charcoal/70">Your payment didn't go through — no money was captured. Please try again.</p>
<a class="btn mt-8 rounded-full border-0 px-8 text-primary-content" style="background-color: var(--color-primary, #8a9a7b);" href="/">Back to the shop</a> <a class="btn mt-8 rounded-full border-0 px-8 text-primary-content" style="background-color: var(--color-primary, #8a9a7b);" href={links.basket}>Back to your basket</a>
{:else} {:else}
<h1 class="font-serif text-4xl">Nothing to see here</h1> <h1 class="font-serif text-4xl">Nothing to see here</h1>
<p class="mt-3 text-charcoal/70">This link is missing a payment reference.</p> <p class="mt-3 text-charcoal/70">This link is missing a payment reference.</p>
<a class="btn mt-8 rounded-full border-0 px-8 text-primary-content" style="background-color: var(--color-primary, #8a9a7b);" href="/">Back to the shop</a> <a class="btn mt-8 rounded-full border-0 px-8 text-primary-content" style="background-color: var(--color-primary, #8a9a7b);" href={links.booking}>Back to the shop</a>
{/if} {/if}
</section> </section>

View file

@ -7,6 +7,13 @@
right: 'justify-end' right: 'justify-end'
}; };
// Whole class names, not `btn-${variant}`: Tailwind only generates classes
// it finds written out, so a built-up name rendered as a plain grey button.
const variantClasses: Record<string, string> = {
primary: 'btn-primary',
secondary: 'btn-secondary'
};
const sizeClasses: Record<string, string> = { const sizeClasses: Record<string, string> = {
xs: 'btn-xs', xs: 'btn-xs',
sm: 'btn-sm', sm: 'btn-sm',
@ -18,7 +25,7 @@
<div class="flex {alignmentClasses[data.alignment] || 'justify-center'}"> <div class="flex {alignmentClasses[data.alignment] || 'justify-center'}">
<a <a
href={data.href || '#'} href={data.href || '#'}
class="btn btn-{data.variant || 'primary'} {sizeClasses[data.size] || ''}" class="btn {variantClasses[data.variant] || 'btn-primary'} {sizeClasses[data.size] || ''}"
style={data.color ? `background-color: ${data.color}; border-color: ${data.color};` : ''} style={data.color ? `background-color: ${data.color}; border-color: ${data.color};` : ''}
> >
{data.label || 'Button'} {data.label || 'Button'}

View file

@ -3,7 +3,7 @@
import { browser } from '$app/environment'; import { browser } from '$app/environment';
import { goto } from '$app/navigation'; import { goto } from '$app/navigation';
import { page } from '$app/state'; import { page } from '$app/state';
import { DEFAULT_NOTES_HINT, DEFAULT_PRIVACY_NOTICE, type BasketLine, type CheckoutBlockData } from '$shared/types'; import { DEFAULT_NOTES_HINT, DEFAULT_PRIVACY_NOTICE, shopLinks, type BasketLine, type CheckoutBlockData } from '$shared/types';
import { getBasketContext } from '$shared/basket.svelte'; import { getBasketContext } from '$shared/basket.svelte';
import { DEFAULT_CURRENCY, DEFAULT_TIMEZONE, formatInstant, formatPrice } from '$shared/calendar'; import { DEFAULT_CURRENCY, DEFAULT_TIMEZONE, formatInstant, formatPrice } from '$shared/calendar';
import { formatDuration } from '$shared/items'; import { formatDuration } from '$shared/items';
@ -15,6 +15,9 @@
const basket = getBasketContext(); const basket = getBasketContext();
// Not set in the admin preview, which has no footer data. // Not set in the admin preview, which has no footer data.
const privacyPage = $derived(page.data.footer?.privacyPage || ''); const privacyPage = $derived(page.data.footer?.privacyPage || '');
// On its own basket page there is no shop above, so point to the booking page.
const bookingHref = $derived(shopLinks(page.data.header).booking);
const shopAbove = $derived(page.url.pathname === bookingHref);
const customer = $state({ name: '', email: '', phone: '', notes: '' }); const customer = $state({ name: '', email: '', phone: '', notes: '' });
let payState = $state<'idle' | 'creating' | 'ready' | 'confirming' | 'error'>('idle'); let payState = $state<'idle' | 'creating' | 'ready' | 'confirming' | 'error'>('idle');
@ -352,7 +355,11 @@
{#if basket.lines.length === 0} {#if basket.lines.length === 0}
<div class="mt-12 rounded-2xl border border-charcoal/10 bg-white/60 px-6 py-16 text-center"> <div class="mt-12 rounded-2xl border border-charcoal/10 bg-white/60 px-6 py-16 text-center">
<p class="font-serif text-xl">Your basket is empty</p> <p class="font-serif text-xl">Your basket is empty</p>
{#if shopAbove}
<p class="mt-2 text-sm text-fg-body/70">Pick a service or product above.</p> <p class="mt-2 text-sm text-fg-body/70">Pick a service or product above.</p>
{:else}
<a class="mt-6 inline-flex rounded-full bg-sage px-6 py-2.5 text-sm font-medium text-primary-content transition hover:bg-sage-dark" href={bookingHref}>Book a session</a>
{/if}
</div> </div>
{:else} {:else}
{#if holdLeftMs !== null && slotLineCount} {#if holdLeftMs !== null && slotLineCount}

View file

@ -1,4 +1,7 @@
<script lang="ts"> <script lang="ts">
import { page } from '$app/state';
import { shopLinks } from '$shared/types';
let { data } = $props<{ let { data } = $props<{
data: { data: {
heading?: string; heading?: string;
@ -21,7 +24,7 @@
{/if} {/if}
{#if data.buttonLabel} {#if data.buttonLabel}
<div class="animate-fade-in mt-10" style="animation-delay: 0.3s;"> <div class="animate-fade-in mt-10" style="animation-delay: 0.3s;">
<a class="btn rounded-full border-0 bg-sage px-10 py-3 text-lg text-primary-content shadow-lg transition hover:bg-sage-dark hover:shadow-xl" href={data.buttonUrl || '/book'}> <a class="btn rounded-full border-0 bg-sage px-10 py-3 text-lg text-primary-content shadow-lg transition hover:bg-sage-dark hover:shadow-xl" href={data.buttonUrl || shopLinks(page.data.header).booking}>
{data.buttonLabel} {data.buttonLabel}
</a> </a>
</div> </div>

View file

@ -1,6 +1,6 @@
<script lang="ts"> <script lang="ts">
import { page } from '$app/state'; import { page } from '$app/state';
import type { BasketLine, BookableTime, ShopBlockData, ItemRecord } from '$shared/types'; import { shopLinks, type BasketLine, type BookableTime, type ShopBlockData, type ItemRecord } from '$shared/types';
import { getBasketContext } from '$shared/basket.svelte'; import { getBasketContext } from '$shared/basket.svelte';
import { DEFAULT_CURRENCY, DEFAULT_TIMEZONE, addMonths, createCalendarMonth, formatInstant, formatPrice, startOfMonth, zonedDateKey, zonedInputToIso } from '$shared/calendar'; import { DEFAULT_CURRENCY, DEFAULT_TIMEZONE, addMonths, createCalendarMonth, formatInstant, formatPrice, startOfMonth, zonedDateKey, zonedInputToIso } from '$shared/calendar';
import { bundleListPrice, formatDuration, lowestPrice } from '$shared/items'; import { bundleListPrice, formatDuration, lowestPrice } from '$shared/items';
@ -46,6 +46,7 @@
const weekdayLetters = ['M', 'T', 'W', 'T', 'F', 'S', 'S']; const weekdayLetters = ['M', 'T', 'W', 'T', 'F', 'S', 'S'];
const timezone = $derived<string>(page.data.timezone ?? DEFAULT_TIMEZONE); const timezone = $derived<string>(page.data.timezone ?? DEFAULT_TIMEZONE);
const currency = $derived<string>(page.data.currency ?? DEFAULT_CURRENCY); const currency = $derived<string>(page.data.currency ?? DEFAULT_CURRENCY);
const basketHref = $derived(shopLinks(page.data.header).basket);
let visibleItems: ItemRecord[] = $derived.by(() => { let visibleItems: ItemRecord[] = $derived.by(() => {
let result: ItemRecord[] = items; let result: ItemRecord[] = items;
@ -408,7 +409,7 @@
</button> </button>
{#if itemInBasket} {#if itemInBasket}
<a <a
href="/book" href={basketHref}
class="inline-flex items-center gap-1 text-sm font-medium text-sage-dark underline-offset-2 hover:underline" class="inline-flex items-center gap-1 text-sm font-medium text-sage-dark underline-offset-2 hover:underline"
>✓ In basket</a >✓ In basket</a
> >
@ -597,7 +598,7 @@
{#if ui.justAdded} {#if ui.justAdded}
<p class="mt-3 text-sm font-medium text-sage-dark"> <p class="mt-3 text-sm font-medium text-sage-dark">
Added ✓ — <a href="/book" class="underline underline-offset-2 hover:no-underline">view basket</a> Added ✓ — <a href={basketHref} class="underline underline-offset-2 hover:no-underline">view basket</a>
</p> </p>
{/if} {/if}
</div> </div>

View file

@ -61,8 +61,11 @@ export type UpcomingCalendarBlockData = {
export type HeaderGlobal = { export type HeaderGlobal = {
logo: { url: string; alt: string }; logo: { url: string; alt: string };
navLinks: { label: string; href: string }[]; navLinks: { label: string; href: string }[];
/** The header button. Its address is also where hero buttons without one and "Book another" lead. */
ctaButton: { label: string; href: string }; ctaButton: { label: string; href: string };
homePage: string; homePage: string;
/** Slug of the page with the Checkout block, typed in Site design: the basket in the header and "view basket" lead here ('' = the CTA button's address). */
basketPage?: string;
}; };
export type FooterGlobal = { export type FooterGlobal = {
@ -85,9 +88,18 @@ export const defaultHeader: HeaderGlobal = {
{ label: 'Services', href: '/services' } { label: 'Services', href: '/services' }
], ],
ctaButton: { label: 'Book Now', href: '/book' }, ctaButton: { label: 'Book Now', href: '/book' },
homePage: 'home' homePage: 'home',
basketPage: ''
}; };
/** Where booking (the CTA button's address) and the basket (the basket page, else the same address) are. */
export function shopLinks(header?: Partial<HeaderGlobal> | null) {
const booking = header?.ctaButton?.href || '/book';
// Typed by hand, so tolerate "/basket", "basket/" and spaces.
const basketSlug = header?.basketPage?.trim().replace(/^\/+|\/+$/g, '');
return { booking, basket: basketSlug ? `/${basketSlug}` : booking };
}
export const defaultFooter: FooterGlobal = { export const defaultFooter: FooterGlobal = {
businessName: 'Eva Shafik Massage', businessName: 'Eva Shafik Massage',
tagline: 'Warm, restorative massage therapy for everyday wellbeing.', tagline: 'Warm, restorative massage therapy for everyday wellbeing.',