Packages and banners from the CMS, host injection, translation files and the contact form #19
@@ -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-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-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-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.
|
- 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).
|
- NFR-PK-01 Tests use the snapshot only (no dependence on a build or network).
|
||||||
|
|
||||||
|
|||||||
@@ -11,6 +11,7 @@ import { fileURLToPath } from 'node:url';
|
|||||||
import {
|
import {
|
||||||
mapBanner,
|
mapBanner,
|
||||||
mapOfferings,
|
mapOfferings,
|
||||||
|
mapTopBanner,
|
||||||
type SiteOfferings,
|
type SiteOfferings,
|
||||||
} from '../src/lib/offerings.ts';
|
} from '../src/lib/offerings.ts';
|
||||||
|
|
||||||
@@ -81,6 +82,25 @@ async function main() {
|
|||||||
`[offerings] banner not available (${String(error)}): none`,
|
`[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 {
|
} else {
|
||||||
console.warn(
|
console.warn(
|
||||||
`[offerings] answer of ${base} has no valid package: using the snapshot`,
|
`[offerings] answer of ${base} has no valid package: using the snapshot`,
|
||||||
|
|||||||
@@ -76,4 +76,101 @@ describe('pakketten live uit het CMS', () => {
|
|||||||
expect(await cards(page).count()).toBe(3);
|
expect(await cards(page).count()).toBe(3);
|
||||||
expect(messages.filter((m) => !m.includes('500'))).toEqual([]);
|
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, {
|
import PackagesProvider, {
|
||||||
useBanner,
|
useBanner,
|
||||||
usePackages,
|
usePackages,
|
||||||
|
useTopBanner,
|
||||||
type LoadJson,
|
type LoadJson,
|
||||||
} from './PackagesProvider';
|
} from './PackagesProvider';
|
||||||
|
|
||||||
function Shown() {
|
function Shown() {
|
||||||
const banner = useBanner();
|
const banner = useBanner();
|
||||||
|
const top = useTopBanner();
|
||||||
return (
|
return (
|
||||||
<>
|
<>
|
||||||
<ul>
|
<ul>
|
||||||
@@ -18,6 +20,9 @@ function Shown() {
|
|||||||
))}
|
))}
|
||||||
</ul>
|
</ul>
|
||||||
<p data-testid="banner">{banner ? banner.title : 'geen banner'}</p>
|
<p data-testid="banner">{banner ? banner.title : 'geen banner'}</p>
|
||||||
|
<p data-testid="top">
|
||||||
|
{top ? (top.title ?? top.text) : 'geen balk'}
|
||||||
|
</p>
|
||||||
</>
|
</>
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
@@ -34,10 +39,16 @@ const card = (price: string) => [
|
|||||||
|
|
||||||
// A fake CMS: one answer per path; a value, undefined (204) or an Error to
|
// A fake CMS: one answer per path; a value, undefined (204) or an Error to
|
||||||
// throw
|
// throw
|
||||||
type Answers = { offerings?: unknown; banner?: unknown };
|
type Answers = {
|
||||||
|
offerings?: unknown;
|
||||||
|
banner?: unknown;
|
||||||
|
topBanner?: unknown;
|
||||||
|
};
|
||||||
const fake = (answers: Answers): LoadJson =>
|
const fake = (answers: Answers): LoadJson =>
|
||||||
vi.fn(async (path: string) => {
|
vi.fn(async (path: string) => {
|
||||||
const answer = path.endsWith('/banner')
|
const answer = path.endsWith('?position=top')
|
||||||
|
? answers.topBanner
|
||||||
|
: path.endsWith('/banner')
|
||||||
? answers.banner
|
? answers.banner
|
||||||
: answers.offerings;
|
: answers.offerings;
|
||||||
if (answer instanceof Error) throw answer;
|
if (answer instanceof Error) throw answer;
|
||||||
@@ -125,6 +136,44 @@ describe('PackagesProvider', () => {
|
|||||||
expect(screen.getByTestId('banner')).toHaveTextContent('geen banner');
|
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 () => {
|
it('passes an abort signal and aborts on unmount', async () => {
|
||||||
const signals: AbortSignal[] = [];
|
const signals: AbortSignal[] = [];
|
||||||
const load: LoadJson = (_path, signal) => {
|
const load: LoadJson = (_path, signal) => {
|
||||||
@@ -136,7 +185,7 @@ describe('PackagesProvider', () => {
|
|||||||
<Shown />
|
<Shown />
|
||||||
</PackagesProvider>,
|
</PackagesProvider>,
|
||||||
);
|
);
|
||||||
expect(signals).toHaveLength(2);
|
expect(signals).toHaveLength(3);
|
||||||
expect(signals.every((signal) => !signal.aborted)).toBe(true);
|
expect(signals.every((signal) => !signal.aborted)).toBe(true);
|
||||||
view.unmount();
|
view.unmount();
|
||||||
expect(signals.every((signal) => signal.aborted)).toBe(true);
|
expect(signals.every((signal) => signal.aborted)).toBe(true);
|
||||||
|
|||||||
@@ -1,8 +1,15 @@
|
|||||||
import { createContext, useContext, useEffect, useMemo, useState } from 'react';
|
import { createContext, useContext, useEffect, useMemo, useState } from 'react';
|
||||||
import type { ReactNode } from 'react';
|
import type { ReactNode } from 'react';
|
||||||
import bakedPackages, { banner as bakedBanner } from '@/content/packages';
|
import bakedPackages, {
|
||||||
import type { PricingBanner, PricingPackage } from '@/content/types';
|
banner as bakedBanner,
|
||||||
import { mapBanner, mapOfferings } from '@/lib/offerings';
|
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
|
// 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
|
// 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
|
// 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
|
// 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
|
// 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 OFFERINGS_PATH = '/api/v1/offerings';
|
||||||
const BANNER_PATH = '/api/v1/offerings/banner';
|
const BANNER_PATH = '/api/v1/offerings/banner';
|
||||||
|
const TOP_BANNER_PATH = '/api/v1/offerings/banner?position=top';
|
||||||
const TIMEOUT_MS = 8000;
|
const TIMEOUT_MS = 8000;
|
||||||
|
|
||||||
// The JSON answer; undefined for 204; throws for anything else
|
// The JSON answer; undefined for 204; throws for anything else
|
||||||
@@ -35,9 +44,14 @@ const loadFromApi: LoadJson = async (path, signal) => {
|
|||||||
interface Live {
|
interface Live {
|
||||||
packages: PricingPackage[];
|
packages: PricingPackage[];
|
||||||
banner: PricingBanner | null;
|
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);
|
const LiveContext = createContext<Live>(baked);
|
||||||
|
|
||||||
@@ -49,6 +63,10 @@ export const usePackages = (): PricingPackage[] =>
|
|||||||
export const useBanner = (): PricingBanner | null =>
|
export const useBanner = (): PricingBanner | null =>
|
||||||
useContext(LiveContext).banner;
|
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) =>
|
const same = (a: unknown, b: unknown) =>
|
||||||
JSON.stringify(a) === JSON.stringify(b);
|
JSON.stringify(a) === JSON.stringify(b);
|
||||||
|
|
||||||
@@ -93,7 +111,19 @@ export default function PackagesProvider({
|
|||||||
}
|
}
|
||||||
})
|
})
|
||||||
.catch(() => undefined);
|
.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 () => {
|
return () => {
|
||||||
clearTimeout(timer);
|
clearTimeout(timer);
|
||||||
controller.abort();
|
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();
|
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 () => {
|
it('shows no banner without one', async () => {
|
||||||
await renderWithProviders(
|
await renderWithProviders(
|
||||||
<Pricing content={content} packages={packages} banner={null} />,
|
<Pricing content={content} packages={packages} banner={null} />,
|
||||||
|
|||||||
@@ -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 DeferredImage from '@/components/DeferredImage/DeferredImage';
|
||||||
import PageSection from '@/components/PageSection/PageSection';
|
import PageSection from '@/components/PageSection/PageSection';
|
||||||
import Reveal from '@/components/Reveal/Reveal';
|
import Reveal from '@/components/Reveal/Reveal';
|
||||||
@@ -7,10 +7,12 @@ import type {
|
|||||||
HomeContent,
|
HomeContent,
|
||||||
PricingBanner,
|
PricingBanner,
|
||||||
PricingPackage,
|
PricingPackage,
|
||||||
|
PricingTopBanner,
|
||||||
} from '@/content/types';
|
} from '@/content/types';
|
||||||
import { visiblePackages } from '@/lib/visiblePackages';
|
import { visiblePackages } from '@/lib/visiblePackages';
|
||||||
import PriceBanner from './PriceBanner';
|
import PriceBanner from './PriceBanner';
|
||||||
import PriceCard from './PriceCard';
|
import PriceCard from './PriceCard';
|
||||||
|
import PriceTopBar from './PriceTopBar';
|
||||||
|
|
||||||
const TITLE_ID = 'pricing-title';
|
const TITLE_ID = 'pricing-title';
|
||||||
const STAGGER = 0.08;
|
const STAGGER = 0.08;
|
||||||
@@ -29,12 +31,20 @@ type PricingProps = {
|
|||||||
packages: PricingPackage[];
|
packages: PricingPackage[];
|
||||||
// Optional band under the cards; not a package
|
// Optional band under the cards; not a package
|
||||||
banner?: PricingBanner | null;
|
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
|
// "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.
|
// 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);
|
const shown = visiblePackages(packages);
|
||||||
if (shown.length === 0) return null;
|
if (shown.length === 0) return null;
|
||||||
|
|
||||||
@@ -67,18 +77,36 @@ export default function Pricing({ content, packages, banner }: PricingProps) {
|
|||||||
lead={content.lead}
|
lead={content.lead}
|
||||||
/>
|
/>
|
||||||
</Reveal>
|
</Reveal>
|
||||||
<Grid
|
{topBanner && (
|
||||||
templateColumns={{ base: '1fr', lg: 'repeat(3, 1fr)' }}
|
<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"
|
gap="gridGap"
|
||||||
maxW={{ base: '460px', lg: 'none' }}
|
maxW={{ base: '460px', lg: 'none' }}
|
||||||
mx="auto"
|
mx="auto"
|
||||||
>
|
>
|
||||||
{shown.map((pkg, index) => (
|
{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} />
|
<PriceCard pkg={pkg} />
|
||||||
</Reveal>
|
</Reveal>
|
||||||
))}
|
))}
|
||||||
</Grid>
|
</Flex>
|
||||||
{banner && (
|
{banner && (
|
||||||
<Reveal>
|
<Reveal>
|
||||||
<PriceBanner
|
<PriceBanner
|
||||||
|
|||||||
@@ -31,5 +31,6 @@
|
|||||||
]
|
]
|
||||||
}
|
}
|
||||||
],
|
],
|
||||||
"banner": null
|
"banner": null,
|
||||||
|
"topBanner": null
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -1,9 +1,11 @@
|
|||||||
import type { PricingBanner, PricingPackage } from './types';
|
import type { PricingBanner, PricingPackage, PricingTopBanner } from './types';
|
||||||
import snapshot from './offerings.snapshot.json';
|
import snapshot from './offerings.snapshot.json';
|
||||||
|
|
||||||
interface Offerings {
|
interface Offerings {
|
||||||
packages: PricingPackage[];
|
packages: PricingPackage[];
|
||||||
banner: PricingBanner | null;
|
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
|
// 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 banner: PricingBanner | null = offerings.banner;
|
||||||
|
|
||||||
|
export const topBanner: PricingTopBanner | null = offerings.topBanner ?? null;
|
||||||
|
|
||||||
export default packages;
|
export default packages;
|
||||||
|
|||||||
@@ -112,6 +112,15 @@ export interface PricingBanner {
|
|||||||
link?: { label: string; url: string };
|
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
|
// 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.
|
// (/portfolio?shoot=) and the portfolio page tags its photos with them.
|
||||||
export type ShootTypeId =
|
export type ShootTypeId =
|
||||||
|
|||||||
@@ -3,6 +3,7 @@ import { describe, expect, it } from 'vitest';
|
|||||||
import {
|
import {
|
||||||
isSafeBannerUrl,
|
isSafeBannerUrl,
|
||||||
mapBanner,
|
mapBanner,
|
||||||
|
mapTopBanner,
|
||||||
mapOfferings,
|
mapOfferings,
|
||||||
parsePriceText,
|
parsePriceText,
|
||||||
} from './offerings';
|
} 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', () => {
|
describe('isSafeBannerUrl', () => {
|
||||||
it.each(['https://example.nl/x', '/contact', '/#contact', '/a?b=1'])(
|
it.each(['https://example.nl/x', '/contact', '/#contact', '/a?b=1'])(
|
||||||
'staat %s toe',
|
'staat %s toe',
|
||||||
|
|||||||
@@ -27,9 +27,18 @@ export interface OfferingBanner {
|
|||||||
link?: { label: string; url: string };
|
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 {
|
export interface SiteOfferings {
|
||||||
packages: OfferingPackage[];
|
packages: OfferingPackage[];
|
||||||
banner: OfferingBanner | null;
|
banner: OfferingBanner | null;
|
||||||
|
topBanner: OfferingTopBanner | null;
|
||||||
}
|
}
|
||||||
|
|
||||||
const SLUG = /^[a-z0-9-]+$/;
|
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) =>
|
const orderOf = (raw: RawOffering) =>
|
||||||
typeof raw.displayOrder === 'number' ? raw.displayOrder : 0;
|
typeof raw.displayOrder === 'number' ? raw.displayOrder : 0;
|
||||||
|
|
||||||
|
|||||||
@@ -11,6 +11,7 @@ import homeContent from '../content/homeContent';
|
|||||||
import instagramContent from '../content/instagramContent';
|
import instagramContent from '../content/instagramContent';
|
||||||
import {
|
import {
|
||||||
useBanner,
|
useBanner,
|
||||||
|
useTopBanner,
|
||||||
usePackages,
|
usePackages,
|
||||||
} from '../components/PackagesProvider/PackagesProvider';
|
} from '../components/PackagesProvider/PackagesProvider';
|
||||||
import testimonials from '../content/testimonials';
|
import testimonials from '../content/testimonials';
|
||||||
@@ -34,6 +35,7 @@ export const Route = createFileRoute('/')({
|
|||||||
function Index() {
|
function Index() {
|
||||||
const packages = usePackages();
|
const packages = usePackages();
|
||||||
const banner = useBanner();
|
const banner = useBanner();
|
||||||
|
const topBanner = useTopBanner();
|
||||||
const { pakket: searched } = Route.useSearch();
|
const { pakket: searched } = Route.useSearch();
|
||||||
// The search only counts after hydration, so the prerendered HTML and the
|
// The search only counts after hydration, so the prerendered HTML and the
|
||||||
// first browser render agree (BR-HYD-10)
|
// first browser render agree (BR-HYD-10)
|
||||||
@@ -51,6 +53,7 @@ function Index() {
|
|||||||
content={homeContent.pricing}
|
content={homeContent.pricing}
|
||||||
packages={packages}
|
packages={packages}
|
||||||
banner={banner}
|
banner={banner}
|
||||||
|
topBanner={topBanner}
|
||||||
/>
|
/>
|
||||||
<Testimonials
|
<Testimonials
|
||||||
content={homeContent.testimonials}
|
content={homeContent.testimonials}
|
||||||
|
|||||||
Reference in New Issue
Block a user