Compare commits

..

4 commits

Author SHA1 Message Date
bcb6cf80c7 Docs: commerce credentials are required for shop data; type-check setup
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01KgF3Kf47LjPGHKQHszpUAv
2026-10-06 12:06:06 +00:00
3308f2f85f Public site: readable text on brand-coloured buttons
Hero, Shop, Checkout, checkout-return and the header logo fallback used
white text on the site Primary; on a light Primary that was unreadable.
They now use primary-content (auto-contrast, see $shared/theme).

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01KgF3Kf47LjPGHKQHszpUAv
2026-10-06 12:06:05 +00:00
cd66d61f6f Public pages: build slug filters with pb.filter
The URL slug was interpolated into the filter string, so a crafted URL
could rewrite the query (e.g. make any path serve a page). API rules
still limited it to published pages, so no drafts leaked.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01KgF3Kf47LjPGHKQHszpUAv
2026-10-06 12:06:05 +00:00
91e3e916d8 Shop block: share item loading with the admin preview, never render blank
The admin preview never received items/slots/events, so Shop and Upcoming
calendar blocks were empty there. loadShopData() (shared) now feeds both
the public layout and a new /preview loader.

A Shop block with nothing to show (no active items, a filter matching
none, or commerce data unavailable because POCKETBASE_ADMIN_* is unset)
now says so instead of rendering an empty section.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01KgF3Kf47LjPGHKQHszpUAv
2026-10-06 12:06:05 +00:00
12 changed files with 106 additions and 54 deletions

View file

@ -157,7 +157,9 @@ DOMAIN=localhost docker compose up --build
# Public app: http://www.localhost:8080
# PocketBase: http://db.localhost:8080/_/
# Type checking (can run on the host with node_modules present)
# Type checking (needs node_modules in packages/shared too, or every shared
# file that imports a package fails with "Cannot find module")
cd packages/shared && npm ci
cd app-admin && npm run check
cd app-public && npm run check
@ -176,3 +178,4 @@ cd app-public && npm run build
- `SMTP_HOST`, `SMTP_PORT`, `SMTP_USER`, `SMTP_PASS`, `EMAIL_FROM`, `EMAIL_FROM_NAME` — Brevo SMTP relay for booking emails (both apps). Empty `SMTP_HOST` = log emails instead of sending.
- `SITE_TIMEZONE` — IANA timezone for booking times in emails (default `Europe/Oslo`).
- Stripe + PocketBase admin secrets are read from a root-level `.env` next to `docker-compose.yml`; see `.env.example`.
- `POCKETBASE_ADMIN_EMAIL` / `POCKETBASE_ADMIN_PASSWORD` are required for **any** commerce data: without them the public app logs `Commerce data unavailable` and Shop blocks show "Nothing is available". Shop data is loaded by `loadShopData()` in `packages/shared/src/server/shop.ts` (public layout and admin `/preview`).

View file

@ -0,0 +1,22 @@
import { eventOverlapsRange, getUpcomingCalendarRange, normalizeEvent } from '$lib/calendar';
import { loadShopData } from '$shared/server/shop';
import type { PageServerLoad } from './$types';
// The draft blocks come from sessionStorage (client-side), so load the data
// any block might need: shop items/slots and upcoming events. Failures leave
// the blocks empty rather than breaking the preview.
export const load: PageServerLoad = async ({ locals }) => {
const range = getUpcomingCalendarRange();
const [shop, events] = await Promise.all([
loadShopData(locals.pb).catch((e) => {
console.warn('Preview: shop data unavailable:', e instanceof Error ? e.message : e);
return { items: [], slots: [] };
}),
locals.pb
.collection('events')
.getFullList({ filter: locals.pb.filter('published = true && start <= {:end}', { end: range.end }), sort: 'start' })
.catch(() => [])
]);
const calendarEvents = events.map((event) => normalizeEvent(event)).filter((event) => eventOverlapsRange(event, range.start, range.end));
return { ...shop, calendarEvents };
};

View file

