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:
@@ -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();
|
||||
});
|
||||
|
||||
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 () => {
|
||||
await renderWithProviders(
|
||||
<Pricing content={content} packages={packages} />,
|
||||
|
||||
@@ -3,8 +3,13 @@ import DeferredImage from '@/components/DeferredImage/DeferredImage';
|
||||
import PageSection from '@/components/PageSection/PageSection';
|
||||
import Reveal from '@/components/Reveal/Reveal';
|
||||
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 PriceBanner from './PriceBanner';
|
||||
import PriceCard from './PriceCard';
|
||||
|
||||
const TITLE_ID = 'pricing-title';
|
||||
@@ -22,12 +27,14 @@ const decorationPositions = [
|
||||
type PricingProps = {
|
||||
content: HomeContent['pricing'];
|
||||
packages: PricingPackage[];
|
||||
// Optional band under the cards; not a package
|
||||
banner?: PricingBanner | null;
|
||||
};
|
||||
|
||||
// "Prijzen": the shoot packages as cards (design .pricing). One column on
|
||||
// phones and tablets, three from `lg`. Without a valid package the section
|
||||
// is left out entirely.
|
||||
export default function Pricing({ content, packages }: PricingProps) {
|
||||
export default function Pricing({ content, packages, banner }: PricingProps) {
|
||||
const shown = visiblePackages(packages);
|
||||
if (shown.length === 0) return null;
|
||||
|
||||
@@ -72,6 +79,11 @@ export default function Pricing({ content, packages }: PricingProps) {
|
||||
</Reveal>
|
||||
))}
|
||||
</Grid>
|
||||
{banner && (
|
||||
<Reveal>
|
||||
<PriceBanner banner={banner} />
|
||||
</Reveal>
|
||||
)}
|
||||
</Box>
|
||||
</PageSection>
|
||||
);
|
||||
|
||||
Reference in New Issue
Block a user