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>
|
||||
);
|
||||
|
||||
@@ -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
|
||||
// display order. Andrea uses the small business scheme (KOR): no VAT.
|
||||
const packages: PricingPackage[] = [
|
||||
{
|
||||
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',
|
||||
],
|
||||
},
|
||||
];
|
||||
interface Offerings {
|
||||
packages: PricingPackage[];
|
||||
banner: PricingBanner | null;
|
||||
}
|
||||
|
||||
// The shoot packages and the optional banner. config/fetchOfferings.ts writes
|
||||
// offerings.generated.json before every build with what the CMS says; without
|
||||
// it (tests, a build without CMS address, a CMS that is down) the committed
|
||||
// snapshot is used. Andrea uses the small business scheme (KOR): no VAT.
|
||||
// Tests always use the snapshot, so they do not depend on a build.
|
||||
const generated =
|
||||
import.meta.env.MODE === 'test'
|
||||
? {}
|
||||
: import.meta.glob<Offerings>('./offerings.generated.json', {
|
||||
eager: true,
|
||||
import: 'default',
|
||||
});
|
||||
|
||||
const offerings: Offerings =
|
||||
generated['./offerings.generated.json'] ?? (snapshot as Offerings);
|
||||
|
||||
// In display order
|
||||
const packages: PricingPackage[] = offerings.packages;
|
||||
|
||||
export const banner: PricingBanner | null = offerings.banner;
|
||||
|
||||
export default packages;
|
||||
|
||||
@@ -94,6 +94,23 @@ export interface PricingPackage {
|
||||
name: string;
|
||||
price: number; // whole euros
|
||||
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
|
||||
|
||||
@@ -9,7 +9,7 @@ import IntroGallery from '../components/home/IntroGallery/IntroGallery';
|
||||
import heroContent from '../content/heroContent';
|
||||
import homeContent from '../content/homeContent';
|
||||
import instagramContent from '../content/instagramContent';
|
||||
import packages from '../content/packages';
|
||||
import packages, { banner } from '../content/packages';
|
||||
import testimonials from '../content/testimonials';
|
||||
import siteContent from '../content/siteContent';
|
||||
import { visibleSocials } from '../lib/visibleSocials';
|
||||
@@ -42,7 +42,11 @@ function Index() {
|
||||
<Hero content={heroContent} socials={siteContent.socials} />
|
||||
<IntroGallery content={homeContent.intro} />
|
||||
<AboutBlock content={homeContent.about} />
|
||||
<Pricing content={homeContent.pricing} packages={packages} />
|
||||
<Pricing
|
||||
content={homeContent.pricing}
|
||||
packages={packages}
|
||||
banner={banner}
|
||||
/>
|
||||
<Testimonials
|
||||
content={homeContent.testimonials}
|
||||
testimonials={testimonials}
|
||||
|
||||
Reference in New Issue
Block a user