Compare commits
2 commits
c3c10229b0
...
f20d6777ab
| Author | SHA1 | Date | |
|---|---|---|---|
| f20d6777ab | |||
| ec1156b1fa |
7 changed files with 38 additions and 54 deletions
|
|
@ -154,7 +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 pages** are picked in Site design (`header.bookingPage`, `header.basketPage`; '' = the booking page). Links to them come 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 (`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
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -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 pick it as *Site design → Header → Booking page*: the header button, hero buttons without an address and *Book another* after paying lead there. Add a `checkout` block either to the same page, or to a page of its own picked as *Basket page*: the basket in the header and *view basket* in the shop lead there. Site design warns when the page picked lacks the block it needs or isn't published. (Sites set up before these settings keep using the header button's old address, or `/book`, until a page is picked.)
|
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.
|
||||||
|
|
||||||
## Bundles and codes
|
## Bundles and codes
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -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 }), 'Empty = the booking page')}
|
{@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">
|
||||||
|
|
|
||||||
|
|
@ -27,12 +27,12 @@ export const load: PageServerLoad = async ({ locals }) => {
|
||||||
getGlobal(locals.pb, 'colors', defaultColors)
|
getGlobal(locals.pb, 'colors', defaultColors)
|
||||||
]);
|
]);
|
||||||
|
|
||||||
// All pages for the page selectors, with what the booking and basket
|
// All pages for the page selectors, with what the basket setting warns
|
||||||
// settings need to warn about (unpublished, no Shop / Checkout block).
|
// about (unpublished, no Checkout block).
|
||||||
const records = await locals.pb.collection('pages').getFullList({ sort: 'slug', fields: 'id,slug,title,published,blocks' });
|
const records = await locals.pb.collection('pages').getFullList({ sort: 'slug', fields: 'id,slug,title,published,blocks' });
|
||||||
const pages = records.map((page) => {
|
const pages = records.map((page) => {
|
||||||
const types = new Set(((page.blocks as { type?: string }[]) || []).map((block) => block.type));
|
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, hasShop: types.has('shop'), hasCheckout: types.has('checkout') };
|
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 };
|
||||||
|
|
|
||||||
|
|
@ -10,10 +10,8 @@
|
||||||
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 and the booking/basket pages;
|
// Older records may predate the CTA button and the basket page; the inputs below need values.
|
||||||
// they start from wherever the site's links led until now.
|
header.ctaButton ??= { label: '', href: '' };
|
||||||
header.ctaButton ??= { label: '' };
|
|
||||||
header.bookingPage ||= shopLinks(header).booking.slice(1);
|
|
||||||
header.basketPage ??= '';
|
header.basketPage ??= '';
|
||||||
footer.privacyPage ??= '';
|
footer.privacyPage ??= '';
|
||||||
|
|
||||||
|
|
@ -40,19 +38,12 @@
|
||||||
|
|
||||||
const pageBySlug = (slug: string) => data.pages.find((page) => page.slug === slug);
|
const pageBySlug = (slug: string) => data.pages.find((page) => page.slug === slug);
|
||||||
|
|
||||||
function bookingProblem(slug: string) {
|
// The page the basket links lead to: the basket page, else the CTA's address when that is a page here.
|
||||||
const page = pageBySlug(slug);
|
function basketProblem() {
|
||||||
if (!page) return `There is no page “${slug}” — pick one.`;
|
const page = pageBySlug(shopLinks(header).basket.replace(/^\/|\/$/g, ''));
|
||||||
if (!page.published) return 'This page isn’t published yet.';
|
|
||||||
if (!page.hasShop) return 'This page has no Shop block.';
|
|
||||||
return '';
|
|
||||||
}
|
|
||||||
|
|
||||||
function basketProblem(slug: string) {
|
|
||||||
const page = pageBySlug(slug || header.bookingPage);
|
|
||||||
if (!page) return '';
|
if (!page) return '';
|
||||||
if (!page.published) return 'This page isn’t published yet.';
|
if (!page.published) return `“${page.title}” isn’t published yet.`;
|
||||||
if (!page.hasCheckout) return 'This page 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 '';
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
@ -108,26 +99,20 @@
|
||||||
{/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 font-bold">CTA button</h3>
|
||||||
<input class="input w-full" aria-label="Button label" bind:value={header.ctaButton.label} placeholder="Book Now" />
|
<div class="grid grid-cols-2 gap-2">
|
||||||
<p class="mt-1 text-sm text-base-content/60">Leads to the booking page. Empty = no button.</p>
|
<input class="input w-full" aria-label="Button label" bind:value={header.ctaButton.label} placeholder="Label" />
|
||||||
<h3 class="mt-6 mb-2 font-bold">Booking page</h3>
|
<input class="input w-full" aria-label="Button address" bind:value={header.ctaButton.href} placeholder="/book" />
|
||||||
<select class="select w-full" aria-label="Booking page" bind:value={header.bookingPage}>
|
</div>
|
||||||
{#if !pageBySlug(header.bookingPage)}<option value={header.bookingPage}>— Select a page —</option>{/if}
|
<p class="mt-1 text-sm text-base-content/60">Hero buttons without an address and “Book another” after paying lead here too.</p>
|
||||||
{#each data.pages as page (page.id)}
|
<h3 class="mt-6 mb-2 font-bold">Basket page <span class="font-normal text-base-content/50">(optional)</span></h3>
|
||||||
<option value={page.slug}>{page.title} [{page.slug}]</option>
|
|
||||||
{/each}
|
|
||||||
</select>
|
|
||||||
<p class="mt-1 text-sm text-base-content/60">Where people choose what to book: the header button, hero buttons without an address and “Book another” after paying lead here.</p>
|
|
||||||
{#if bookingProblem(header.bookingPage)}<p class="mt-1 text-sm font-semibold">⚠ {bookingProblem(header.bookingPage)}</p>{/if}
|
|
||||||
<h3 class="mt-6 mb-2 font-bold">Basket page</h3>
|
|
||||||
<select class="select w-full" aria-label="Basket page" bind:value={header.basketPage}>
|
<select class="select w-full" aria-label="Basket page" bind:value={header.basketPage}>
|
||||||
<option value="">— Same as the booking page —</option>
|
<option value="">— Same as the CTA button —</option>
|
||||||
{#each data.pages as page (page.id)}
|
{#each data.pages as page (page.id)}
|
||||||
<option value={page.slug}>{page.title} [{page.slug}]</option>
|
<option value={page.slug}>{page.title} [{page.slug}]</option>
|
||||||
{/each}
|
{/each}
|
||||||
</select>
|
</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.</p>
|
<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(header.basketPage)}<p class="mt-1 text-sm font-semibold">⚠ {basketProblem(header.basketPage)}</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}>
|
||||||
<option value="">— Select a page —</option>
|
<option value="">— Select a page —</option>
|
||||||
|
|
|
||||||
|
|
@ -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'}
|
||||||
|
|
|
||||||
|
|
@ -61,12 +61,10 @@ 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. It leads to the booking page; `href` is only read on sites set up before there was one. */
|
/** 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 Shop block: the header button, hero buttons without an address and "Book another" lead here. */
|
/** Slug of the page with the Checkout block: the basket in the header and "view basket" lead here ('' = the CTA button's address). */
|
||||||
bookingPage?: string;
|
|
||||||
/** Slug of the page with the Checkout block: the basket in the header and "view basket" lead here ('' = the booking page). */
|
|
||||||
basketPage?: string;
|
basketPage?: string;
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|
@ -89,22 +87,15 @@ export const defaultHeader: HeaderGlobal = {
|
||||||
{ label: 'About', href: '/about' },
|
{ label: 'About', href: '/about' },
|
||||||
{ label: 'Services', href: '/services' }
|
{ label: 'Services', href: '/services' }
|
||||||
],
|
],
|
||||||
ctaButton: { label: 'Book Now' },
|
ctaButton: { label: 'Book Now', href: '/book' },
|
||||||
homePage: 'home',
|
homePage: 'home',
|
||||||
bookingPage: 'book',
|
|
||||||
basketPage: ''
|
basketPage: ''
|
||||||
};
|
};
|
||||||
|
|
||||||
/**
|
/** Where booking (the CTA button's address) and the basket (the basket page, else the same address) are. */
|
||||||
* Addresses of the booking and basket pages. Sites set up before these
|
|
||||||
* settings existed sent everything to `/book` or the button's own address,
|
|
||||||
* so that is still where they lead until a page is picked in Site design.
|
|
||||||
*/
|
|
||||||
export function shopLinks(header?: Partial<HeaderGlobal> | null) {
|
export function shopLinks(header?: Partial<HeaderGlobal> | null) {
|
||||||
const legacy = header?.ctaButton?.href?.match(/^\/([a-z0-9-]+)\/?$/)?.[1];
|
const booking = header?.ctaButton?.href || '/book';
|
||||||
const booking = header?.bookingPage || legacy || 'book';
|
return { booking, basket: header?.basketPage ? `/${header.basketPage}` : booking };
|
||||||
const basket = header?.basketPage || booking;
|
|
||||||
return { booking: `/${booking}`, basket: `/${basket}` };
|
|
||||||
}
|
}
|
||||||
|
|
||||||
export const defaultFooter: FooterGlobal = {
|
export const defaultFooter: FooterGlobal = {
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue