diff --git a/AGENTS.md b/AGENTS.md index 674d9eb..f952d17 100644 --- a/AGENTS.md +++ b/AGENTS.md @@ -157,9 +157,7 @@ DOMAIN=localhost docker compose up --build # Public app: http://www.localhost:8080 # PocketBase: http://db.localhost:8080/_/ -# 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 +# Type checking (can run on the host with node_modules present) cd app-admin && npm run check cd app-public && npm run check @@ -178,4 +176,3 @@ 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`). diff --git a/app-admin/src/routes/preview/+page.server.ts b/app-admin/src/routes/preview/+page.server.ts deleted file mode 100644 index f219859..0000000 --- a/app-admin/src/routes/preview/+page.server.ts +++ /dev/null @@ -1,22 +0,0 @@ -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 }; -}; diff --git a/app-admin/src/routes/preview/+page.svelte b/app-admin/src/routes/preview/+page.svelte index 7627ae1..4b1211d 100644 --- a/app-admin/src/routes/preview/+page.svelte +++ b/app-admin/src/routes/preview/+page.svelte @@ -27,7 +27,7 @@ {#if blocks.length} - + {:else}

No preview content

diff --git a/app-public/src/lib/components/Header.svelte b/app-public/src/lib/components/Header.svelte index 69caf2d..2ff12ed 100644 --- a/app-public/src/lib/components/Header.svelte +++ b/app-public/src/lib/components/Header.svelte @@ -46,7 +46,7 @@ {#if header.logo?.url} {header.logo.alt {:else} - ES + ES {/if} Eva Shafik diff --git a/app-public/src/routes/+layout.server.ts b/app-public/src/routes/+layout.server.ts index 315bc59..f4a9947 100644 --- a/app-public/src/routes/+layout.server.ts +++ b/app-public/src/routes/+layout.server.ts @@ -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(pb.filter('key = {:key}', { key })); + const record = await pb.collection('globals').getFirstListItem(`key = "${key}"`); return record.data || fallback; } catch { return fallback; @@ -35,11 +35,44 @@ export const load: LayoutServerLoad = async ({ locals, cookies }) => { const basketId = cookies.get(BASKET_COOKIE); if (basketId) basket = await loadBasket(pb, basketId); - ({ items, slots } = await loadShopData(pb)); + 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 || '' + })); } catch (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); + // Admin PB not configured (e.g. fresh dev env) — commerce features off. + console.warn('Commerce data unavailable:', e instanceof Error ? e.message : e); } return { header, footer, colors, user: locals.user, basket, items, slots }; diff --git a/app-public/src/routes/+page.server.ts b/app-public/src/routes/+page.server.ts index eb226c7..6153b9d 100644 --- a/app-public/src/routes/+page.server.ts +++ b/app-public/src/routes/+page.server.ts @@ -16,7 +16,7 @@ export const load: PageServerLoad = async ({ locals }) => { try { const page = await locals.pb .collection('pages') - .getFirstListItem(locals.pb.filter('slug = {:slug} && published = true', { slug: homeSlug })); + .getFirstListItem(`slug = "${homeSlug}" && published = true`); let calendarEvents: CalendarEventRecord[] = []; if (hasUpcomingCalendarBlock(page.blocks || [])) { const range = getUpcomingCalendarRange(); diff --git a/app-public/src/routes/[slug]/+page.server.ts b/app-public/src/routes/[slug]/+page.server.ts index 4d6c301..5e88b53 100644 --- a/app-public/src/routes/[slug]/+page.server.ts +++ b/app-public/src/routes/[slug]/+page.server.ts @@ -7,7 +7,7 @@ export const load: PageServerLoad = async ({ params, locals }) => { try { const page = await locals.pb .collection('pages') - .getFirstListItem(locals.pb.filter('slug = {:slug} && published = true', { slug: params.slug })); + .getFirstListItem(`slug = "${params.slug}" && published = true`); let calendarEvents: CalendarEventRecord[] = []; if (hasUpcomingCalendarBlock(page.blocks || [])) { const range = getUpcomingCalendarRange(); diff --git a/app-public/src/routes/checkout/return/+page.svelte b/app-public/src/routes/checkout/return/+page.svelte index 15f9406..b09b23d 100644 --- a/app-public/src/routes/checkout/return/+page.svelte +++ b/app-public/src/routes/checkout/return/+page.svelte @@ -25,7 +25,7 @@
{#if data.state === 'paid' && data.order} -
✓
+
✓

Thank you, {data.order.customerDetails?.name || 'friend'}!

Your booking is confirmed. A receipt was sent to {data.order.email}. @@ -51,7 +51,7 @@ - Book another + Book another {:else if data.state === 'processing'}

Processing your payment…

@@ -63,10 +63,10 @@ {:else if data.state === 'canceled' || data.state === 'failed'}

Payment not completed

Your payment didn't go through — no money was captured. Please try again.

- Back to the shop + Back to the shop {:else}

Nothing to see here

This link is missing a payment reference.

- Back to the shop + Back to the shop {/if}
diff --git a/packages/shared/src/blocks/CheckoutBlock.svelte b/packages/shared/src/blocks/CheckoutBlock.svelte index bd12b04..5a9b4cb 100644 --- a/packages/shared/src/blocks/CheckoutBlock.svelte +++ b/packages/shared/src/blocks/CheckoutBlock.svelte @@ -347,7 +347,7 @@ {#if payState === 'idle' || payState === 'creating'}