Updates the packages and the banner live in the browser

The build still bakes the current packages and the active banner into the HTML.
After hydration the page asks /api/v1/offerings and /api/v1/offerings/banner
once and replaces what differs; errors and time-outs keep what was baked, and
a 204 from the banner route hides the banner. The banner is now the
OfferingBanner contract (title, text, optional link) instead of layout=banner.

Co-Authored-By: Claude Sonnet 5.5 <noreply@anthropic.com>
This commit is contained in:
2026-11-12 11:19:50 +01:00
co-authored by Claude Sonnet 5.5
parent f9180f231f
commit 12319bb841
22 changed files with 584 additions and 180 deletions
+26 -49
View File
@@ -1,17 +1,15 @@
import { Box, chakra, Heading, Text, useRecipe } from '@chakra-ui/react';
import { Link } from '@tanstack/react-router';
import { Box, Heading, Text, useRecipe } from '@chakra-ui/react';
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").
// Only the title is required; whatever is empty is left out. Without a button
// label the button says "Neem contact op".
// The optional dark band under the price cards: an announcement from the CMS
// (an offer, a notice). It is not a bookable package and cannot be dismissed.
// Only the title is required; the text and the button are left out when empty.
// The link is a https address or a path on this site (the CMS guarantees
// that, mapBanner checks it again), so a plain anchor is enough.
export default function PriceBanner({ banner }: PriceBannerProps) {
const linkButton = useRecipe({ key: 'linkButton' });
@@ -27,7 +25,10 @@ export default function PriceBanner({ banner }: PriceBannerProps) {
color="white"
display="grid"
gap={{ base: 6, md: 10 }}
gridTemplateColumns={{ base: '1fr', md: '1fr auto' }}
gridTemplateColumns={{
base: '1fr',
md: banner.link ? '1fr auto' : '1fr',
}}
alignItems="center"
>
<Box>
@@ -36,57 +37,33 @@ export default function PriceBanner({ banner }: PriceBannerProps) {
id="price-banner-title"
fontSize="1.5rem"
color="white"
mb={2}
mb={banner.text ? 2 : 0}
>
{banner.title}
</Heading>
{banner.description && (
<Text color="white" opacity={0.85} mb={3}>
{banner.description}
{banner.text && (
<Text color="white" opacity={0.85}>
{banner.text}
</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' }}>
{banner.priceText && (
<Text
fontFamily="heading"
fontSize="1.75rem"
lineHeight="1.1"
color="white"
>
{banner.priceText}
</Text>
)}
{banner.priceNote && (
<Text fontSize="sm" opacity={0.85}>
{banner.priceNote}
</Text>
)}
{banner.link && (
<Box
asChild
css={linkButton({ variant: 'light', size: 'fit' })}
mt={banner.priceText || banner.priceNote ? 4 : 0}
justifySelf={{ base: 'start', md: 'center' }}
>
<Link to="/" hash="contact" data-testid="price-banner-cta">
{banner.ctaLabel ?? 'Neem contact op'}
</Link>
<a
href={banner.link.url}
data-testid="price-banner-cta"
{...(banner.link.url.startsWith('https://')
? { rel: 'noopener' }
: {})}
>
{banner.link.label}
</a>
</Box>
</Box>
)}
</Box>
);
}
@@ -35,11 +35,8 @@ describe('Pricing', () => {
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',
text: 'Alleen in december',
link: { label: 'Boek de actie', url: '/contact' },
};
const { container } = await renderWithProviders(
<Pricing content={content} packages={packages} banner={banner} />,
@@ -47,13 +44,12 @@ describe('Pricing', () => {
const section = screen.getByRole('region', { name: 'Prijzen' });
const shown = within(section).getByTestId('price-banner');
expect(
within(shown).getByText('€ 99 i.p.v. € 150'),
within(shown).getByText('Alleen in december'),
).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
).toHaveAttribute('href', '/contact');
// The cards are still the three packages: no card for the banner
expect(
within(section).queryByTestId('price-card-kerstactie'),
).not.toBeInTheDocument();
@@ -63,24 +59,38 @@ describe('Pricing', () => {
expect(await axeResults(container)).toHaveNoViolations();
});
it('hides every empty field of the banner', async () => {
it('marks an external link and hides every empty field', async () => {
const { container } = await renderWithProviders(
<Pricing
content={content}
packages={packages}
banner={{ title: 'Past er niets bij?', features: [] }}
banner={{
title: 'Nieuws',
link: { label: 'Lees meer', url: 'https://example.nl/x' },
}}
/>,
);
const shown = screen.getByTestId('price-banner');
expect(shown.querySelectorAll('p')).toHaveLength(0);
expect(
within(shown).getByRole('link', { name: 'Lees meer' }),
).toHaveAttribute('rel', 'noopener');
expect(await axeResults(container)).toHaveNoViolations();
});
it('shows only the title without text and link', async () => {
const { container } = await renderWithProviders(
<Pricing
content={content}
packages={packages}
banner={{ title: 'Past er niets bij?' }}
/>,
);
const shown = screen.getByTestId('price-banner');
expect(
within(shown).getByRole('heading', { level: 3 }),
).toHaveTextContent('Past er niets bij?');
expect(shown.querySelectorAll('ul, li')).toHaveLength(0);
// Only the heading and the button have text
expect(shown.querySelectorAll('p')).toHaveLength(0);
expect(
within(shown).getByRole('link', { name: 'Neem contact op' }),
).toBeInTheDocument();
expect(within(shown).queryByRole('link')).not.toBeInTheDocument();
expect(await axeResults(container)).toHaveNoViolations();
});