Optional basket page; Button blocks follow the site colour; Site design tidy-up #9

Merged
reudy merged 5 commits from booking-basket-pages into main 2026-10-26 13:09:24 +01:00
4 changed files with 12 additions and 13 deletions
Showing only changes of commit 68c67d7e96 - Show all commits

View file

@ -154,7 +154,7 @@ 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 (`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`. - **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. - **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 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 picked 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. 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

@ -40,8 +40,10 @@
// The page the basket links lead to: the basket page, else the CTA's address when that is a page here. // The page the basket links lead to: the basket page, else the CTA's address when that is a page here.
function basketProblem() { function basketProblem() {
const page = pageBySlug(shopLinks(header).basket.replace(/^\/|\/$/g, '')); const slug = shopLinks(header).basket.replace(/^\/|\/$/g, '');
if (!page) return ''; 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.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.`; if (!page.hasCheckout) return `“${page.title}” has no Checkout block, so people can’t pay from it.`;
return ''; return '';
@ -105,13 +107,8 @@
</div> </div>
<p class="mt-1 text-sm text-base-content/60">Hero buttons without an address and “Book another” after paying lead here too.</p> <p class="mt-1 text-sm text-base-content/60">Hero buttons without an address and “Book another” after paying lead here too.</p>
<h3 class="mt-6 mb-2 font-bold">Basket page <span class="font-normal text-base-content/50">(optional)</span></h3> <h3 class="mt-6 mb-2 font-bold">Basket page <span class="font-normal text-base-content/50">(optional)</span></h3>
<select class="select w-full" aria-label="Basket page" bind:value={header.basketPage}> <input class="input w-full" aria-label="Basket page" bind:value={header.basketPage} placeholder="Same as the CTA button" />
<option value="">— Same as the CTA button —</option> <p class="mt-1 text-sm text-base-content/60">The slug of the page where people pay, e.g. <code>basket</code>: the basket in the header and “view basket” in the shop lead there. Leave it empty if the CTA button’s page has the Checkout block.</p>
{#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">Where people pay: the basket in the header and “view basket” in the shop lead here. Leave it empty if the CTA button’s page has the Checkout block.</p>
{#if basketProblem()}<p class="mt-1 text-sm font-semibold">⚠ {basketProblem()}</p>{/if} {#if basketProblem()}<p class="mt-1 text-sm font-semibold">⚠ {basketProblem()}</p>{/if}
<h3 class="mt-6 mb-2 font-bold">Home page</h3> <h3 class="mt-6 mb-2 font-bold">Home page</h3>
<select class="select w-full" aria-label="Home page" bind:value={header.homePage}> <select class="select w-full" aria-label="Home page" bind:value={header.homePage}>

View file

@ -64,7 +64,7 @@ export type HeaderGlobal = {
/** The header button. Its address is also where hero buttons without one and "Book another" lead. */ /** 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: the basket in the header and "view basket" lead here ('' = the CTA button's address). */ /** 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; basketPage?: string;
}; };
@ -95,7 +95,9 @@ export const defaultHeader: HeaderGlobal = {
/** Where booking (the CTA button's address) and the basket (the basket page, else the same address) are. */ /** 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) { export function shopLinks(header?: Partial<HeaderGlobal> | null) {
const booking = header?.ctaButton?.href || '/book'; const booking = header?.ctaButton?.href || '/book';
return { booking, basket: header?.basketPage ? `/${header.basketPage}` : booking }; // 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 = {