Compare commits
4 commits
fb2157bbe0
...
bcb6cf80c7
| Author | SHA1 | Date | |
|---|---|---|---|
| bcb6cf80c7 | |||
| 3308f2f85f | |||
| cd66d61f6f | |||
| 91e3e916d8 |
12 changed files with 106 additions and 54 deletions
|
|
@ -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`).
|
||||
|
|
|
|||
22
app-admin/src/routes/preview/+page.server.ts
Normal file
22
app-admin/src/routes/preview/+page.server.ts
Normal 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 };
|
||||
};
|
||||
|
|
@ -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>
|
||||
|
|
|
|||
|
|
@ -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>
|
||||
|
|
|
|||
|
|
@ -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 };
|
||||
|
|
|
|||
|
|
@ -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();
|
||||
|
|
|
|||
|
|
@ -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();
|
||||
|
|
|
|||
|
|
@ -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>
|
||||
|
|
|
|||
|
|
@ -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}
|
||||
|
|
|
|||
|
|
@ -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>
|
||||
|
|
|
|||
|
|
@ -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 &&
|
||||
|
|
|
|||
52
packages/shared/src/server/shop.ts
Normal file
52
packages/shared/src/server/shop.ts
Normal 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 };
|
||||
}
|
||||
Loading…
Add table
Add a link
Reference in a new issue