From 9ac852f2a2a2a4f68114232c0bab146680934fa7 Mon Sep 17 00:00:00 2001 From: Sluijsens Date: Sat, 14 Nov 2026 12:19:40 +0100 Subject: [PATCH] Pakketten: laatste rij gecentreerd op desktop, tweede (smalle) OfferingBanner boven de pakketten (?position=top) Co-Authored-By: Claude Sonnet 5.5 --- .../__tests__/PackagesSection.test.tsx | 33 ++++++++++++++++++- .../landing/components/OfferingTopBanner.tsx | 29 ++++++++++++++++ .../landing/components/PackageList.tsx | 7 ++-- .../landing/components/PackagesSection.tsx | 4 +++ .../landing/hooks/useOfferingBannerQuery.ts | 24 +++++++++----- 5 files changed, 85 insertions(+), 12 deletions(-) create mode 100644 src/features/landing/components/OfferingTopBanner.tsx diff --git a/src/features/landing/__tests__/PackagesSection.test.tsx b/src/features/landing/__tests__/PackagesSection.test.tsx index 4287b2d..8421017 100644 --- a/src/features/landing/__tests__/PackagesSection.test.tsx +++ b/src/features/landing/__tests__/PackagesSection.test.tsx @@ -29,8 +29,19 @@ function renderSection() { const BANNER_PATH = '/api/v1/offerings/banner'; /** Routes the optional CMS banner request (204 = none, or the given banner) apart from the packages call. */ -function stubFetch(offerings: () => Promise, banner: unknown = null) { +function stubFetch( + offerings: () => Promise, + banner: unknown = null, + topBanner: unknown = null, +) { const fn = vi.fn((url: string) => { + if (String(url).endsWith(`${BANNER_PATH}?position=top`)) { + return Promise.resolve( + topBanner === null + ? new Response(null, { status: 204 }) + : new Response(JSON.stringify(topBanner), { status: 200 }), + ); + } if (String(url).endsWith(BANNER_PATH)) { return Promise.resolve( banner === null @@ -168,6 +179,26 @@ describe('PackagesSection', () => { ); }); + it('shows a slim top banner next to the bottom banner when both are active', async () => { + stubFetch( + () => Promise.resolve(new Response(JSON.stringify(packages), { status: 200 })), + { title: 'Onder', text: 'Grote banner.', linkLabel: null, linkUrl: null }, + { + title: '', + text: 'Nu 10% korting.', + linkLabel: 'Meer', + linkUrl: 'https://example.com/top', + }, + ); + renderSection(); + expect(await screen.findByTestId('offering-top-banner')).toHaveTextContent('Nu 10% korting.'); + expect(screen.getByTestId('offering-top-banner-cta')).toHaveAttribute( + 'href', + 'https://example.com/top', + ); + expect(await screen.findByTestId('offering-banner')).toHaveTextContent('Onder'); + }); + it('renders no banner without link when the CMS has none', async () => { mockApi(packages); renderSection(); diff --git a/src/features/landing/components/OfferingTopBanner.tsx b/src/features/landing/components/OfferingTopBanner.tsx new file mode 100644 index 0000000..4d7c6c3 --- /dev/null +++ b/src/features/landing/components/OfferingTopBanner.tsx @@ -0,0 +1,29 @@ +import type { OfferingBannerData } from '../hooks/useOfferingBannerQuery'; + +/** + * Slim one-line bar above the package cards, filled from the CMS OfferingBanner with position + * `top` (live, optional). May be shown together with the big banner under the cards. + */ +export function OfferingTopBanner({ banner }: { banner: OfferingBannerData }) { + const hasLink = banner.linkLabel !== null && banner.linkUrl !== null; + return ( +
+

+ {banner.title ? {banner.title} : null} + {banner.text} +

+ {hasLink ? ( + + {banner.linkLabel} + + ) : null} +
+ ); +} diff --git a/src/features/landing/components/PackageList.tsx b/src/features/landing/components/PackageList.tsx index 7b2f987..36356dd 100644 --- a/src/features/landing/components/PackageList.tsx +++ b/src/features/landing/components/PackageList.tsx @@ -37,10 +37,13 @@ export function PackageList({ packages, loading = false, resetKey }: PackageList aria-label="Pakketten" tabIndex={0} data-testid="packages-grid" - className="-mx-6 flex snap-x snap-mandatory items-stretch gap-4 overflow-x-auto px-6 pb-2 sm:mx-0 sm:grid sm:snap-none sm:grid-cols-2 sm:overflow-visible sm:px-0 sm:pb-0 min-[1001px]:grid-cols-3" + className="-mx-6 flex snap-x snap-mandatory items-stretch gap-4 overflow-x-auto px-6 pb-2 sm:mx-0 sm:flex-wrap sm:justify-center sm:snap-none sm:overflow-visible sm:px-0 sm:pb-0" > {items.map((item, index) => ( -
+
{item}
))} diff --git a/src/features/landing/components/PackagesSection.tsx b/src/features/landing/components/PackagesSection.tsx index 98ca448..0456786 100644 --- a/src/features/landing/components/PackagesSection.tsx +++ b/src/features/landing/components/PackagesSection.tsx @@ -4,6 +4,7 @@ import { usePackageFilter } from '../../../shared/packages/usePackageFilter'; import { FilterChips } from './FilterChips'; import { useOfferingBannerQuery } from '../hooks/useOfferingBannerQuery'; import { OfferingBanner } from './OfferingBanner'; +import { OfferingTopBanner } from './OfferingTopBanner'; import { PackageBanner } from './PackageBanner'; import { PackageList } from './PackageList'; @@ -20,6 +21,7 @@ export function PackagesSection() { const filter = usePackageFilter(data ?? [], packagesSettings); const loaded = !isLoading && !isError && data !== undefined; const { data: offeringBanner } = useOfferingBannerQuery(); + const { data: topBanner } = useOfferingBannerQuery('top'); // The CMS OfferingBanner (live) takes precedence over the legacy per-site package banner. const banner = offeringBanner ? ( @@ -43,6 +45,8 @@ export function PackagesSection() {

+ {topBanner ? : null} + {isError ? (

Pakketten konden niet worden geladen.

diff --git a/src/features/landing/hooks/useOfferingBannerQuery.ts b/src/features/landing/hooks/useOfferingBannerQuery.ts index a1041de..c41e35e 100644 --- a/src/features/landing/hooks/useOfferingBannerQuery.ts +++ b/src/features/landing/hooks/useOfferingBannerQuery.ts @@ -8,23 +8,29 @@ export interface OfferingBannerData { linkUrl: string | null; } -function bannerEndpoint() { - return `${import.meta.env.VITE_API_BASE_URL ?? ''}/api/v1/offerings/banner`; +/** Two places: `bottom` (default, big banner under the cards) and `top` (slim one-line bar above them). */ +export type OfferingBannerPosition = 'top' | 'bottom'; + +function bannerEndpoint(position: OfferingBannerPosition) { + const base = `${import.meta.env.VITE_API_BASE_URL ?? ''}/api/v1/offerings/banner`; + // No parameter means `bottom` (backwards compatible with the first API version). + return position === 'top' ? `${base}?position=top` : base; } /** 204 (no active banner) and any failure resolve to `null`: the banner is optional, never an error. */ -async function fetchBanner(): Promise { +async function fetchBanner(position: OfferingBannerPosition): Promise { try { - const response = await fetch(bannerEndpoint()); + const response = await fetch(bannerEndpoint(position)); if (response.status === 204 || !response.ok) { return null; } const data = (await response.json()) as Partial | null; - if (!data || typeof data.title !== 'string' || typeof data.text !== 'string') { + // A top banner may have an empty title; text is always required. + if (!data || typeof data.text !== 'string' || data.text === '') { return null; } return { - title: data.title, + title: typeof data.title === 'string' ? data.title : '', text: data.text, linkLabel: data.linkLabel ?? null, linkUrl: data.linkUrl ?? null, @@ -34,10 +40,10 @@ async function fetchBanner(): Promise { } } -export function useOfferingBannerQuery() { +export function useOfferingBannerQuery(position: OfferingBannerPosition = 'bottom') { return useQuery({ - queryKey: ['offering-banner'], - queryFn: fetchBanner, + queryKey: ['offering-banner', position], + queryFn: () => fetchBanner(position), // Short staleness so a change in the CMS shows up quickly (the API itself caches for 60 s). staleTime: 60_000, });