Packages and banners from the CMS, host injection, translation files and the contact form #19

Merged
Sluijsens merged 44 commits from feature/asf-packages-cms into master 2026-11-16 14:17:14 +01:00
14 changed files with 474 additions and 20 deletions
Showing only changes of commit 6f1be2f7f5 - Show all commits
@@ -8,6 +8,8 @@ Decided by Bryan via SLP Software - SLS - Main, 2026-11-12. Source of truth: the
- FR-PK-03 One source: the price cards, the "welke shoot" choices of the contact form and the `?pakket=` check use the same list (`content/packages.ts`).
- FR-PK-04 Mapping: `slug` is the package id (kept `zwangerschap`, `newborn`, `gezin`: they appear in `?pakket=` and the form), `title` the name, the price text is read as whole euros ("€ 175", "€ 1.250", "175,-"); a card with an unreadable price, no features or a bad slug is skipped; order by `displayOrder`.
- FR-PK-05 Banner: the first usable offering with `layout=banner` becomes an optional dark band under the cards (own block, price as free text). It is not a package: not in the form choices, not in the package count, no booking link with a package.
- FR-PK-07 Last row of cards (desktop): rows of three, an incomplete last row is centred, for any number of cards, with no styling per number. Phone and tablet stay one column. Done with a wrapping flex and card width `calc((100% - 2 * gap) / 3)`.
- FR-PK-08 Slim top bar (2026-11-14, Bryan via SLS-Main): a second banner ABOVE the cards, next to the one under them; both may show at once. One line (title and text on one line, optional small text link), a slim bar in the ASF style that matches the white bottom banner. Contract: `GET /api/v1/offerings/banner?position=top|bottom` (no parameter is bottom), 204 is none, fields title/text/linkLabel/linkUrl, the title may be empty for top (title or text required). Built in like the bottom banner: baked in the HTML, replaced live after hydration, 204 hides it, errors keep what was baked, empty fields hidden.
- FR-PK-06 The rebuild trigger (CMS change leads to a new build) is separate from the build; decision for Bryan (webhook to workflow_dispatch or a nightly build). Until then a change shows after the next build.
- NFR-PK-01 Tests use the snapshot only (no dependence on a build or network).
+20
View File
@@ -11,6 +11,7 @@ import { fileURLToPath } from 'node:url';
import {
mapBanner,
mapOfferings,
mapTopBanner,
type SiteOfferings,
} from '../src/lib/offerings.ts';
@@ -81,6 +82,25 @@ async function main() {
`[offerings] banner not available (${String(error)}): none`,
);
}
// The slim top bar, same rules
try {
const top = mapTopBanner(
await fetchAnswer(
base,
'/api/v1/offerings/banner?position=top',
),
);
result.topBanner = top;
console.log(
top
? `[offerings] top bar "${top.title ?? top.text}"`
: '[offerings] no active top bar',
);
} catch (error) {
console.warn(
`[offerings] top bar not available (${String(error)}): none`,
);
}
} else {
console.warn(
`[offerings] answer of ${base} has no valid package: using the snapshot`,
+97
View File
@@ -76,4 +76,101 @@ describe('pakketten live uit het CMS', () => {
expect(await cards(page).count()).toBe(3);
expect(messages.filter((m) => !m.includes('500'))).toEqual([]);
});
// De kaartenrij: op desktop rijen van drie, een onvolledige laatste rij
// staat in het midden, voor elk aantal. Op tablet en mobiel één kolom.
const many = (count: number) =>
Array.from({ length: count }, (_, index) => ({
slug: `pakket-${index + 1}`,
title: `Pakket ${index + 1}`,
price: '€ 100',
features: ['Een kenmerk'],
displayOrder: index,
}));
const boxes = (page: OpenedPage['page']) =>
cards(page).evaluateAll((nodes) =>
nodes.map((node) => {
const { x, y, width } = node.getBoundingClientRect();
return { x, y: Math.round(y + window.scrollY), width };
}),
);
it.each([4, 5, 7, 8, 10])(
'zet de laatste, onvolledige rij van %i kaarten in het midden',
async (count) => {
const { page } = await openPage(server.origin + '/', {
prepare: mock(200, many(count)),
});
await waitForHydration(page);
await eventually(() => cards(page).count()).toBe(count);
const found = await boxes(page);
const rows = new Map<number, typeof found>();
for (const box of found) {
rows.set(box.y, [...(rows.get(box.y) ?? []), box]);
}
const list = [...rows.values()];
expect(list.length).toBe(Math.ceil(count / 3));
const first = list[0];
// Alle kaarten even breed; de volle rij vult de breedte
const width = first[0].width;
const left = first[0].x;
const right = first[2].x + width;
for (const box of found) expect(box.width).toBeCloseTo(width, 0);
for (const row of list.slice(0, -1)) expect(row).toHaveLength(3);
// De laatste rij ligt in het midden van de volle rij
const last = list[list.length - 1];
const rowLeft = last[0].x;
const rowRight = last[last.length - 1].x + width;
expect((rowLeft + rowRight) / 2).toBeCloseTo((left + right) / 2, 0);
},
);
it.each([800, 390])(
'houdt de kaarten onder elkaar bij %ipx breed',
async (width) => {
const { page } = await openPage(server.origin + '/', {
width,
prepare: mock(200, many(4)),
});
await waitForHydration(page);
await eventually(() => cards(page).count()).toBe(4);
const found = await boxes(page);
expect(new Set(found.map((box) => box.x)).size).toBe(1);
expect(new Set(found.map((box) => box.y)).size).toBe(4);
},
);
const topBar =
(status: number, body?: unknown) =>
async (page: OpenedPage['page']) => {
await page.route(
/\/api\/v1\/offerings\/banner\?position=top/,
(route) =>
route.fulfill({
status,
contentType: 'application/json',
body: body === undefined ? '' : JSON.stringify(body),
}),
);
};
it('toont de slanke balk boven de kaarten, op één regel op desktop', async () => {
const { page } = await openPage(server.origin + '/', {
prepare: topBar(200, {
title: 'Nieuw',
text: 'Nog twee plekken in december',
linkLabel: 'Boek nu',
linkUrl: '/contact',
}),
});
await waitForHydration(page);
const bar = page.getByTestId('price-top-bar');
await eventually(() => bar.count()).toBe(1);
const barBox = await bar.boundingBox();
const cardBox = await cards(page).first().boundingBox();
expect(barBox!.y + barBox!.height).toBeLessThan(cardBox!.y);
// Slank: een regel tekst plus opvulling
expect(barBox!.height).toBeLessThan(70);
});
});
@@ -5,11 +5,13 @@ import { renderWithProviders } from '@/test/renderWithProviders';
import PackagesProvider, {
useBanner,
usePackages,
useTopBanner,
type LoadJson,
} from './PackagesProvider';
function Shown() {
const banner = useBanner();
const top = useTopBanner();
return (
<>
<ul>
@@ -18,6 +20,9 @@ function Shown() {
))}
</ul>
<p data-testid="banner">{banner ? banner.title : 'geen banner'}</p>
<p data-testid="top">
{top ? (top.title ?? top.text) : 'geen balk'}
</p>
</>
);
}
@@ -34,12 +39,18 @@ const card = (price: string) => [
// A fake CMS: one answer per path; a value, undefined (204) or an Error to
// throw
type Answers = { offerings?: unknown; banner?: unknown };
type Answers = {
offerings?: unknown;
banner?: unknown;
topBanner?: unknown;
};
const fake = (answers: Answers): LoadJson =>
vi.fn(async (path: string) => {
const answer = path.endsWith('/banner')
? answers.banner
: answers.offerings;
const answer = path.endsWith('?position=top')
? answers.topBanner
: path.endsWith('/banner')
? answers.banner
: answers.offerings;
if (answer instanceof Error) throw answer;
return answer;
});
@@ -125,6 +136,44 @@ describe('PackagesProvider', () => {
expect(screen.getByTestId('banner')).toHaveTextContent('geen banner');
});
it('shows the slim top bar from the CMS, asking for position=top', async () => {
const load = fake({
topBanner: { title: '', text: 'Nog twee plekken', linkLabel: null },
});
await show(load);
await waitFor(() =>
expect(screen.getByTestId('top')).toHaveTextContent(
'Nog twee plekken',
),
);
expect(load).toHaveBeenCalledWith(
'/api/v1/offerings/banner?position=top',
expect.anything(),
);
});
it('keeps the two banners apart', async () => {
await show(
fake({
banner: { title: 'Onder' },
topBanner: { title: 'Boven' },
}),
);
await waitFor(() =>
expect(screen.getByTestId('top')).toHaveTextContent('Boven'),
);
expect(screen.getByTestId('banner')).toHaveTextContent('Onder');
});
it.each([
['a network error', new Error('offline')],
['an answer without title and text', { title: '', text: ' ' }],
['a 204 (no active bar)', undefined],
])('shows no top bar on %s', async (_name, answer) => {
await show(fake({ topBanner: answer }));
expect(screen.getByTestId('top')).toHaveTextContent('geen balk');
});
it('passes an abort signal and aborts on unmount', async () => {
const signals: AbortSignal[] = [];
const load: LoadJson = (_path, signal) => {
@@ -136,7 +185,7 @@ describe('PackagesProvider', () => {
<Shown />
</PackagesProvider>,
);
expect(signals).toHaveLength(2);
expect(signals).toHaveLength(3);
expect(signals.every((signal) => !signal.aborted)).toBe(true);
view.unmount();
expect(signals.every((signal) => signal.aborted)).toBe(true);
@@ -1,8 +1,15 @@
import { createContext, useContext, useEffect, useMemo, useState } from 'react';
import type { ReactNode } from 'react';
import bakedPackages, { banner as bakedBanner } from '@/content/packages';
import type { PricingBanner, PricingPackage } from '@/content/types';
import { mapBanner, mapOfferings } from '@/lib/offerings';
import bakedPackages, {
banner as bakedBanner,
topBanner as bakedTopBanner,
} from '@/content/packages';
import type {
PricingBanner,
PricingPackage,
PricingTopBanner,
} from '@/content/types';
import { mapBanner, mapOfferings, mapTopBanner } from '@/lib/offerings';
// The shoot packages and the announcement banner the pages show. The build
// bakes the current ones into the HTML (prices for search engines, no layout
@@ -13,10 +20,12 @@ import { mapBanner, mapOfferings } from '@/lib/offerings';
// Failing safe is the rule: a network error, a time-out, a bad status or an
// answer that cannot be used leaves what was baked on screen. Nothing flashes
// and no price ever becomes empty. The one exception is by design: a 204 from
// the banner route means "no active banner" and hides a baked banner.
// a banner route means "no active banner" and hides a baked banner (the one
// under the cards and the slim bar above them each on their own).
const OFFERINGS_PATH = '/api/v1/offerings';
const BANNER_PATH = '/api/v1/offerings/banner';
const TOP_BANNER_PATH = '/api/v1/offerings/banner?position=top';
const TIMEOUT_MS = 8000;
// The JSON answer; undefined for 204; throws for anything else
@@ -35,9 +44,14 @@ const loadFromApi: LoadJson = async (path, signal) => {
interface Live {
packages: PricingPackage[];
banner: PricingBanner | null;
topBanner: PricingTopBanner | null;
}
const baked: Live = { packages: bakedPackages, banner: bakedBanner };
const baked: Live = {
packages: bakedPackages,
banner: bakedBanner,
topBanner: bakedTopBanner,
};
const LiveContext = createContext<Live>(baked);
@@ -49,6 +63,10 @@ export const usePackages = (): PricingPackage[] =>
export const useBanner = (): PricingBanner | null =>
useContext(LiveContext).banner;
// The slim bar above the cards, if any
export const useTopBanner = (): PricingTopBanner | null =>
useContext(LiveContext).topBanner;
const same = (a: unknown, b: unknown) =>
JSON.stringify(a) === JSON.stringify(b);
@@ -93,7 +111,19 @@ export default function PackagesProvider({
}
})
.catch(() => undefined);
void Promise.all([packages, banner]).finally(() => clearTimeout(timer));
const topBanner = load(TOP_BANNER_PATH, signal)
.then((answer) => {
if (signal.aborted) return;
if (answer === undefined) update({ topBanner: null });
else {
const mapped = mapTopBanner(answer);
if (mapped) update({ topBanner: mapped });
}
})
.catch(() => undefined);
void Promise.all([packages, banner, topBanner]).finally(() =>
clearTimeout(timer),
);
return () => {
clearTimeout(timer);
controller.abort();
@@ -0,0 +1,85 @@
import { Box, chakra, Text } from '@chakra-ui/react';
import type { PricingTopBanner } from '@/content/types';
type PriceTopBarProps = {
banner: PricingTopBanner;
};
// The slim bar above the price cards: one line with a short announcement
// from the CMS, made to go with the white banner under the cards (same white,
// hairline border and thin heidegroen rule on top). The title is small
// spaced capitals in the heading font, the text is quiet ink, and a link is a
// small underlined deep-green text link, not a button. The title may be left
// out; the text may be too, but not both (mapTopBanner guarantees that). On
// a phone a long line wraps, which is the only time it is more than one.
export default function PriceTopBar({ banner }: PriceTopBarProps) {
const { title, text, link } = banner;
return (
<Box
as="aside"
aria-label={title ?? 'Mededeling'}
data-testid="price-top-bar"
display="flex"
flexWrap="wrap"
alignItems="center"
justifyContent="center"
columnGap={3}
rowGap={1}
mb="gridGap"
mx="auto"
px="clamp(1rem, 3vw, 2rem)"
py={3}
bg="white"
borderWidth="1px"
borderColor="line"
borderTopWidth="3px"
borderTopColor="accent"
textAlign="center"
>
{title && (
<Text
as="strong"
fontFamily="heading"
fontWeight="normal"
fontSize="0.8125rem"
letterSpacing="0.14em"
textTransform="uppercase"
color="ink"
>
{title}
</Text>
)}
{title && text && (
<Box
aria-hidden="true"
w="5px"
h="5px"
bg="accent"
transform="rotate(45deg)"
/>
)}
{text && (
<Text fontSize="0.9375rem" color="ink.soft">
{text}
</Text>
)}
{link && (
<chakra.a
href={link.url}
data-testid="price-top-bar-link"
fontSize="0.875rem"
color="accent.deep"
textDecoration="underline"
textUnderlineOffset="3px"
_hover={{ color: 'ink' }}
{...(link.url.startsWith('https://')
? { rel: 'noopener' }
: {})}
>
{link.label}
</chakra.a>
)}
</Box>
);
}
@@ -94,6 +94,75 @@ describe('Pricing', () => {
expect(await axeResults(container)).toHaveNoViolations();
});
it('shows a slim bar above the cards next to the banner under them', async () => {
const { container } = await renderWithProviders(
<Pricing
content={content}
packages={packages}
banner={{ title: 'Onder' }}
topBanner={{
title: 'Nieuw',
text: 'Nog twee plekken',
link: { label: 'Boek nu', url: 'https://example.nl/x' },
}}
/>,
);
const bar = screen.getByTestId('price-top-bar');
expect(within(bar).getByText('Nieuw')).toBeInTheDocument();
expect(within(bar).getByText('Nog twee plekken')).toBeInTheDocument();
expect(
within(bar).getByRole('link', { name: 'Boek nu' }),
).toHaveAttribute('rel', 'noopener');
// The bar comes before the first card, the banner after the last
const first = screen.getByTestId('price-card-zwangerschap');
expect(
bar.compareDocumentPosition(first) &
Node.DOCUMENT_POSITION_FOLLOWING,
).toBeTruthy();
expect(
first.compareDocumentPosition(screen.getByTestId('price-banner')) &
Node.DOCUMENT_POSITION_FOLLOWING,
).toBeTruthy();
expect(await axeResults(container)).toHaveNoViolations();
});
it('leaves out what the slim bar does not have', async () => {
await renderWithProviders(
<Pricing
content={content}
packages={packages}
topBanner={{ text: 'Alleen tekst' }}
/>,
);
const bar = screen.getByTestId('price-top-bar');
expect(bar).toHaveTextContent('Alleen tekst');
expect(within(bar).queryByRole('link')).not.toBeInTheDocument();
expect(screen.queryByTestId('price-banner')).not.toBeInTheDocument();
});
it('shows a slim bar with a title only and a site link', async () => {
await renderWithProviders(
<Pricing
content={content}
packages={packages}
topBanner={{
title: 'Alleen titel',
link: { label: 'Meer', url: '/contact' },
}}
/>,
);
const bar = screen.getByTestId('price-top-bar');
expect(bar).toHaveTextContent('Alleen titel');
expect(within(bar).getByRole('link')).not.toHaveAttribute('rel');
});
it('shows no slim bar without one', async () => {
await renderWithProviders(
<Pricing content={content} packages={packages} topBanner={null} />,
);
expect(screen.queryByTestId('price-top-bar')).not.toBeInTheDocument();
});
it('shows no banner without one', async () => {
await renderWithProviders(
<Pricing content={content} packages={packages} banner={null} />,
+35 -7
View File
@@ -1,4 +1,4 @@
import { Box, Grid } from '@chakra-ui/react';
import { Box, Flex } from '@chakra-ui/react';
import DeferredImage from '@/components/DeferredImage/DeferredImage';
import PageSection from '@/components/PageSection/PageSection';
import Reveal from '@/components/Reveal/Reveal';
@@ -7,10 +7,12 @@ import type {
HomeContent,
PricingBanner,
PricingPackage,
PricingTopBanner,
} from '@/content/types';
import { visiblePackages } from '@/lib/visiblePackages';
import PriceBanner from './PriceBanner';
import PriceCard from './PriceCard';
import PriceTopBar from './PriceTopBar';
const TITLE_ID = 'pricing-title';
const STAGGER = 0.08;
@@ -29,12 +31,20 @@ type PricingProps = {
packages: PricingPackage[];
// Optional band under the cards; not a package
banner?: PricingBanner | null;
// Optional slim bar above the cards; both may show at the same time
topBanner?: PricingTopBanner | null;
};
// "Prijzen": the shoot packages as cards (design .pricing). One column on
// phones and tablets, three from `lg`. Without a valid package the section
// phones and tablets, from `lg` rows of three where an incomplete last row is
// centred, for any number of cards (4, 5, 7, ...). Without a valid package the section
// is left out entirely.
export default function Pricing({ content, packages, banner }: PricingProps) {
export default function Pricing({
content,
packages,
banner,
topBanner,
}: PricingProps) {
const shown = visiblePackages(packages);
if (shown.length === 0) return null;
@@ -67,18 +77,36 @@ export default function Pricing({ content, packages, banner }: PricingProps) {
lead={content.lead}
/>
</Reveal>
<Grid
templateColumns={{ base: '1fr', lg: 'repeat(3, 1fr)' }}
{topBanner && (
<Reveal>
<PriceTopBar banner={topBanner} />
</Reveal>
)}
{/* Wrapping flex, not a grid: a grid leaves the last row at
the left. Every card is exactly a third of the row minus
the gaps, so the cards of a full row line up and an
incomplete last row is centred. */}
<Flex
direction={{ base: 'column', lg: 'row' }}
wrap={{ base: 'nowrap', lg: 'wrap' }}
justify="center"
gap="gridGap"
maxW={{ base: '460px', lg: 'none' }}
mx="auto"
>
{shown.map((pkg, index) => (
<Reveal key={pkg.id} delay={index * STAGGER} h="100%">
<Reveal
key={pkg.id}
delay={index * STAGGER}
w={{
base: '100%',
lg: 'calc((100% - 2 * {spacing.gridGap}) / 3)',
}}
>
<PriceCard pkg={pkg} />
</Reveal>
))}
</Grid>
</Flex>
{banner && (
<Reveal>
<PriceBanner
+2 -1
View File
@@ -31,5 +31,6 @@
]
}
],
"banner": null
"banner": null,
"topBanner": null
}
+5 -1
View File
@@ -1,9 +1,11 @@
import type { PricingBanner, PricingPackage } from './types';
import type { PricingBanner, PricingPackage, PricingTopBanner } from './types';
import snapshot from './offerings.snapshot.json';
interface Offerings {
packages: PricingPackage[];
banner: PricingBanner | null;
// Missing in a generated file from before the top bar existed
topBanner?: PricingTopBanner | null;
}
// The shoot packages and the optional banner. config/fetchOfferings.ts writes
@@ -27,4 +29,6 @@ const packages: PricingPackage[] = offerings.packages;
export const banner: PricingBanner | null = offerings.banner;
export const topBanner: PricingTopBanner | null = offerings.topBanner ?? null;
export default packages;
+9
View File
@@ -112,6 +112,15 @@ export interface PricingBanner {
link?: { label: string; url: string };
}
// The slim bar above the price cards (GET
// /api/v1/offerings/banner?position=top): one line with a title, a text or
// both, and optionally a small link. Both banners may show at the same time.
export interface PricingTopBanner {
title?: string;
text?: string;
link?: { label: string; url: string };
}
// The kinds of shoot Andrea offers. The ids are stable: they go into URLs
// (/portfolio?shoot=) and the portfolio page tags its photos with them.
export type ShootTypeId =
+32
View File
@@ -3,6 +3,7 @@ import { describe, expect, it } from 'vitest';
import {
isSafeBannerUrl,
mapBanner,
mapTopBanner,
mapOfferings,
parsePriceText,
} from './offerings';
@@ -164,6 +165,37 @@ describe('mapBanner', () => {
});
});
describe('mapTopBanner', () => {
it('accepts a title, a text or both, and a complete safe link', () => {
expect(mapTopBanner({ title: 'T', text: 'x' })).toMatchObject({
title: 'T',
text: 'x',
});
expect(mapTopBanner({ title: '', text: 'x' })?.title).toBeUndefined();
expect(mapTopBanner({ title: 'T', text: null })?.text).toBeUndefined();
expect(
mapTopBanner({
text: 'x',
linkLabel: 'Hier',
linkUrl: '/contact',
})?.link,
).toEqual({ label: 'Hier', url: '/contact' });
expect(
mapTopBanner({
text: 'x',
linkLabel: 'Hier',
linkUrl: 'http://a.nl',
})?.link,
).toBeUndefined();
});
it('rejects an answer with neither title nor text', () => {
expect(mapTopBanner({ title: ' ', text: '' })).toBeNull();
expect(mapTopBanner(null)).toBeNull();
expect(mapTopBanner([{ title: 'T' }])).toBeNull();
});
});
describe('isSafeBannerUrl', () => {
it.each(['https://example.nl/x', '/contact', '/#contact', '/a?b=1'])(
'staat %s toe',
+25
View File
@@ -27,9 +27,18 @@ export interface OfferingBanner {
link?: { label: string; url: string };
}
// The slim bar above the cards (GET /api/v1/offerings/banner?position=top).
// The title may be empty here, but not both title and text.
export interface OfferingTopBanner {
title?: string;
text?: string;
link?: { label: string; url: string };
}
export interface SiteOfferings {
packages: OfferingPackage[];
banner: OfferingBanner | null;
topBanner: OfferingTopBanner | null;
}
const SLUG = /^[a-z0-9-]+$/;
@@ -116,6 +125,22 @@ export function mapBanner(answer: unknown): OfferingBanner | null {
};
}
// The 200 answer of /api/v1/offerings/banner?position=top: one line, so a
// title, a text or both; null when it has neither
export function mapTopBanner(answer: unknown): OfferingTopBanner | null {
if (!isObject(answer)) return null;
const title = asText(answer.title);
const text = asText(answer.text);
if (!title && !text) return null;
const label = asText(answer.linkLabel);
const url = asText(answer.linkUrl);
return {
title,
text,
link: label && url && isSafeBannerUrl(url) ? { label, url } : undefined,
};
}
const orderOf = (raw: RawOffering) =>
typeof raw.displayOrder === 'number' ? raw.displayOrder : 0;
+3
View File
@@ -11,6 +11,7 @@ import homeContent from '../content/homeContent';
import instagramContent from '../content/instagramContent';
import {
useBanner,
useTopBanner,
usePackages,
} from '../components/PackagesProvider/PackagesProvider';
import testimonials from '../content/testimonials';
@@ -34,6 +35,7 @@ export const Route = createFileRoute('/')({
function Index() {
const packages = usePackages();
const banner = useBanner();
const topBanner = useTopBanner();
const { pakket: searched } = Route.useSearch();
// The search only counts after hydration, so the prerendered HTML and the
// first browser render agree (BR-HYD-10)
@@ -51,6 +53,7 @@ function Index() {
content={homeContent.pricing}
packages={packages}
banner={banner}
topBanner={topBanner}
/>
<Testimonials
content={homeContent.testimonials}