@ -27,7 +27,7 @@
</svelte:head>
{#if blocks.length}
<BlockRenderer {blocks} />
<BlockRenderer {blocks} items={data.items} slots={data.slots} calendarEvents={data.calendarEvents} />
{:else}
<section class="mx-auto max-w-3xl px-6 py-20 text-center">
<h1 class="text-4xl">No preview content</h1>

View file

@ -46,7 +46,7 @@
{#if header.logo?.url}
<img class="h-10 w-10 shrink-0 rounded-full object-cover md:h-12 md:w-12" src={header.logo.url} alt={header.logo.alt || ''} />
{:else}
<span class="grid h-10 w-10 shrink-0 place-items-center rounded-full bg-sage text-lg font-bold text-white md:h-12 md:w-12">ES</span>
<span class="grid h-10 w-10 shrink-0 place-items-center rounded-full bg-sage text-lg font-bold text-primary-content md:h-12 md:w-12">ES</span>
{/if}
<span class="truncate font-serif text-lg font-bold md:text-xl">Eva Shafik</span>
</a>

View file

@ -1,13 +1,13 @@
import { defaultColors, defaultFooter, defaultHeader } from '$lib/types';
import type { ItemRecord, SlotRecord } from '$lib/types';
import { getFileUrl } from '$lib/pb';
import { getAdminPb } from '$lib/server/pb-admin';
import { BASKET_COOKIE, loadBasket, sweepExpiredHolds } from '$lib/server/basket';
import { loadShopData } from '$shared/server/shop';
import type { LayoutServerLoad } from './$types';
async function getGlobal(pb: App.Locals['pb'], key: string, fallback: unknown) {
try {
const record = await pb.collection('globals').getFirstListItem(`key = "${key}"`);
const record = await pb.collection('globals').getFirstListItem(pb.filter('key = {:key}', { key }));
return record.data || fallback;
} catch {
return fallback;
@ -35,44 +35,11 @@ export const load: LayoutServerLoad = async ({ locals, cookies }) => {
const basketId = cookies.get(BASKET_COOKIE);
if (basketId) basket = await loadBasket(pb, basketId);
const itemRecords = await pb
.collection('items')
.getFullList({ filter: 'active = true', sort: 'name', expand: 'image' })
.catch(() => []);
items = itemRecords.map((record) => {
const media = record.expand?.image;
return {
id: record.id,
name: record.name,
description: record.description || '',
price: record.price,
image: record.image || '',
imageUrl: media ? getFileUrl('media', media.id, media.file) : '',
type: record.type,
stock: record.stock ?? null,
duration: record.duration ?? null,
active: record.active
};
});
const nowIso = new Date().toISOString();
const slotRecords = await pb
.collection('slots')
.getFullList({ filter: `status = 'available' && start >= "${nowIso}"`, sort: 'start' })
.catch(() => []);
slots = slotRecords.map((record) => ({
id: record.id,
item: record.item,
start: record.start,
end: record.end || '',
status: record.status,
heldUntil: record.heldUntil || null,
order: record.order || null,
notes: record.notes || ''
}));
({ items, slots } = await loadShopData(pb));
} catch (e) {
// Admin PB not configured (e.g. fresh dev env) — commerce features off.
console.warn('Commerce data unavailable:', e instanceof Error ? e.message : e);
// Admin PB not configured (e.g. fresh dev env) — commerce features off;
// Shop blocks then show their "nothing available" message.
console.warn('Commerce data unavailable (shop blocks will be empty):', e instanceof Error ? e.message : e);
}
return { header, footer, colors, user: locals.user, basket, items, slots };

View file

@ -16,7 +16,7 @@ export const load: PageServerLoad = async ({ locals }) => {
try {
const page = await locals.pb
.collection('pages')
.getFirstListItem(`slug = "${homeSlug}" && published = true`);
.getFirstListItem(locals.pb.filter('slug = {:slug} && published = true', { slug: homeSlug }));
let calendarEvents: CalendarEventRecord[] = [];
if (hasUpcomingCalendarBlock(page.blocks || [])) {
const range = getUpcomingCalendarRange();

View file

@ -7,7 +7,7 @@ export const load: PageServerLoad = async ({ params, locals }) => {
try {
const page = await locals.pb
.collection('pages')
.getFirstListItem(`slug = "${params.slug}" && published = true`);
.getFirstListItem(locals.pb.filter('slug = {:slug} && published = true', { slug: params.slug }));
let calendarEvents: CalendarEventRecord[] = [];
if (hasUpcomingCalendarBlock(page.blocks || [])) {
const range = getUpcomingCalendarRange();

View file

@ -25,7 +25,7 @@
<section class="mx-auto max-w-2xl px-6 py-16 text-center">
{#if data.state === 'paid' && data.order}
<div class="mb-6 inline-grid h-16 w-16 place-items-center rounded-full bg-sage text-3xl text-white">✓</div>
<div class="mb-6 inline-grid h-16 w-16 place-items-center rounded-full bg-sage text-3xl text-primary-content">✓</div>
<h1 class="font-serif text-4xl">Thank you, {data.order.customerDetails?.name || 'friend'}!</h1>
<p class="mt-3 text-charcoal/70">
Your booking is confirmed. A receipt was sent to <strong>{data.order.email}</strong>.
@ -51,7 +51,7 @@
</div>
</div>
<a class="btn mt-8 rounded-full border-0 px-8 text-white" 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="/">Book another</a>
{:else if data.state === 'processing'}
<h1 class="font-serif text-4xl">Processing your payment…</h1>
<p class="mt-3 text-charcoal/70">
@ -63,10 +63,10 @@
{:else if data.state === 'canceled' || data.state === 'failed'}
<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>
<a class="btn mt-8 rounded-full border-0 px-8 text-white" 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="/">Back to the shop</a>
{:else}
<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>
<a class="btn mt-8 rounded-full border-0 px-8 text-white" 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="/">Back to the shop</a>
{/if}
</section>

View file

@ -347,7 +347,7 @@
{#if payState === 'idle' || payState === 'creating'}
<button
type="submit"
class="btn w-full rounded-full border-0 text-white"
class="btn w-full rounded-full border-0 text-primary-content"
style="background-color: var(--color-primary, #8a9a7b);"
disabled={payState === 'creating'}
>
@ -382,7 +382,7 @@
{#if payState === 'ready' || payState === 'confirming'}
<button
type="button"
class="btn mt-4 w-full rounded-full border-0 text-white"
class="btn mt-4 w-full rounded-full border-0 text-primary-content"
style="background-color: var(--color-primary, #8a9a7b);"
disabled={payState === 'confirming'}
onclick={confirmPayment}

View file

@ -21,7 +21,7 @@
{/if}
{#if data.buttonLabel}
<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-white 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 || '/book'}>
{data.buttonLabel}
</a>
</div>

View file

@ -130,6 +130,14 @@
<h2 class="mb-12 text-center font-serif text-3xl text-charcoal md:text-4xl">{data.title}</h2>
{/if}
{#if !visibleItems.length}
<!-- Never an empty section: no active items, a filter that matches none,
or commerce data unavailable (see the public layout's server log). -->
<p class="rounded-2xl border border-dashed border-charcoal/15 px-6 py-10 text-center text-charcoal/60">
Nothing is available to book right now — please check back soon.
</p>
{/if}
<div class={isList ? 'flex flex-col gap-8' : 'grid gap-8 sm:grid-cols-2 lg:grid-cols-3'}>
{#each visibleItems as item (item.id)}
{@const ui = cardStates[item.id]}
@ -204,7 +212,7 @@
class="inline-flex items-center justify-center gap-2 rounded-full px-6 py-2.5 text-sm font-medium transition {ui?.pickerOpen
? 'border border-charcoal/15 text-charcoal hover:bg-charcoal/5'
: itemSlotsByDay?.size
? 'bg-sage text-white hover:bg-sage-dark'
? 'bg-sage text-primary-content hover:bg-sage-dark'
: 'cursor-not-allowed bg-charcoal/10 text-charcoal/50'}"
disabled={!itemSlotsByDay?.size && !ui?.pickerOpen}
onclick={() => togglePicker(item.id)}
@ -214,7 +222,7 @@
{:else}
<button
type="button"
class="inline-flex items-center justify-center gap-2 rounded-full bg-sage px-6 py-2.5 text-sm font-medium text-white transition hover:bg-sage-dark disabled:cursor-not-allowed disabled:bg-charcoal/10 disabled:text-charcoal/50"
class="inline-flex items-center justify-center gap-2 rounded-full bg-sage px-6 py-2.5 text-sm font-medium text-primary-content transition hover:bg-sage-dark disabled:cursor-not-allowed disabled:bg-charcoal/10 disabled:text-charcoal/50"
disabled={soldOut || ui?.adding}
onclick={() => addItem(item.id)}
>
@ -252,7 +260,7 @@
aria-pressed={selected}
onclick={() => (ui.selectedDayKey = day.dateKey)}
class="aspect-square rounded-full text-sm transition {selected
? 'bg-sage font-semibold text-white'
? 'bg-sage font-semibold text-primary-content'
: selectable
? 'cursor-pointer bg-sage/15 font-medium text-charcoal hover:bg-sage/35'
: 'cursor-default text-charcoal/25'} {!day.inMonth ? 'opacity-40' : ''} {day.isToday &&

View file

@ -0,0 +1,52 @@
import type PocketBase from 'pocketbase';
import { getFileUrl } from '../pb';
import type { ItemRecord, SlotRecord } from '../types';
/**
* Active items and future available slots, shaped for the Shop/Checkout
* blocks. Used by the public layout and the admin draft preview so both
* render the same shop.
*
* `pb` must be able to read items, slots and media (admin client on the
* public site, the logged-in superuser in the admin). Errors propagate.
*/
export async function loadShopData(pb: PocketBase): Promise<{ items: ItemRecord[]; slots: SlotRecord[] }> {
const [itemRecords, slotRecords] = await Promise.all([
pb.collection('items').getFullList({ filter: 'active = true', sort: 'name', expand: 'image' }),
pb.collection('slots').getFullList({
filter: pb.filter("status = 'available' && start >= {:now}", { now: new Date() }),
sort: 'start'
})
]);
const items = itemRecords.map((record): ItemRecord => {
const media = record.expand?.image;
return {
id: record.id,
name: record.name,
description: record.description || '',
price: record.price,
image: record.image || '',
imageUrl: media ? getFileUrl('media', media.id, media.file) : '',
type: record.type,
stock: record.stock ?? null,
duration: record.duration ?? null,
active: record.active
};
});
const slots = slotRecords.map(
(record): SlotRecord => ({
id: record.id,
item: record.item,
start: record.start,
end: record.end || '',
status: record.status,
heldUntil: record.heldUntil || null,
order: record.order || null,
notes: record.notes || ''
})
);
return { items, slots };
}