Reads the shoot packages and an optional banner from the CMS at build time
The build asks GET /api/v1/offerings and bakes the packages into the pages, with a committed snapshot as fallback so a CMS outage never breaks the build or shows an empty price. The form choices and ?pakket= use the same list. An offering with layout=banner becomes an optional band under the price cards. Co-Authored-By: Claude Sonnet 5.5 <noreply@anthropic.com>
This commit is contained in:
@@ -84,10 +84,17 @@ jobs:
|
|||||||
run: pnpm test
|
run: pnpm test
|
||||||
|
|
||||||
# Sentry toont bij elke fout uit welke commit de build komt
|
# Sentry toont bij elke fout uit welke commit de build komt
|
||||||
|
# De pakketten en prijzen komen uit het CMS: de build haalt ze op
|
||||||
|
# (web/config/fetchOfferings.ts) en valt bij een storing terug op de
|
||||||
|
# gecommitte lijst. ASF_OFFERINGS_URL (repo-variabele) is het adres dat
|
||||||
|
# /api/v1/offerings serveert, zonder is de fallback de bron. Let op: dit
|
||||||
|
# artefact is ook wat naar productie gaat; zet de variabele dus op het
|
||||||
|
# CMS waar de echte gegevens staan.
|
||||||
- name: Build
|
- name: Build
|
||||||
run: pnpm build
|
run: pnpm build
|
||||||
env:
|
env:
|
||||||
VITE_RELEASE: ${{ github.sha }}
|
VITE_RELEASE: ${{ github.sha }}
|
||||||
|
OFFERINGS_URL: ${{ vars.ASF_OFFERINGS_URL }}
|
||||||
|
|
||||||
- name: Audit (productiepakketten, blokkerend)
|
- name: Audit (productiepakketten, blokkerend)
|
||||||
run: pnpm audit:deps
|
run: pnpm audit:deps
|
||||||
|
|||||||
@@ -14,3 +14,4 @@
|
|||||||
| Feature | testimonials-redesign | ✅ Complete (merged, PR #16) | feature/testimonials-redesign (worktree ../AndreaSlopFotografie-testimonials-redesign) | web/src/components/home/Testimonials (Testimonials, TestimonialSlide, TestimonialCarousel), web/src/recipes/carouselControl.ts, web/src/content (Testimonial type, testimonials.ts), possibly SectionHeading, LAYOUT.md, unit/e2e tests that reference the dots | 2026-11-05 |
|
| Feature | testimonials-redesign | ✅ Complete (merged, PR #16) | feature/testimonials-redesign (worktree ../AndreaSlopFotografie-testimonials-redesign) | web/src/components/home/Testimonials (Testimonials, TestimonialSlide, TestimonialCarousel), web/src/recipes/carouselControl.ts, web/src/content (Testimonial type, testimonials.ts), possibly SectionHeading, LAYOUT.md, unit/e2e tests that reference the dots | 2026-11-05 |
|
||||||
| Feature | cms-api-foundation | ✅ Complete (merged PR #17, 2026-11-10; follow-ups: ASF production, contact feature) | feature/cms-api-foundation (worktree ../AndreaSlopFotografie-cms-api-foundation) | Cross-repo: feature briefs for the SlpModularCms repo (new Api.AndreaSlopFotografie client, per-site theming, per-site module set); in this repo only docs, later web integration (CMS serves the site) | 2026-11-05 |
|
| Feature | cms-api-foundation | ✅ Complete (merged PR #17, 2026-11-10; follow-ups: ASF production, contact feature) | feature/cms-api-foundation (worktree ../AndreaSlopFotografie-cms-api-foundation) | Cross-repo: feature briefs for the SlpModularCms repo (new Api.AndreaSlopFotografie client, per-site theming, per-site module set); in this repo only docs, later web integration (CMS serves the site) | 2026-11-05 |
|
||||||
| Feature | contact-form-cms | 🔵 Inception | feature/contact-form-cms (worktree ../AndreaSlopFotografie-contact-form) | web/src/components/ContactForm, ContactFormGate, web/src/contact (submitContactForm), new web/src/cms-client (copied headless package), web/config/securityHeaders.ts, content/siteContent contactForm switch | 2026-11-10 |
|
| Feature | contact-form-cms | 🔵 Inception | feature/contact-form-cms (worktree ../AndreaSlopFotografie-contact-form) | web/src/components/ContactForm, ContactFormGate, web/src/contact (submitContactForm), new web/src/cms-client (copied headless package), web/config/securityHeaders.ts, content/siteContent contactForm switch | 2026-11-10 |
|
||||||
|
| Feature | asf-packages-cms | 🔵 Construction | feature/asf-packages-cms (worktree ../AndreaSlopFotografie-packages, based on feature/contact-form-cms) | web/config (offerings, fetchOfferings), web/src/content (packages, snapshot, types), Pricing + PriceBanner, CI Build env | 2026-11-12 |
|
||||||
|
|||||||
@@ -0,0 +1,30 @@
|
|||||||
|
# AI-DLC State Tracking
|
||||||
|
|
||||||
|
## Project Information
|
||||||
|
- **Feature Name**: ASF packages and banner from the CMS (build-time)
|
||||||
|
- **Feature Slug**: asf-packages-cms
|
||||||
|
- **Project Type**: Brownfield
|
||||||
|
- **Start Date**: 2026-11-12
|
||||||
|
- **Current Stage**: CONSTRUCTION - code generated, awaiting CMS data on ASF-test for a test deploy
|
||||||
|
- **Branch**: feature/asf-packages-cms (from feature/contact-form-cms 7737104; merge order: contact-form-cms first)
|
||||||
|
- **Worktree**: K:\Development\SlpSoftware\Projects\AndreaSlopFotografie-packages
|
||||||
|
|
||||||
|
## Language Configuration
|
||||||
|
- **Documentation Language**: English
|
||||||
|
- **Conversation Language**: User Language (Dutch)
|
||||||
|
- **Source**: aidlc-docs/language-preference.md
|
||||||
|
|
||||||
|
## Extension Configuration
|
||||||
|
- Security Baseline: Yes (inherited from contact-form-cms)
|
||||||
|
- Property-Based Testing: Partial (inherited)
|
||||||
|
|
||||||
|
## Operations Configuration
|
||||||
|
- **Include Operations Phase**: No for now (deployment is the existing CI; rebuild trigger is a pending decision by Bryan)
|
||||||
|
|
||||||
|
## Stage Progress
|
||||||
|
- [x] INCEPTION - Workspace Detection, Requirements (approved by SLP Software - SLS - Main for Bryan, 2026-11-12)
|
||||||
|
- [x] INCEPTION - Workflow Planning (single unit: build step + site wiring)
|
||||||
|
- [x] CONSTRUCTION - Functional Design (see requirements.md, design recorded there; approved: snapshot fallback, one source, banner as own block)
|
||||||
|
- [x] CONSTRUCTION - Code Generation (build step, mapping, snapshot, banner, tests)
|
||||||
|
- [ ] CONSTRUCTION - Build and Test on ASF-test with real CMS data (blocked: Offerings module + 3 packages in the ASF-test CMS, asked of the CMS session)
|
||||||
|
- [ ] OPERATIONS - rebuild trigger (webhook or nightly) decided by Bryan
|
||||||
@@ -0,0 +1,25 @@
|
|||||||
|
# Requirements and design: packages and banner from the CMS
|
||||||
|
|
||||||
|
Decided by Bryan via SLP Software - SLS - Main, 2026-11-12. Source of truth: the CMS API `GET /api/v1/offerings` (fields: id, slug, title, description, price as free text, priceNote, features[], ctaLabel, featured, displayOrder, categoryId, category, layout `card|banner`; at most one banner per site).
|
||||||
|
|
||||||
|
## Requirements
|
||||||
|
- FR-PK-01 The build asks the CMS for the offerings and bakes them into the pages (prices in the HTML and in the structured data). The browser never calls the offerings API.
|
||||||
|
- FR-PK-02 Fallback: with no address, an unreachable CMS or an answer without a valid package the committed snapshot (`src/content/offerings.snapshot.json`, the three packages) is used. The build never fails because of the CMS and never shows an empty or wrong price. The log names the source.
|
||||||
|
- 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-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).
|
||||||
|
|
||||||
|
## Design
|
||||||
|
- `web/config/offerings.ts` pure mapping and validation (unit and property tests).
|
||||||
|
- `web/config/fetchOfferings.ts` build step (`pnpm build` runs it first): `OFFERINGS_URL` (the site's own address serving the API), 10 s timeout, 2 attempts, writes the gitignored `src/content/offerings.generated.json`.
|
||||||
|
- `web/src/content/packages.ts` picks generated data (build) or the snapshot (tests, missing file).
|
||||||
|
- CI: the Build step gets `OFFERINGS_URL` from the repo variable `ASF_OFFERINGS_URL`. The artifact built there is also what goes to production, so the variable must point to the CMS holding the real data.
|
||||||
|
- `PriceBanner` component inside `Pricing`.
|
||||||
|
|
||||||
|
## Open
|
||||||
|
- Offerings module on the ASF-test host and the three packages in the ASF-test CMS (asked of the CMS session; 2026-11-12 the endpoint answered 404 on test.andreaslop.nl).
|
||||||
|
- Repo variable `ASF_OFFERINGS_URL` (who sets it: Bryan or SLS).
|
||||||
|
- Rebuild trigger.
|
||||||
|
- ASF production CMS address does not exist yet.
|
||||||
@@ -30,3 +30,6 @@ lighthouse-reports
|
|||||||
|
|
||||||
# Gegenereerde cache van Start
|
# Gegenereerde cache van Start
|
||||||
.tanstack
|
.tanstack
|
||||||
|
|
||||||
|
# Written by config/fetchOfferings.ts before every build
|
||||||
|
src/content/offerings.generated.json
|
||||||
|
|||||||
@@ -0,0 +1,69 @@
|
|||||||
|
// Build step, runs before the build: asks the CMS for the shoot packages and
|
||||||
|
// writes src/content/offerings.generated.json, which the site imports. With
|
||||||
|
// no address, a failing CMS or an unusable answer the committed snapshot
|
||||||
|
// (src/content/offerings.snapshot.json) is used, so the build never fails
|
||||||
|
// and never shows empty prices. The log says which one was used.
|
||||||
|
//
|
||||||
|
// OFFERINGS_URL: the site's own address that serves the API, for example
|
||||||
|
// https://test.andreaslop.nl (the API is same-origin, /api/v1/offerings).
|
||||||
|
import { readFileSync, writeFileSync } from 'node:fs';
|
||||||
|
import { fileURLToPath } from 'node:url';
|
||||||
|
import { mapOfferings, type SiteOfferings } from './offerings.ts';
|
||||||
|
|
||||||
|
const SNAPSHOT = fileURLToPath(
|
||||||
|
new URL('../src/content/offerings.snapshot.json', import.meta.url),
|
||||||
|
);
|
||||||
|
const GENERATED = fileURLToPath(
|
||||||
|
new URL('../src/content/offerings.generated.json', import.meta.url),
|
||||||
|
);
|
||||||
|
const TIMEOUT_MS = 10_000;
|
||||||
|
const ATTEMPTS = 2;
|
||||||
|
|
||||||
|
async function fetchAnswer(base: string): Promise<unknown> {
|
||||||
|
const url = new URL('/api/v1/offerings', base);
|
||||||
|
for (let attempt = 1; ; attempt++) {
|
||||||
|
try {
|
||||||
|
const response = await fetch(url, {
|
||||||
|
signal: AbortSignal.timeout(TIMEOUT_MS),
|
||||||
|
headers: { Accept: 'application/json' },
|
||||||
|
});
|
||||||
|
if (!response.ok) throw new Error(`status ${response.status}`);
|
||||||
|
return await response.json();
|
||||||
|
} catch (error) {
|
||||||
|
if (attempt >= ATTEMPTS) throw error;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
async function main() {
|
||||||
|
const snapshot = JSON.parse(
|
||||||
|
readFileSync(SNAPSHOT, 'utf8'),
|
||||||
|
) as SiteOfferings;
|
||||||
|
const base = process.env.OFFERINGS_URL?.trim();
|
||||||
|
let result = { ...snapshot, source: 'snapshot' };
|
||||||
|
if (!base) {
|
||||||
|
console.log('[offerings] no OFFERINGS_URL: using the snapshot');
|
||||||
|
} else {
|
||||||
|
try {
|
||||||
|
const mapped = mapOfferings(await fetchAnswer(base));
|
||||||
|
if (mapped) {
|
||||||
|
result = { ...mapped, source: 'cms' };
|
||||||
|
console.log(
|
||||||
|
`[offerings] ${mapped.packages.length} packages` +
|
||||||
|
`${mapped.banner ? ' and a banner' : ''} from ${base}`,
|
||||||
|
);
|
||||||
|
} else {
|
||||||
|
console.warn(
|
||||||
|
`[offerings] answer of ${base} has no valid package: using the snapshot`,
|
||||||
|
);
|
||||||
|
}
|
||||||
|
} catch (error) {
|
||||||
|
console.warn(
|
||||||
|
`[offerings] ${base} not reachable (${String(error)}): using the snapshot`,
|
||||||
|
);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
writeFileSync(GENERATED, JSON.stringify(result, null, 4) + '\n');
|
||||||
|
}
|
||||||
|
|
||||||
|
await main();
|
||||||
@@ -0,0 +1,135 @@
|
|||||||
|
import fc from 'fast-check';
|
||||||
|
import { describe, expect, it } from 'vitest';
|
||||||
|
import { mapOfferings, parsePriceText } from './offerings';
|
||||||
|
|
||||||
|
const card = (over: Record<string, unknown> = {}) => ({
|
||||||
|
id: 'x',
|
||||||
|
slug: 'newborn',
|
||||||
|
title: 'Newborn',
|
||||||
|
description: 'Mooie shoot',
|
||||||
|
price: '€ 185',
|
||||||
|
priceNote: 'incl. galerij',
|
||||||
|
features: ['1-2 uur fotografie', 'Online galerij'],
|
||||||
|
ctaLabel: 'Boek',
|
||||||
|
featured: false,
|
||||||
|
displayOrder: 2,
|
||||||
|
categoryId: null,
|
||||||
|
category: null,
|
||||||
|
layout: 'card',
|
||||||
|
...over,
|
||||||
|
});
|
||||||
|
|
||||||
|
describe('parsePriceText', () => {
|
||||||
|
it.each([
|
||||||
|
['€ 175', 175],
|
||||||
|
['€ 1.250', 1250],
|
||||||
|
['175,-', 175],
|
||||||
|
['€ 175,00', 175],
|
||||||
|
['€\u00a0185', 185],
|
||||||
|
])('leest %s als %i', (text, euros) => {
|
||||||
|
expect(parsePriceText(text)).toBe(euros);
|
||||||
|
});
|
||||||
|
|
||||||
|
it.each(['', 'op aanvraag', '€ 12,50', '€ 0', '175 of 185', null, 12])(
|
||||||
|
'geeft geen prijs voor %j',
|
||||||
|
(text) => {
|
||||||
|
expect(parsePriceText(text)).toBeNull();
|
||||||
|
},
|
||||||
|
);
|
||||||
|
|
||||||
|
it('geeft terug wat formatteren als hele euros oplevert', () => {
|
||||||
|
fc.assert(
|
||||||
|
fc.property(fc.integer({ min: 1, max: 99_999 }), (euros) => {
|
||||||
|
const grouped = euros.toLocaleString('nl-NL');
|
||||||
|
expect(parsePriceText(`€ ${grouped}`)).toBe(euros);
|
||||||
|
expect(parsePriceText(`€ ${euros}`)).toBe(euros);
|
||||||
|
}),
|
||||||
|
);
|
||||||
|
});
|
||||||
|
});
|
||||||
|
|
||||||
|
describe('mapOfferings', () => {
|
||||||
|
it('maakt pakketten in volgorde van displayOrder', () => {
|
||||||
|
const result = mapOfferings([
|
||||||
|
card({ slug: 'gezin', title: 'Gezin', displayOrder: 3 }),
|
||||||
|
card({
|
||||||
|
slug: 'zwangerschap',
|
||||||
|
title: 'Zwangerschap',
|
||||||
|
displayOrder: 1,
|
||||||
|
}),
|
||||||
|
card(),
|
||||||
|
]);
|
||||||
|
expect(result?.packages.map((p) => p.id)).toEqual([
|
||||||
|
'zwangerschap',
|
||||||
|
'newborn',
|
||||||
|
'gezin',
|
||||||
|
]);
|
||||||
|
expect(result?.packages[1]).toMatchObject({
|
||||||
|
name: 'Newborn',
|
||||||
|
price: 185,
|
||||||
|
priceNote: 'incl. galerij',
|
||||||
|
ctaLabel: 'Boek',
|
||||||
|
});
|
||||||
|
expect(result?.banner).toBeNull();
|
||||||
|
});
|
||||||
|
|
||||||
|
it('houdt de banner buiten de pakketten en neemt de eerste bruikbare', () => {
|
||||||
|
const result = mapOfferings([
|
||||||
|
card(),
|
||||||
|
card({
|
||||||
|
slug: 'actie',
|
||||||
|
title: 'Kerstactie',
|
||||||
|
price: '€ 99 i.p.v. € 150',
|
||||||
|
layout: 'banner',
|
||||||
|
displayOrder: 9,
|
||||||
|
}),
|
||||||
|
card({
|
||||||
|
slug: 'actie2',
|
||||||
|
title: 'Tweede',
|
||||||
|
layout: 'banner',
|
||||||
|
displayOrder: 10,
|
||||||
|
}),
|
||||||
|
]);
|
||||||
|
expect(result?.packages.map((p) => p.id)).toEqual(['newborn']);
|
||||||
|
expect(result?.banner).toMatchObject({
|
||||||
|
title: 'Kerstactie',
|
||||||
|
priceText: '€ 99 i.p.v. € 150',
|
||||||
|
});
|
||||||
|
});
|
||||||
|
|
||||||
|
it('slaat ongeldige kaarten over en behoudt de rest', () => {
|
||||||
|
const result = mapOfferings([
|
||||||
|
card({ slug: 'Slecht Id' }),
|
||||||
|
card({ slug: 'a', price: 'op aanvraag' }),
|
||||||
|
card({ slug: 'b', title: ' ' }),
|
||||||
|
card({ slug: 'c', features: [] }),
|
||||||
|
card({ slug: 'd', features: ['ok', ''] }),
|
||||||
|
card({ slug: 'newborn' }),
|
||||||
|
card({ slug: 'newborn', title: 'Dubbel' }),
|
||||||
|
]);
|
||||||
|
expect(result?.packages.map((p) => p.id)).toEqual(['newborn']);
|
||||||
|
expect(result?.packages[0].name).toBe('Newborn');
|
||||||
|
});
|
||||||
|
|
||||||
|
it('verwerpt een antwoord zonder geldig pakket', () => {
|
||||||
|
expect(mapOfferings([])).toBeNull();
|
||||||
|
expect(mapOfferings([card({ price: '' })])).toBeNull();
|
||||||
|
expect(mapOfferings([card({ layout: 'banner' })])).toBeNull();
|
||||||
|
expect(mapOfferings({ items: [] })).toBeNull();
|
||||||
|
expect(mapOfferings(null)).toBeNull();
|
||||||
|
expect(mapOfferings('fout')).toBeNull();
|
||||||
|
});
|
||||||
|
|
||||||
|
it('geeft nooit een pakket met lege of ongeldige prijs terug, wat er ook komt', () => {
|
||||||
|
fc.assert(
|
||||||
|
fc.property(fc.array(fc.jsonValue()), (answer) => {
|
||||||
|
const result = mapOfferings(answer);
|
||||||
|
for (const pkg of result?.packages ?? []) {
|
||||||
|
expect(Number.isInteger(pkg.price)).toBe(true);
|
||||||
|
expect(pkg.price).toBeGreaterThan(0);
|
||||||
|
expect(pkg.features.length).toBeGreaterThan(0);
|
||||||
|
}
|
||||||
|
}),
|
||||||
|
);
|
||||||
|
});
|
||||||
|
});
|
||||||
@@ -0,0 +1,130 @@
|
|||||||
|
// Turns the answer of GET /api/v1/offerings (the CMS) into what the site
|
||||||
|
// shows: the shoot packages (cards) and at most one banner. Pure functions, so
|
||||||
|
// they are tested without a network. The build step (fetchOfferings.ts) uses
|
||||||
|
// them; the site itself never calls the API (prices are in the HTML).
|
||||||
|
//
|
||||||
|
// Rule of the design: a bad answer never breaks the build and never leads to
|
||||||
|
// an empty or wrong price. Anything that is not clearly valid is dropped, and
|
||||||
|
// when no valid card is left the whole answer is rejected (null), so the
|
||||||
|
// caller keeps the last known list (the snapshot).
|
||||||
|
|
||||||
|
export interface OfferingPackage {
|
||||||
|
id: string;
|
||||||
|
name: string;
|
||||||
|
price: number; // whole euros
|
||||||
|
features: string[];
|
||||||
|
priceNote?: string;
|
||||||
|
description?: string;
|
||||||
|
ctaLabel?: string;
|
||||||
|
featured?: boolean;
|
||||||
|
}
|
||||||
|
|
||||||
|
export interface OfferingBanner {
|
||||||
|
title: string;
|
||||||
|
description: string;
|
||||||
|
priceText: string;
|
||||||
|
priceNote?: string;
|
||||||
|
features: string[];
|
||||||
|
ctaLabel?: string;
|
||||||
|
}
|
||||||
|
|
||||||
|
export interface SiteOfferings {
|
||||||
|
packages: OfferingPackage[];
|
||||||
|
banner: OfferingBanner | null;
|
||||||
|
}
|
||||||
|
|
||||||
|
const SLUG = /^[a-z0-9-]+$/;
|
||||||
|
|
||||||
|
// "€ 175", "€ 1.250", "175,-", "€ 175,00" → whole euros. Anything else
|
||||||
|
// ("op aanvraag", "€ 12,50", "€ 0") has no usable price and gives null.
|
||||||
|
export function parsePriceText(text: unknown): number | null {
|
||||||
|
if (typeof text !== 'string') return null;
|
||||||
|
const match = /^\D*?(\d{1,3}(?:\.\d{3})+|\d+)(?:,(?:-|0{1,2}))?\D*$/.exec(
|
||||||
|
text.trim(),
|
||||||
|
);
|
||||||
|
if (!match) return null;
|
||||||
|
const euros = Number(match[1].replace(/\./g, ''));
|
||||||
|
return Number.isInteger(euros) && euros > 0 ? euros : null;
|
||||||
|
}
|
||||||
|
|
||||||
|
const asText = (value: unknown): string | undefined =>
|
||||||
|
typeof value === 'string' && value.trim() !== '' ? value.trim() : undefined;
|
||||||
|
|
||||||
|
function asFeatures(value: unknown): string[] | null {
|
||||||
|
if (!Array.isArray(value)) return null;
|
||||||
|
const features = value.map(asText);
|
||||||
|
return features.length > 0 && features.every((f) => f !== undefined)
|
||||||
|
? (features as string[])
|
||||||
|
: null;
|
||||||
|
}
|
||||||
|
|
||||||
|
interface RawOffering {
|
||||||
|
[key: string]: unknown;
|
||||||
|
}
|
||||||
|
|
||||||
|
const isObject = (value: unknown): value is RawOffering =>
|
||||||
|
typeof value === 'object' && value !== null && !Array.isArray(value);
|
||||||
|
|
||||||
|
function toPackage(raw: RawOffering): OfferingPackage | null {
|
||||||
|
const id = asText(raw.slug);
|
||||||
|
const name = asText(raw.title);
|
||||||
|
const price = parsePriceText(raw.price);
|
||||||
|
const features = asFeatures(raw.features);
|
||||||
|
if (!id || !SLUG.test(id) || !name || price === null || !features) {
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
return {
|
||||||
|
id,
|
||||||
|
name,
|
||||||
|
price,
|
||||||
|
features,
|
||||||
|
priceNote: asText(raw.priceNote),
|
||||||
|
description: asText(raw.description),
|
||||||
|
ctaLabel: asText(raw.ctaLabel),
|
||||||
|
featured: raw.featured === true ? true : undefined,
|
||||||
|
};
|
||||||
|
}
|
||||||
|
|
||||||
|
function toBanner(raw: RawOffering): OfferingBanner | null {
|
||||||
|
const title = asText(raw.title);
|
||||||
|
const priceText = asText(raw.price);
|
||||||
|
const features = asFeatures(raw.features);
|
||||||
|
if (!title || !priceText || !features) return null;
|
||||||
|
return {
|
||||||
|
title,
|
||||||
|
description: asText(raw.description) ?? '',
|
||||||
|
priceText,
|
||||||
|
priceNote: asText(raw.priceNote),
|
||||||
|
features,
|
||||||
|
ctaLabel: asText(raw.ctaLabel),
|
||||||
|
};
|
||||||
|
}
|
||||||
|
|
||||||
|
const orderOf = (raw: RawOffering) =>
|
||||||
|
typeof raw.displayOrder === 'number' ? raw.displayOrder : 0;
|
||||||
|
|
||||||
|
// null: the answer cannot be used (not a list, or no valid card)
|
||||||
|
export function mapOfferings(answer: unknown): SiteOfferings | null {
|
||||||
|
if (!Array.isArray(answer)) return null;
|
||||||
|
const rows = answer
|
||||||
|
.filter(isObject)
|
||||||
|
.map((raw, index) => ({ raw, index }))
|
||||||
|
.sort((a, b) => orderOf(a.raw) - orderOf(b.raw) || a.index - b.index)
|
||||||
|
.map(({ raw }) => raw);
|
||||||
|
|
||||||
|
const seen = new Set<string>();
|
||||||
|
const packages: OfferingPackage[] = [];
|
||||||
|
let banner: OfferingBanner | null = null;
|
||||||
|
for (const raw of rows) {
|
||||||
|
if (raw.layout === 'banner') {
|
||||||
|
// The CMS allows one banner per site; the first usable one wins
|
||||||
|
banner ??= toBanner(raw);
|
||||||
|
continue;
|
||||||
|
}
|
||||||
|
const pkg = toPackage(raw);
|
||||||
|
if (!pkg || seen.has(pkg.id)) continue;
|
||||||
|
seen.add(pkg.id);
|
||||||
|
packages.push(pkg);
|
||||||
|
}
|
||||||
|
return packages.length > 0 ? { packages, banner } : null;
|
||||||
|
}
|
||||||
+1
-1
@@ -6,7 +6,7 @@
|
|||||||
"packageManager": "pnpm@12.11.2",
|
"packageManager": "pnpm@12.11.2",
|
||||||
"scripts": {
|
"scripts": {
|
||||||
"dev": "vite",
|
"dev": "vite",
|
||||||
"build": "tsc && vite build && node config/externalizeInlineScripts.ts",
|
"build": "node config/fetchOfferings.ts && tsc && vite build && node config/externalizeInlineScripts.ts",
|
||||||
"preview": "node config/previewServer.ts",
|
"preview": "node config/previewServer.ts",
|
||||||
"e2e": "vitest run --config vitest.e2e.config.ts",
|
"e2e": "vitest run --config vitest.e2e.config.ts",
|
||||||
"postinstall": "chakra typegen ./src/theme.ts",
|
"postinstall": "chakra typegen ./src/theme.ts",
|
||||||
|
|||||||
@@ -0,0 +1,88 @@
|
|||||||
|
import { Box, chakra, Heading, Text, useRecipe } from '@chakra-ui/react';
|
||||||
|
import { Link } from '@tanstack/react-router';
|
||||||
|
import type { PricingBanner } from '@/content/types';
|
||||||
|
|
||||||
|
type PriceBannerProps = {
|
||||||
|
banner: PricingBanner;
|
||||||
|
};
|
||||||
|
|
||||||
|
// The optional dark band under the price cards (an offering with
|
||||||
|
// layout=banner in the CMS), for an offer or an announcement. It is not a
|
||||||
|
// bookable package: the button only leads to the contact form, without a
|
||||||
|
// chosen package. The price is free text from the CMS ("€ 99 i.p.v. € 150").
|
||||||
|
export default function PriceBanner({ banner }: PriceBannerProps) {
|
||||||
|
const linkButton = useRecipe({ key: 'linkButton' });
|
||||||
|
|
||||||
|
return (
|
||||||
|
<Box
|
||||||
|
as="aside"
|
||||||
|
aria-labelledby="price-banner-title"
|
||||||
|
data-testid="price-banner"
|
||||||
|
mt="gridGap"
|
||||||
|
px="clamp(1.5rem, 4vw, 3.5rem)"
|
||||||
|
py="clamp(2rem, 4vw, 3rem)"
|
||||||
|
bg="ink"
|
||||||
|
color="white"
|
||||||
|
display="grid"
|
||||||
|
gap={{ base: 6, md: 10 }}
|
||||||
|
gridTemplateColumns={{ base: '1fr', md: '1fr auto' }}
|
||||||
|
alignItems="center"
|
||||||
|
>
|
||||||
|
<Box>
|
||||||
|
<Heading
|
||||||
|
as="h3"
|
||||||
|
id="price-banner-title"
|
||||||
|
fontSize="1.5rem"
|
||||||
|
color="white"
|
||||||
|
mb={2}
|
||||||
|
>
|
||||||
|
{banner.title}
|
||||||
|
</Heading>
|
||||||
|
{banner.description && (
|
||||||
|
<Text color="white" opacity={0.85} mb={3}>
|
||||||
|
{banner.description}
|
||||||
|
</Text>
|
||||||
|
)}
|
||||||
|
{banner.features.length > 0 && (
|
||||||
|
<chakra.ul
|
||||||
|
listStyleType="none"
|
||||||
|
display="flex"
|
||||||
|
flexWrap="wrap"
|
||||||
|
columnGap={6}
|
||||||
|
rowGap={1}
|
||||||
|
fontSize="sm"
|
||||||
|
opacity={0.85}
|
||||||
|
>
|
||||||
|
{banner.features.map((feature) => (
|
||||||
|
<chakra.li key={feature}>{feature}</chakra.li>
|
||||||
|
))}
|
||||||
|
</chakra.ul>
|
||||||
|
)}
|
||||||
|
</Box>
|
||||||
|
<Box textAlign={{ base: 'start', md: 'center' }}>
|
||||||
|
<Text
|
||||||
|
fontFamily="heading"
|
||||||
|
fontSize="1.75rem"
|
||||||
|
lineHeight="1.1"
|
||||||
|
color="white"
|
||||||
|
>
|
||||||
|
{banner.priceText}
|
||||||
|
</Text>
|
||||||
|
{banner.priceNote && (
|
||||||
|
<Text fontSize="sm" opacity={0.85} mb={4}>
|
||||||
|
{banner.priceNote}
|
||||||
|
</Text>
|
||||||
|
)}
|
||||||
|
<Box
|
||||||
|
asChild
|
||||||
|
css={linkButton({ variant: 'light', size: 'fit' })}
|
||||||
|
mt={banner.priceNote ? 0 : 4}
|
||||||
|
>
|
||||||
|
<Link to="/" hash="contact" data-testid="price-banner-cta">
|
||||||
|
{banner.ctaLabel ?? 'Neem contact op'}
|
||||||
|
</Link>
|
||||||
|
</Box>
|
||||||
|
</Box>
|
||||||
|
</Box>
|
||||||
|
);
|
||||||
|
}
|
||||||
@@ -32,6 +32,44 @@ describe('Pricing', () => {
|
|||||||
expect(await axeResults(container)).toHaveNoViolations();
|
expect(await axeResults(container)).toHaveNoViolations();
|
||||||
});
|
});
|
||||||
|
|
||||||
|
it('shows an optional banner under the cards, not as a package', async () => {
|
||||||
|
const banner = {
|
||||||
|
title: 'Kerstactie',
|
||||||
|
description: 'Alleen in december',
|
||||||
|
priceText: '€ 99 i.p.v. € 150',
|
||||||
|
priceNote: 'tot 31 december',
|
||||||
|
features: ['30 minuten', '10 foto’s'],
|
||||||
|
ctaLabel: 'Boek de actie',
|
||||||
|
};
|
||||||
|
const { container } = await renderWithProviders(
|
||||||
|
<Pricing content={content} packages={packages} banner={banner} />,
|
||||||
|
);
|
||||||
|
const section = screen.getByRole('region', { name: 'Prijzen' });
|
||||||
|
const shown = within(section).getByTestId('price-banner');
|
||||||
|
expect(
|
||||||
|
within(shown).getByText('€ 99 i.p.v. € 150'),
|
||||||
|
).toBeInTheDocument();
|
||||||
|
expect(
|
||||||
|
within(shown).getByRole('link', { name: 'Boek de actie' }),
|
||||||
|
).toHaveAttribute('href', '/#contact');
|
||||||
|
// The cards are still the three packages: no card and no booking
|
||||||
|
// link with a package for the banner
|
||||||
|
expect(
|
||||||
|
within(section).queryByTestId('price-card-kerstactie'),
|
||||||
|
).not.toBeInTheDocument();
|
||||||
|
expect(
|
||||||
|
within(section).getAllByTestId(/^price-card-[a-z]+$/),
|
||||||
|
).toHaveLength(3);
|
||||||
|
expect(await axeResults(container)).toHaveNoViolations();
|
||||||
|
});
|
||||||
|
|
||||||
|
it('shows no banner without one', async () => {
|
||||||
|
await renderWithProviders(
|
||||||
|
<Pricing content={content} packages={packages} banner={null} />,
|
||||||
|
);
|
||||||
|
expect(screen.queryByTestId('price-banner')).not.toBeInTheDocument();
|
||||||
|
});
|
||||||
|
|
||||||
it('can be linked to as /#prijzen', async () => {
|
it('can be linked to as /#prijzen', async () => {
|
||||||
await renderWithProviders(
|
await renderWithProviders(
|
||||||
<Pricing content={content} packages={packages} />,
|
<Pricing content={content} packages={packages} />,
|
||||||
|
|||||||
@@ -3,8 +3,13 @@ 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';
|
||||||
import SectionHeading from '@/components/SectionHeading/SectionHeading';
|
import SectionHeading from '@/components/SectionHeading/SectionHeading';
|
||||||
import type { HomeContent, PricingPackage } from '@/content/types';
|
import type {
|
||||||
|
HomeContent,
|
||||||
|
PricingBanner,
|
||||||
|
PricingPackage,
|
||||||
|
} from '@/content/types';
|
||||||
import { visiblePackages } from '@/lib/visiblePackages';
|
import { visiblePackages } from '@/lib/visiblePackages';
|
||||||
|
import PriceBanner from './PriceBanner';
|
||||||
import PriceCard from './PriceCard';
|
import PriceCard from './PriceCard';
|
||||||
|
|
||||||
const TITLE_ID = 'pricing-title';
|
const TITLE_ID = 'pricing-title';
|
||||||
@@ -22,12 +27,14 @@ const decorationPositions = [
|
|||||||
type PricingProps = {
|
type PricingProps = {
|
||||||
content: HomeContent['pricing'];
|
content: HomeContent['pricing'];
|
||||||
packages: PricingPackage[];
|
packages: PricingPackage[];
|
||||||
|
// Optional band under the cards; not a package
|
||||||
|
banner?: PricingBanner | 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, three from `lg`. Without a valid package the section
|
||||||
// is left out entirely.
|
// is left out entirely.
|
||||||
export default function Pricing({ content, packages }: PricingProps) {
|
export default function Pricing({ content, packages, banner }: PricingProps) {
|
||||||
const shown = visiblePackages(packages);
|
const shown = visiblePackages(packages);
|
||||||
if (shown.length === 0) return null;
|
if (shown.length === 0) return null;
|
||||||
|
|
||||||
@@ -72,6 +79,11 @@ export default function Pricing({ content, packages }: PricingProps) {
|
|||||||
</Reveal>
|
</Reveal>
|
||||||
))}
|
))}
|
||||||
</Grid>
|
</Grid>
|
||||||
|
{banner && (
|
||||||
|
<Reveal>
|
||||||
|
<PriceBanner banner={banner} />
|
||||||
|
</Reveal>
|
||||||
|
)}
|
||||||
</Box>
|
</Box>
|
||||||
</PageSection>
|
</PageSection>
|
||||||
);
|
);
|
||||||
|
|||||||
@@ -0,0 +1,35 @@
|
|||||||
|
{
|
||||||
|
"packages": [
|
||||||
|
{
|
||||||
|
"id": "zwangerschap",
|
||||||
|
"name": "Zwangerschap",
|
||||||
|
"price": 175,
|
||||||
|
"features": [
|
||||||
|
"1 uur fotografie",
|
||||||
|
"Minstens 30 zorgvuldig nabewerkte foto's",
|
||||||
|
"Persoonlijke online fotogalerij"
|
||||||
|
]
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"id": "newborn",
|
||||||
|
"name": "Newborn",
|
||||||
|
"price": 185,
|
||||||
|
"features": [
|
||||||
|
"1-2 uur fotografie",
|
||||||
|
"Minstens 40 zorgvuldig nabewerkte foto's",
|
||||||
|
"Persoonlijke online fotogalerij"
|
||||||
|
]
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"id": "gezin",
|
||||||
|
"name": "Gezin",
|
||||||
|
"price": 175,
|
||||||
|
"features": [
|
||||||
|
"1 uur fotografie",
|
||||||
|
"Minstens 30 zorgvuldig nabewerkte foto's",
|
||||||
|
"Persoonlijke online fotogalerij"
|
||||||
|
]
|
||||||
|
}
|
||||||
|
],
|
||||||
|
"banner": null
|
||||||
|
}
|
||||||
+27
-35
@@ -1,38 +1,30 @@
|
|||||||
import type { PricingPackage } from './types';
|
import type { PricingBanner, PricingPackage } from './types';
|
||||||
|
import snapshot from './offerings.snapshot.json';
|
||||||
|
|
||||||
// The shoot packages until the CMS API exists (live site, October 2026), in
|
interface Offerings {
|
||||||
// display order. Andrea uses the small business scheme (KOR): no VAT.
|
packages: PricingPackage[];
|
||||||
const packages: PricingPackage[] = [
|
banner: PricingBanner | null;
|
||||||
{
|
}
|
||||||
id: 'zwangerschap',
|
|
||||||
name: 'Zwangerschap',
|
// The shoot packages and the optional banner. config/fetchOfferings.ts writes
|
||||||
price: 175,
|
// offerings.generated.json before every build with what the CMS says; without
|
||||||
features: [
|
// it (tests, a build without CMS address, a CMS that is down) the committed
|
||||||
'1 uur fotografie',
|
// snapshot is used. Andrea uses the small business scheme (KOR): no VAT.
|
||||||
"Minstens 30 zorgvuldig nabewerkte foto's",
|
// Tests always use the snapshot, so they do not depend on a build.
|
||||||
'Persoonlijke online fotogalerij',
|
const generated =
|
||||||
],
|
import.meta.env.MODE === 'test'
|
||||||
},
|
? {}
|
||||||
{
|
: import.meta.glob<Offerings>('./offerings.generated.json', {
|
||||||
id: 'newborn',
|
eager: true,
|
||||||
name: 'Newborn',
|
import: 'default',
|
||||||
price: 185,
|
});
|
||||||
features: [
|
|
||||||
'1-2 uur fotografie',
|
const offerings: Offerings =
|
||||||
"Minstens 40 zorgvuldig nabewerkte foto's",
|
generated['./offerings.generated.json'] ?? (snapshot as Offerings);
|
||||||
'Persoonlijke online fotogalerij',
|
|
||||||
],
|
// In display order
|
||||||
},
|
const packages: PricingPackage[] = offerings.packages;
|
||||||
{
|
|
||||||
id: 'gezin',
|
export const banner: PricingBanner | null = offerings.banner;
|
||||||
name: 'Gezin',
|
|
||||||
price: 175,
|
|
||||||
features: [
|
|
||||||
'1 uur fotografie',
|
|
||||||
"Minstens 30 zorgvuldig nabewerkte foto's",
|
|
||||||
'Persoonlijke online fotogalerij',
|
|
||||||
],
|
|
||||||
},
|
|
||||||
];
|
|
||||||
|
|
||||||
export default packages;
|
export default packages;
|
||||||
|
|||||||
@@ -94,6 +94,23 @@ export interface PricingPackage {
|
|||||||
name: string;
|
name: string;
|
||||||
price: number; // whole euros
|
price: number; // whole euros
|
||||||
features: string[];
|
features: string[];
|
||||||
|
// From the CMS offering; all optional
|
||||||
|
priceNote?: string;
|
||||||
|
description?: string;
|
||||||
|
ctaLabel?: string;
|
||||||
|
featured?: boolean;
|
||||||
|
}
|
||||||
|
|
||||||
|
// The one optional banner under the price cards (an offering with
|
||||||
|
// layout=banner in the CMS). It is not a bookable package: it is not in the
|
||||||
|
// form's choices and not in the package count. The price is free text.
|
||||||
|
export interface PricingBanner {
|
||||||
|
title: string;
|
||||||
|
description: string;
|
||||||
|
priceText: string;
|
||||||
|
priceNote?: string;
|
||||||
|
features: string[];
|
||||||
|
ctaLabel?: 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
|
||||||
|
|||||||
@@ -9,7 +9,7 @@ import IntroGallery from '../components/home/IntroGallery/IntroGallery';
|
|||||||
import heroContent from '../content/heroContent';
|
import heroContent from '../content/heroContent';
|
||||||
import homeContent from '../content/homeContent';
|
import homeContent from '../content/homeContent';
|
||||||
import instagramContent from '../content/instagramContent';
|
import instagramContent from '../content/instagramContent';
|
||||||
import packages from '../content/packages';
|
import packages, { banner } from '../content/packages';
|
||||||
import testimonials from '../content/testimonials';
|
import testimonials from '../content/testimonials';
|
||||||
import siteContent from '../content/siteContent';
|
import siteContent from '../content/siteContent';
|
||||||
import { visibleSocials } from '../lib/visibleSocials';
|
import { visibleSocials } from '../lib/visibleSocials';
|
||||||
@@ -42,7 +42,11 @@ function Index() {
|
|||||||
<Hero content={heroContent} socials={siteContent.socials} />
|
<Hero content={heroContent} socials={siteContent.socials} />
|
||||||
<IntroGallery content={homeContent.intro} />
|
<IntroGallery content={homeContent.intro} />
|
||||||
<AboutBlock content={homeContent.about} />
|
<AboutBlock content={homeContent.about} />
|
||||||
<Pricing content={homeContent.pricing} packages={packages} />
|
<Pricing
|
||||||
|
content={homeContent.pricing}
|
||||||
|
packages={packages}
|
||||||
|
banner={banner}
|
||||||
|
/>
|
||||||
<Testimonials
|
<Testimonials
|
||||||
content={homeContent.testimonials}
|
content={homeContent.testimonials}
|
||||||
testimonials={testimonials}
|
testimonials={testimonials}
|
||||||
|
|||||||
Reference in New Issue
Block a user