From 9661b64635afa86f2e1d572b2a8cf6874beeebd1 Mon Sep 17 00:00:00 2001 From: Sluijsens Date: Tue, 10 Nov 2026 10:34:09 +0100 Subject: [PATCH] Pakketblok: elk aantal pakketten, filterchips, swipe-rij op mobiel en optionele banner Pure logica (splitsen, chips, filter, labels), useSwipeRow en usePackageFilter, ContactPreselect voor het formulier, kaarten in stijl B en tests. Co-Authored-By: Claude Sonnet 5.5 --- .../redesign-modern-timetravel/aidlc-state.md | 2 +- .../redesign-modern-timetravel/audit.md | 60 +++ .../packages-block/code/summary.md | 27 ++ .../functional-design/business-logic-model.md | 44 +++ .../functional-design/business-rules.md | 38 ++ .../functional-design/domain-entities.md | 43 +++ .../functional-design/frontend-components.md | 65 ++++ .../packages-block-code-generation-plan.md | 35 ++ .../plans/packages-block-fd-questions.md | 11 + .../packages-block-functional-design-plan.md | 9 + src/components/layout/RootLayout.tsx | 29 +- .../__tests__/PackagesSection.test.tsx | 359 +++++++++++++++--- .../landing/components/FilterChips.tsx | 33 ++ .../landing/components/PackageBanner.tsx | 53 +++ .../landing/components/PackageCard.tsx | 62 +-- .../components/PackageCardSkeleton.tsx | 25 +- .../landing/components/PackageList.tsx | 57 +++ .../landing/components/PackagesSection.tsx | 98 +++-- src/features/landing/components/SwipeDots.tsx | 34 ++ src/features/landing/data/content.ts | 28 ++ src/index.css | 2 +- .../contact/ContactPreselectProvider.tsx | 20 + src/shared/contact/contactPreselectContext.ts | 18 + src/shared/contact/useContactPreselect.ts | 6 + .../packages/__tests__/packageLogic.test.ts | 125 ++++++ src/shared/packages/packageLogic.ts | 92 +++++ src/shared/packages/usePackageFilter.ts | 32 ++ src/shared/packages/useSwipeRow.ts | 83 ++++ 28 files changed, 1353 insertions(+), 137 deletions(-) create mode 100644 aidlc-docs/features/redesign-modern-timetravel/construction/packages-block/code/summary.md create mode 100644 aidlc-docs/features/redesign-modern-timetravel/construction/packages-block/functional-design/business-logic-model.md create mode 100644 aidlc-docs/features/redesign-modern-timetravel/construction/packages-block/functional-design/business-rules.md create mode 100644 aidlc-docs/features/redesign-modern-timetravel/construction/packages-block/functional-design/domain-entities.md create mode 100644 aidlc-docs/features/redesign-modern-timetravel/construction/packages-block/functional-design/frontend-components.md create mode 100644 aidlc-docs/features/redesign-modern-timetravel/construction/plans/packages-block-code-generation-plan.md create mode 100644 aidlc-docs/features/redesign-modern-timetravel/construction/plans/packages-block-fd-questions.md create mode 100644 aidlc-docs/features/redesign-modern-timetravel/construction/plans/packages-block-functional-design-plan.md create mode 100644 src/features/landing/components/FilterChips.tsx create mode 100644 src/features/landing/components/PackageBanner.tsx create mode 100644 src/features/landing/components/PackageList.tsx create mode 100644 src/features/landing/components/SwipeDots.tsx create mode 100644 src/shared/contact/ContactPreselectProvider.tsx create mode 100644 src/shared/contact/contactPreselectContext.ts create mode 100644 src/shared/contact/useContactPreselect.ts create mode 100644 src/shared/packages/__tests__/packageLogic.test.ts create mode 100644 src/shared/packages/packageLogic.ts create mode 100644 src/shared/packages/usePackageFilter.ts create mode 100644 src/shared/packages/useSwipeRow.ts diff --git a/aidlc-docs/features/redesign-modern-timetravel/aidlc-state.md b/aidlc-docs/features/redesign-modern-timetravel/aidlc-state.md index c7b17a4..ce2aa21 100644 --- a/aidlc-docs/features/redesign-modern-timetravel/aidlc-state.md +++ b/aidlc-docs/features/redesign-modern-timetravel/aidlc-state.md @@ -5,7 +5,7 @@ - **Feature Slug**: redesign-modern-timetravel - **Project Type**: Brownfield - **Start Date**: 2026-11-09T13:00:00Z -- **Current Stage**: CONSTRUCTION - U2 b-modern-sections Code Generation (in progress) +- **Current Stage**: CONSTRUCTION - U3 packages-block Code Generation plan (awaiting approval) - **Branch**: feature/redesign-modern-timetravel ## Workspace State diff --git a/aidlc-docs/features/redesign-modern-timetravel/audit.md b/aidlc-docs/features/redesign-modern-timetravel/audit.md index 725e0f9..314761c 100644 --- a/aidlc-docs/features/redesign-modern-timetravel/audit.md +++ b/aidlc-docs/features/redesign-modern-timetravel/audit.md @@ -586,3 +586,63 @@ **Context**: CMS phase 2 unblocked pending the merge; U2 Code Generation starts. --- + +## U2 Code Generation Complete + +**Timestamp**: 2026-11-10T11:00:00Z + +**User Input**: "Approve plan." + +**AI Response**: "Executed all 9 steps of b-modern-sections-code-generation-plan.md. Tests 10 files/56 tests before, 13 files/122 tests after, all passed; lint 0 errors (2 pre-existing warnings); build OK, Sora/Instrument Sans removed from dist. Code commit on feature/redesign-modern-timetravel, no push. Deviations flagged in construction/b-modern-sections/code/summary.md (display headline from the design, panel filler text, no browser screenshots possible)." + +**Context**: Code Generation U2 complete; awaiting the user's approval before U3. + +--- + +## Correction: ASF Branch Merge NOT Authorized + +**Timestamp**: 2026-11-10T11:30:00Z + +**User Input**: "(cross-session message from CMS & API relaying Bryan's correction: feature/identity-email-notifications may NOT go to master yet; Bryan wants to test first; a merge follows only after his explicit go; a merge on Bryan's behalf is only passed on if he says so himself)" + +**AI Response**: "Earlier today the AI read the user's remark 'ik denk dat de cms sessie ook wel kan mergen ...' as authorization to merge and relayed it to AndreaSlopFotografie, the builder and CMS & API. That was a misreading. Retracted to AndreaSlopFotografie and to the builder (SLS Software - CMS): no merge, no rebase, no phase 2; builder stays on stand-by. No merge had taken place. Lesson: ask for explicit confirmation before relaying an action as a decision when the wording is ambiguous." + +**Context**: CMS phase 2 remains blocked on Bryan's explicit go. + +--- + +## U2 Approved; U3 Functional Design Question Answered + +**Timestamp**: 2026-11-10T12:30:00Z + +**User Input**: "Akkoord, ga naar u3" / "Ik wil beide methoden kunnen gebruiken. Ik denk namelijk dat ik bij SLP Software begin met de op maat aanpak als p0akket, maar deze methode is voor Andrea Slop Fotografie mogelijk wel handig." + +**AI Response**: "U2 approved, starting U3 (packages-block) Functional Design. Banner question: both presentations must be possible. Decision: a package can be shown as a normal card or as the black 'Past er niets bij?' banner under the cards, chosen per site by a frontend setting (bannerSlugs in content.ts, empty for SLP: Maatwerk stays a card); a later additive API field (layout: card|banner, CMS extension, not now) can take over the choice per offering. Chips from 4 packages are independent of the banner." + +**Context**: Functional Design U3. + +--- + +## U3 Functional Design Complete + +**Timestamp**: 2026-11-10T13:10:00Z + +**User Input**: "(none)" + +**AI Response**: "Generated packages-block-functional-design-plan.md, packages-block-fd-questions.md and construction/packages-block/functional-design/{domain-entities, business-rules (BR-U3-1..12), business-logic-model, frontend-components}.md with Mermaid diagrams. Key decisions: any number of packages; banner vs card chosen per site by packagesSettings.bannerSlugs (empty for SLP so Maatwerk stays a card; fallback banner texts; later additive API field layout); chips from 4 card packages with categories; swipe row below sm with snap, dots as buttons, featured scrolled into view; skeleton/error with retry/empty states; CTA sets preselect (slug, key) and scrolls to #contact. Completion message presented; awaiting approval." + +**Context**: Functional Design U3 complete; next is Code Generation plan for U3. + +--- + +## U3 Functional Design Approved; Code Generation Plan Ready + +**Timestamp**: 2026-11-10T13:30:00Z + +**User Input**: "ga verder" + +**AI Response**: "U3 Functional Design approved. Created construction/plans/packages-block-code-generation-plan.md (7 steps). Plan approval prompt presented." + +**Context**: Code Generation Part 1 for U3. + +--- diff --git a/aidlc-docs/features/redesign-modern-timetravel/construction/packages-block/code/summary.md b/aidlc-docs/features/redesign-modern-timetravel/construction/packages-block/code/summary.md new file mode 100644 index 0000000..1c02b3a --- /dev/null +++ b/aidlc-docs/features/redesign-modern-timetravel/construction/packages-block/code/summary.md @@ -0,0 +1,27 @@ +# Code Summary — packages-block (U3) + +## What was built +- **Pure logic** (`src/shared/packages/packageLogic.ts`): `splitPackages`, `deriveChips`, `filterCards`, `resultLabel`, `initialIndex`, `activeIndexFromScroll`. +- **Hooks**: `usePackageFilter` (cards, banner packages, chips, active chip with fallback to "Alles", visible list, status label), `useSwipeRow` (start position on the featured card, rAF-throttled scroll sync for the dots, smooth `scrollTo` unless reduced motion). +- **Contact hand-over** (`src/shared/contact/`): `ContactPreselectContext`/`Provider`/`useContactPreselect` (`subject` = package slug, `key` increments per click); the provider is mounted in `RootLayout`; U4 consumes it. +- **Components**: `PackagesSection` (B styling: alt background, heading, intro, chips + live status line, list, banner, states), `FilterChips`, `PackageList` (one render path: scroll-snap swipe row below `sm`, grid 2 columns from `sm`, 3 above 1000px), `SwipeDots` (buttons with labels, `aria-current`, mobile only, hidden at one card), `PackageCard` (flat block, featured in brand red with "Meest gekozen" badge, CTA sets preselect and scrolls to `#contact`), `PackageBanner` (black "Past er niets bij?" block), `PackageCardSkeleton` (square, 3 in the same container). +- **Settings** (`content.ts`): `packagesSettings = { bannerSlugs: [], chipThreshold: 4, bannerTitle, bannerFallback }`; `PackageCardData` gains optional `category`, `categoryId`, `displayOrder`. +- **Token tweak**: B light `--color-surface-2` is now white (the card colour of the canvas). +- **Heading**: "Drie manieren om te starten." with exactly three card packages, otherwise "Manieren om te starten." + +## How a site chooses card vs banner +Put the package slug in `packagesSettings.bannerSlugs` (e.g. `['maatwerk']`): it is then shown as the black banner under the cards (always visible, independent of the active chip) and not as a card; with no matching package the fallback texts are used. SLP Software keeps the list empty, so Maatwerk is a normal card. A later additive API field `layout: card | banner` can replace the setting. + +## Verification (Step 13.5, real output) +- Before this unit (after U2): 13 files / 122 tests. After: **14 files / 154 tests passed**; `pnpm lint` 0 errors (same 2 warnings); `pnpm build` OK (JS 453 kB, CSS 57.8 kB). Snap utilities and the `min-[1001px]` breakpoint are generated. +- Tests cover: pure logic (split, chip threshold 3 vs 4, blank categories, filter, singular/plural label, initial index, scroll-to-index), the live three packages (no chips/banner, Maatwerk a card, heading), loading/error with retry/empty, six packages with chips and counts and filtering, banner via setting (kept for every chip, fallback, CTA preselect), preselect key increments and scroll to `#contact`, swipe row roles/classes/dots/click/reduced motion/scroll sync with mocked layout, accessibility attributes. + +## Notes for review +- **No `category` yet in the live API**: chips stay hidden until the CMS-U1 API is deployed (by design); with the current three packages the block looks like before, in the new style. +- Real swipe feel, card widths at 360px and the dark look need a browser check (no layout engine in the tests). +- Prettier touched two unrelated files; both were reverted. + +## Hand-offs +- U4: read `useContactPreselect()` in the form (subject options = packages + "Overig"; apply when `key` changes; unknown subject ignored). +- U5: reuse `packageLogic`, `usePackageFilter`, `useSwipeRow`, `ContactPreselect*`; only the presentation (2006 style) is new. +- CMS: optional future `layout` field on offerings (additive, not needed now). diff --git a/aidlc-docs/features/redesign-modern-timetravel/construction/packages-block/functional-design/business-logic-model.md b/aidlc-docs/features/redesign-modern-timetravel/construction/packages-block/functional-design/business-logic-model.md new file mode 100644 index 0000000..0e0e630 --- /dev/null +++ b/aidlc-docs/features/redesign-modern-timetravel/construction/packages-block/functional-design/business-logic-model.md @@ -0,0 +1,44 @@ +# Business Logic Model — packages-block (U3) + +## Data flow +```mermaid +sequenceDiagram + box rgba(99,179,237,0.4) Browser + participant V as Visitor + participant PS as PackagesSection + participant HK as usePackageFilter + end + box rgba(154,230,180,0.4) CMS API + participant A as offerings + end + PS->>A: GET offerings + A-->>PS: package array + PS->>HK: split and derive chips + HK-->>PS: cards, chips, banner + V->>PS: choose a chip + PS->>HK: set active chip + HK-->>PS: filtered cards + V->>PS: click Kies button + PS->>PS: set preselect and scroll to contact +``` + +Text alternative: the section loads the offerings, the filter hook splits cards and banner and derives chips, a chip choice filters the cards, and a Kies button sets the contact preselect and scrolls. + +## Pure functions (unit-testable, `src/shared/packages/`) +- `splitPackages(packages, bannerSlugs) -> { cards, banners }` +- `deriveChips(cards, threshold) -> Chip[] | null` (null = no chips) +- `filterCards(cards, activeId) -> PackageCardData[]` +- `resultLabel(count, hasBanner) -> string` ("1 pakket ...", "3 pakketten ...") +- `initialIndex(visible) -> number` (index of the featured card, else 0) +- `activeIndexFromScroll(scrollLeft, itemWidths|itemOffsets, viewportWidth) -> number` (nearest snap position) + +## Hooks +- `usePackageFilter(packages, settings)`: state `activeId`; returns `{ cards, banners, chips, activeId, setActive, visible, label }`; resets `activeId` to `all` when the chosen category disappears. +- `useSwipeRow(itemCount, initialIndex)`: returns `{ ref, activeIndex, scrollToIndex }`; on mount and when `itemCount`/filter key changes scrolls to `initialIndex` (instant); listens to `scroll` (throttled by `requestAnimationFrame`) to update `activeIndex`; uses `scrollTo({behavior})` with `smooth` unless reduced motion. +- `useContactPreselect` (context from U3, consumed by U4): `{ subject, key, select(subject) }`. + +## Error handling +- API error: error state with retry (`refetch`); loading: skeletons; empty list: info text. +- Unknown/absent `category`: package only under "Alles". +- `bannerSlugs` containing an unknown slug: fallback banner from settings. +- No `ResizeObserver`/`IntersectionObserver` required (scroll event + offsets); jsdom-safe. diff --git a/aidlc-docs/features/redesign-modern-timetravel/construction/packages-block/functional-design/business-rules.md b/aidlc-docs/features/redesign-modern-timetravel/construction/packages-block/functional-design/business-rules.md new file mode 100644 index 0000000..f02928e --- /dev/null +++ b/aidlc-docs/features/redesign-modern-timetravel/construction/packages-block/functional-design/business-rules.md @@ -0,0 +1,38 @@ +# Business Rules — packages-block (U3) + +| Id | Rule | +|---|---| +| BR-U3-1 | The block works with any number of packages (0..n) from the API; nothing is hard-coded to three. Array order = display order; no client-side sorting. | +| BR-U3-2 | **Split**: packages whose `slug` is in `packagesSettings.bannerSlugs` are *banner packages*; all others are *card packages*. Default (empty list): everything is a card, so Maatwerk is a card at SLP Software. | +| BR-U3-3 | **Chips** appear only when the number of card packages is at least `chipThreshold` (4) **and** there is at least one category. Chips: "Alles" plus the distinct non-empty categories of card packages in order of first appearance, each with its count. Selecting a chip shows only that category; "Alles" shows all card packages. Packages without category show only under "Alles". Chip state is not persisted. | +| BR-U3-4 | **Result count**: below the chips a polite status line "N pakket(ten) met vaste prijs" (plus ", plus maatwerk" when a banner is shown); announced to screen readers when the filter changes. | +| BR-U3-5 | **Layout**: from the `sm` breakpoint up a grid (3 columns, 2 columns up to 1000px); below it a **horizontal swipe row** (CSS scroll-snap, `snap-x snap-mandatory`, cards ~85% wide so the next card peeks) for any number of packages. The row works without JavaScript; JS only drives the dots and the initial position. | +| BR-U3-6 | **Banner**: when banner packages exist (or `bannerSlugs` is non-empty without a match, using `bannerFallback`), a black banner is shown below the cards with title, text, price label/note and a CTA to `#contact`. The banner is always visible regardless of the active chip. With an empty `bannerSlugs` no banner is rendered. (Both presentations remain possible per site; a later additive API field `layout: card \| banner` can replace the setting without changing the UI.) | +| BR-U3-7 | **Featured**: the featured package is styled with the brand colour and the "Meest gekozen" corner badge. In the swipe row the featured card is scrolled into view on first display (centered); if none is featured, the first card. After a filter change the row returns to its start (or the featured card if it is still visible). | +| BR-U3-8 | **Dots** (mobile only): one real ` + ); + })} + + ); +} diff --git a/src/features/landing/components/PackageBanner.tsx b/src/features/landing/components/PackageBanner.tsx new file mode 100644 index 0000000..822121f --- /dev/null +++ b/src/features/landing/components/PackageBanner.tsx @@ -0,0 +1,53 @@ +import type { PackageCardData, PackagesSettings } from '../data/content'; +import { handleAnchorClick } from '../../../utils/scrollToHash'; +import { useContactPreselect } from '../../../shared/contact/useContactPreselect'; + +interface PackageBannerProps { + /** The package shown as banner, or undefined to use the fallback texts. */ + pkg?: PackageCardData; + settings: PackagesSettings; +} + +/** Black "Past er niets bij?" banner under the cards (BR-U3-6). */ +export function PackageBanner({ pkg, settings }: PackageBannerProps) { + const { select } = useContactPreselect(); + const text = pkg?.description ?? settings.bannerFallback.text; + const price = pkg?.price ?? settings.bannerFallback.priceLabel; + const note = pkg?.priceNote ?? settings.bannerFallback.priceNote; + const cta = pkg?.ctaLabel ?? settings.bannerFallback.ctaLabel; + + return ( +
+
+

