Aanbod: categorieën beheren in een dialoog en categorie kiezen in het aanbodformulier

Knop 'Categorieën beheren' op de aanbodlijst opent een dialoog om categorieën toe te voegen, te hernoemen en te verwijderen, met Nederlandse meldingen voor een dubbele naam en een categorie die nog in gebruik is. Het formulier krijgt een keuzelijst met 'Geen categorie', de lijst toont de categorie als badge en de querykey ['offerings','list'] vervangt de oude admin-key zodat een hernoeming direct zichtbaar is.

Co-Authored-By: Claude Sonnet 5.5 <noreply@anthropic.com>
This commit is contained in:
2026-11-10 13:06:09 +01:00
co-authored by Claude Sonnet 5.5
parent 8bda5629ff
commit 3048cf8084
24 changed files with 1000 additions and 28 deletions
@@ -5,7 +5,7 @@
- **Feature Slug**: contact-forms-module
- **Project Type**: Brownfield
- **Start Date**: 2026-11-09
- **Current Stage**: CONSTRUCTION - CMS-U1 built and committed (awaiting review); next CMS-U1b
- **Current Stage**: CONSTRUCTION - CMS-U1b built and committed (awaiting review); next CMS-U2
- **Branch**: feature/contact-forms-module (worktree ..SlpModularCms-contact-forms, from master d9cc539; main checkout stays on feature/identity-email-notifications — never switch it)
## Workspace State
@@ -71,3 +71,15 @@
**Context**: awaiting approval.
---
## CMS-U1b plan
**Timestamp**: 2026-11-09
**User Input**: "CMS-U1 v2 geaccepteerd ... stash mag verwijderd ... stuur het plan voor CMS-U1b" (via Redesign - SLS)
**AI Response**: stash dropped (e5e3652); U1b plan written; approval requested.
**Context**: Code Generation Part 1.
---
@@ -0,0 +1,15 @@
# CMS-U1b offerings-categories-ui: code summary
## What changed (frontend/src/features/offerings + nl/en translations only)
- Offerings list page: button "Categorieën beheren" opens CategoriesDialog (no new route). The dialog lists categories with their offering count, adds, renames (inline; Enter confirms, Escape cancels the rename and keeps the dialog open) and deletes (inline confirmation). Errors are shown in Dutch from i18n, not from the API's English titles: duplicate name (409), category in use (409, count from the list), blank/too long name (client side), network, generic.
- OfferingForm: "Categorie" select with "Geen categorie" first. Create sends categoryId or null; edit preselects; a category that no longer exists falls back to none (only judged on fresh data).
- OfferingRow: category badge; the featured toggle now sends categoryId too (PUT replaces the whole offering, so omitting it would have cleared the category).
- Query keys: ['offerings','admin'] renamed to ['offerings','list'] (there is no admin endpoint anymore); category mutations invalidate ['offerings','categories'] and, for rename/delete, ['offerings','list'], so a rename shows up in the list and form without a reload (tested).
- Mocks follow the backend (409 duplicate/in use, 404, counts, 400 invalid categoryId); no seed. The mock `PUT /offerings/order` handler is registered before `/:id` (it was shadowed by `/:id` before).
## Notes
- Radix Select reports an empty value while its options load; the form ignores that (otherwise it wiped the preselected category). Covered by the preselect test.
- Escape during a rename is handled via DialogContent onEscapeKeyDown (Radix closes dialogs on a document listener).
## Verification (real output)
pnpm lint: clean. npx tsc -b: clean. vitest: 42 test files, 278 tests passed (new: 18 in OfferingCategories.test.tsx: dialog 9, list 2, form 5 + schema 1... plus 1 earlier move test). New files formatted with prettier; the 15 pre-existing prettier warnings in this feature folder remain (tech debt, unchanged).
@@ -0,0 +1,27 @@
# Code Generation Plan — CMS-U1b offerings-categories-ui
Frontend only, `frontend/src/features/offerings` (plus the two locale files). Backend routes come from CMS-U1 (commit f2ac377). Wishes from Bryan (via Redesign - SLS): no new page, part of Offerings management; a "Categorieën beheren" button opening a dialog/panel with list + add + rename + delete (409 in understandable Dutch); a "geen categorie" option in the select in the offering form.
## Behaviour
1. **Offerings list page**: a secondary button "Categorieën beheren" next to "Aanbieding toevoegen" opens a dialog. No route change.
2. **Categories dialog** (`CategoriesDialog`): lists categories in API order with the number of offerings (e.g. "Websites · 2 aanbiedingen"); an input + "Toevoegen" at the bottom; each row has rename (pencil: inline input with confirm/cancel, Enter confirms, Escape cancels) and delete (trash: inline "Weet je het zeker? Verwijderen / Annuleren"). Empty state: "Nog geen categorieën. Voeg de eerste toe." Mutation errors show as an inline `role="alert"` message in the dialog.
3. **Error messages (Dutch, not taken from the English API titles)**: create/rename `409` => "Er bestaat al een categorie met de naam '{{name}}'." ; delete `409` => "Deze categorie wordt nog gebruikt door {{count}} aanbieding(en). Verplaats die eerst naar een andere categorie." (count from the list data); network => existing `errors.network`; other => `errors.generic`. Blank name is rejected client-side ("Vul een naam in.", max 100 characters).
4. **Offering form**: a "Categorie" select with the categories and a first option "Geen categorie" (internal value `none`, because Radix Select forbids an empty value). Create sends `categoryId: null` or the id; edit preselects the current category; if the category list is empty the select still shows only "Geen categorie". A stale/unknown `categoryId` from the server falls back to "Geen categorie".
5. **Offering row** shows the category name as a small badge when present.
6. Everything stays consistent through query invalidation: category mutations invalidate `['offerings','categories']` and `['offerings','admin']` (a rename shows in the list and form immediately).
## Steps
- [x] **Step 1 — Types and schema**: `services/types.ts`: `OfferingDto` gains `categoryId?: string | null` and `category?: string | null`; `CreateOfferingRequest` gains `categoryId?: string | null`; new `OfferingCategoryDto { id, name, sortOrder, offeringCount }`. `schemas/offering.ts`: `categoryId: z.string().nullable().optional()`; new `categoryNameSchema` (trimmed, 1..100).
- [x] **Step 2 — Services**: `useOfferingCategories` (GET `/api/v1/offerings/categories`), `useCreateOfferingCategory` (POST), `useRenameOfferingCategory` (PUT `/{id}`), `useDeleteOfferingCategory` (DELETE `/{id}`), same pattern as the existing hooks.
- [x] **Step 3 — Components**: `components/CategoriesDialog.tsx` (state: editing id, delete-pending id, new name, error), reuse `Dialog`, `Button`, `Input`, `FieldError`; `OfferingForm.tsx`: category select (Radix `Select` from `components/ui/select.tsx`); `OfferingRow.tsx`: badge; `OfferingsListPage.tsx`: the button + dialog.
- [x] **Step 4 — i18n**: add `offerings.categories.*` and `offerings.form.categoryLabel/noCategory` to `nl` and `en` translation files (Dutch is the primary wording above; English counterparts provided).
- [x] **Step 5 — Mocks**: `mocks/handlers.ts`: category endpoints with the real behaviours (409 duplicate case-insensitive, 409 in use with counts from the mock offerings, 404 unknown) and offering POST/PUT accepting `categoryId` and returning `categoryId`/`category`. Seed: no categories (nothing is seeded in the real system either); tests add their own.
- [x] **Step 6 — Tests (Vitest + Testing Library + msw)**: dialog (empty state; add; blank name rejected; duplicate name shows the Dutch message; rename; delete unused; delete in-use shows the count message and keeps the row), form (select lists categories and "Geen categorie"; submit sends the chosen `categoryId` or `null`; edit preselects; unknown id falls back), list page (button opens the dialog; the category badge renders), schema test.
- [x] **Step 7 — Verification (automatic)**: `pnpm lint`, `npx tsc -b`, `pnpm test` (full suite). New files are formatted with prettier; the 15 pre-existing prettier warnings are left alone (tech debt, already reported).
- [x] **Step 8 — Docs and commit**: `construction/cms-u1b-offerings-categories-ui/code/summary.md`; one commit; no push.
## Explicitly NOT touched
Backend, ASF-owned frontend areas (auth/refresh, users, theme assets), router, other features, shared UI primitives except by using them (no edits to `components/ui`).
## Traceability
Bryan's category decision, contract § 7 (v2), CMS-U1 handoff (routes, 409 semantics, `offeringCount`).