+ {settings.bannerTitle} +

+

{text}

+
+
+
+
+ {price} +
+
{note}
+
+ { + if (pkg) { + select(pkg.slug); + } + handleAnchorClick(event, '#contact'); + }} + className="bg-white px-[26px] py-[17px] text-base font-bold text-[#0e0d0d] no-underline hover:opacity-90" + data-testid="package-banner-cta" + > + {cta} + +
+
+ ); +} diff --git a/src/features/landing/components/PackageCard.tsx b/src/features/landing/components/PackageCard.tsx index a624da8..b89b6ce 100644 --- a/src/features/landing/components/PackageCard.tsx +++ b/src/features/landing/components/PackageCard.tsx @@ -1,49 +1,63 @@ import type { PackageCardData } from '../data/content'; import { handleAnchorClick } from '../../../utils/scrollToHash'; +import { useContactPreselect } from '../../../shared/contact/useContactPreselect'; +/** Package card of design B: flat block, featured package in the brand colour with a badge. */ export function PackageCard({ pkg }: { pkg: PackageCardData }) { + const { select } = useContactPreselect(); + const featured = Boolean(pkg.featured); + return ( -
- {pkg.featured && ( - + {featured && ( + Meest gekozen )} - {pkg.slug} -

{pkg.title}

-

{pkg.description}

-
+

+ {pkg.title} +

+

+ {pkg.description} +

+
{pkg.price} - {pkg.priceNote}
-
+ ); } diff --git a/src/features/landing/components/PackageCardSkeleton.tsx b/src/features/landing/components/PackageCardSkeleton.tsx index 0fa4d37..3382f42 100644 --- a/src/features/landing/components/PackageCardSkeleton.tsx +++ b/src/features/landing/components/PackageCardSkeleton.tsx @@ -1,26 +1,25 @@ -// Mirrors PackageCard's structure/spacing 1-to-1 so the grid doesn't reflow once -// real data arrives — only the content becomes pulsing placeholder blocks. +// Mirrors PackageCard's structure/spacing so the layout doesn't reflow once real data arrives; +// only the content becomes pulsing placeholder blocks. export function PackageCardSkeleton() { return (