diff --git a/aidlc-docs/features/contact-forms-module/aidlc-state.md b/aidlc-docs/features/contact-forms-module/aidlc-state.md index dca1ade..6b6ddae 100644 --- a/aidlc-docs/features/contact-forms-module/aidlc-state.md +++ b/aidlc-docs/features/contact-forms-module/aidlc-state.md @@ -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 diff --git a/aidlc-docs/features/contact-forms-module/audit.md b/aidlc-docs/features/contact-forms-module/audit.md index f113d36..5d8428e 100644 --- a/aidlc-docs/features/contact-forms-module/audit.md +++ b/aidlc-docs/features/contact-forms-module/audit.md @@ -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. + +--- diff --git a/aidlc-docs/features/contact-forms-module/construction/cms-u1b-offerings-categories-ui/code/summary.md b/aidlc-docs/features/contact-forms-module/construction/cms-u1b-offerings-categories-ui/code/summary.md new file mode 100644 index 0000000..56f1889 --- /dev/null +++ b/aidlc-docs/features/contact-forms-module/construction/cms-u1b-offerings-categories-ui/code/summary.md @@ -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). diff --git a/aidlc-docs/features/contact-forms-module/construction/plans/cms-u1b-offerings-categories-ui-code-generation-plan.md b/aidlc-docs/features/contact-forms-module/construction/plans/cms-u1b-offerings-categories-ui-code-generation-plan.md new file mode 100644 index 0000000..5f939e7 --- /dev/null +++ b/aidlc-docs/features/contact-forms-module/construction/plans/cms-u1b-offerings-categories-ui-code-generation-plan.md @@ -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`). diff --git a/frontend/src/features/offerings/components/CategoriesDialog.tsx b/frontend/src/features/offerings/components/CategoriesDialog.tsx new file mode 100644 index 0000000..2ebefc1 --- /dev/null +++ b/frontend/src/features/offerings/components/CategoriesDialog.tsx @@ -0,0 +1,320 @@ +import { useState, type FormEvent } from 'react'; +import { useTranslation } from 'react-i18next'; +import { Check, Pencil, Trash2, X } from 'lucide-react'; +import { Button } from '@/components/ui/button'; +import { Dialog, DialogContent, DialogHeader, DialogTitle } from '@/components/ui/dialog'; +import { Input } from '@/components/ui/input'; +import { NetworkError, ProblemDetailsError } from '@/lib/api-client'; +import { categoryNameSchema } from '../schemas/offering'; +import { useOfferingCategories } from '../services/useOfferingCategories'; +import { useCreateOfferingCategory } from '../services/useCreateOfferingCategory'; +import { useRenameOfferingCategory } from '../services/useRenameOfferingCategory'; +import { useDeleteOfferingCategory } from '../services/useDeleteOfferingCategory'; +import type { OfferingCategoryDto } from '../services/types'; + +interface CategoriesDialogProps { + open: boolean; + onOpenChange: (open: boolean) => void; +} + +/** + * Manages the categories offerings can be placed in. Lives inside the Offerings management + * (opened from the list page) rather than on a page of its own. + */ +export function CategoriesDialog({ open, onOpenChange }: CategoriesDialogProps) { + const { t } = useTranslation(); + const { data: categories, isPending, isError } = useOfferingCategories(); + const createCategory = useCreateOfferingCategory(); + const renameCategory = useRenameOfferingCategory(); + const deleteCategory = useDeleteOfferingCategory(); + + const [newName, setNewName] = useState(''); + const [editingId, setEditingId] = useState(null); + const [editName, setEditName] = useState(''); + const [deletePendingId, setDeletePendingId] = useState(null); + const [error, setError] = useState(null); + + function validate(name: string): string | null { + const result = categoryNameSchema.safeParse(name); + if (result.success) return null; + return result.error.issues[0].code === 'too_big' + ? t('offerings.categories.errors.nameTooLong') + : t('offerings.categories.errors.nameRequired'); + } + + // Server rejections are translated here instead of showing the API's English titles. + function describeError(err: unknown, context: { name?: string; usedBy?: number }): string { + if (err instanceof NetworkError) return t('errors.network'); + if (err instanceof ProblemDetailsError && err.status === 409) { + return context.usedBy !== undefined + ? t('offerings.categories.errors.inUse', { count: context.usedBy }) + : t('offerings.categories.errors.duplicate', { name: context.name ?? '' }); + } + return t('errors.generic'); + } + + async function handleAdd(event: FormEvent) { + event.preventDefault(); + const trimmed = newName.trim(); + const problem = validate(trimmed); + if (problem) { + setError(problem); + return; + } + setError(null); + try { + await createCategory.mutateAsync(trimmed); + setNewName(''); + } catch (err) { + setError(describeError(err, { name: trimmed })); + } + } + + function startEdit(category: OfferingCategoryDto) { + setError(null); + setDeletePendingId(null); + setEditingId(category.id); + setEditName(category.name); + } + + function cancelEdit() { + setEditingId(null); + setError(null); + } + + async function confirmEdit(category: OfferingCategoryDto) { + const trimmed = editName.trim(); + const problem = validate(trimmed); + if (problem) { + setError(problem); + return; + } + if (trimmed === category.name) { + cancelEdit(); + return; + } + setError(null); + try { + await renameCategory.mutateAsync({ id: category.id, name: trimmed }); + setEditingId(null); + } catch (err) { + setError(describeError(err, { name: trimmed })); + } + } + + function startDelete(category: OfferingCategoryDto) { + setError(null); + setEditingId(null); + setDeletePendingId(category.id); + } + + async function confirmDelete(category: OfferingCategoryDto) { + setError(null); + try { + await deleteCategory.mutateAsync(category.id); + setDeletePendingId(null); + } catch (err) { + setDeletePendingId(null); + setError(describeError(err, { usedBy: category.offeringCount })); + } + } + + function handleOpenChange(next: boolean) { + if (!next) { + setEditingId(null); + setDeletePendingId(null); + setError(null); + setNewName(''); + } + onOpenChange(next); + } + + return ( + + { + // Escape while renaming only cancels the rename, it does not close the dialog. + if (editingId !== null) { + event.preventDefault(); + cancelEdit(); + } + }} + > + + {t('offerings.categories.title')} + + + {error !== null && ( +

+ {error} +

+ )} + + {isPending && ( +

{t('common.loading')}

+ )} + {isError &&

{t('errors.generic')}

} + + {!isPending && !isError && categories.length === 0 && ( +

+ {t('offerings.categories.emptyState')} +

+ )} + + {!isPending && !isError && categories.length > 0 && ( +
    + {categories.map((category) => ( +
  • + {editingId === category.id ? ( + <> + setEditName(e.target.value)} + onKeyDown={(e) => { + if (e.key === 'Enter') { + e.preventDefault(); + void confirmEdit(category); + } else if (e.key === 'Escape') { + e.stopPropagation(); + cancelEdit(); + } + }} + /> +
    + + +
    + + ) : ( + <> +
    + + {category.name} + + + {t('offerings.categories.offeringCount', { + count: category.offeringCount, + })} + +
    + + {deletePendingId === category.id ? ( +
    + + {t('offerings.categories.deleteConfirm')} + + + +
    + ) : ( +
    + + +
    + )} + + )} +
  • + ))} +
+ )} + +
+ setNewName(e.target.value)} + /> + +
+
+
+ ); +} diff --git a/frontend/src/features/offerings/components/OfferingForm.tsx b/frontend/src/features/offerings/components/OfferingForm.tsx index 0064855..15c2a2c 100644 --- a/frontend/src/features/offerings/components/OfferingForm.tsx +++ b/frontend/src/features/offerings/components/OfferingForm.tsx @@ -1,4 +1,4 @@ -import { useState } from 'react'; +import { useEffect, useState } from 'react'; import { useForm, useWatch } from 'react-hook-form'; import { zodResolver } from '@hookform/resolvers/zod'; import { useTranslation } from 'react-i18next'; @@ -7,6 +7,8 @@ import { Button } from '@/components/ui/button'; import { Input } from '@/components/ui/input'; import { Label } from '@/components/ui/label'; import { FieldError } from '@/components/ui/FieldError'; +import { Select, SelectContent, SelectItem, SelectTrigger, SelectValue } from '@/components/ui/select'; +import { useOfferingCategories } from '../services/useOfferingCategories'; import { slugifyPreview } from '@/lib/slugify'; import { offeringFormSchema, type OfferingFormData } from '../schemas/offering'; import type { OfferingDto } from '../services/types'; @@ -39,9 +41,32 @@ export function OfferingForm({ initialValues, onSubmit, isSubmitting }: Offering ctaLabel: '', featured: false, slug: '', + categoryId: null, }, }); + // Radix Select does not allow an empty value, so "no category" is the sentinel 'none' here + // and is mapped back to null for the form value. + const NO_CATEGORY = 'none'; + const { data: categories, isFetching: isFetchingCategories } = useOfferingCategories(); + const categoryId = useWatch({ control, name: 'categoryId' }); + const selectedCategory = + categoryId != null && categories?.some((c) => c.id === categoryId) ? categoryId : NO_CATEGORY; + + // A category that no longer exists (deleted meanwhile) falls back to "no category" so the + // form never submits an id the API would reject. Only judged on fresh data: a cached list + // that is being refetched may still be missing a category that does exist. + useEffect(() => { + if ( + categories !== undefined && + !isFetchingCategories && + categoryId != null && + !categories.some((c) => c.id === categoryId) + ) { + setValue('categoryId', null); + } + }, [categories, isFetchingCategories, categoryId, setValue]); + // useFieldArray requires object-shaped array items — features is a plain string[], // so add/remove are handled directly via setValue instead. const features = useWatch({ control, name: 'features' }); @@ -177,6 +202,37 @@ export function OfferingForm({ initialValues, onSubmit, isSubmitting }: Offering +
+ + +
+
{features.map((_, index) => ( diff --git a/frontend/src/features/offerings/components/OfferingRow.tsx b/frontend/src/features/offerings/components/OfferingRow.tsx index abe39ff..e620c4a 100644 --- a/frontend/src/features/offerings/components/OfferingRow.tsx +++ b/frontend/src/features/offerings/components/OfferingRow.tsx @@ -3,6 +3,7 @@ import { CSS } from '@dnd-kit/utilities'; import { useTranslation } from 'react-i18next'; import { GripVertical, Star, ChevronUp, ChevronDown, Pencil, Trash2 } from 'lucide-react'; import { Link } from '@tanstack/react-router'; +import { Badge } from '@/components/ui/badge'; import { Button } from '@/components/ui/button'; import { TableCell, TableRow } from '@/components/ui/table'; import { useUpdateOffering } from '../services/useUpdateOffering'; @@ -45,7 +46,14 @@ export function OfferingRow({ offering, isFirst, isLast, onDeleteRequested }: Of - {offering.title} + + {offering.title} + {offering.category && ( + + {offering.category} + + )} + {offering.price} +
+ + +
{isPending &&

{t('common.loading')}

} @@ -50,6 +62,8 @@ export function OfferingsListPage() { )} + + ; + +/** A category name as typed by an admin (already trimmed by the caller). */ +export const categoryNameSchema = z.string().min(1).max(100); diff --git a/frontend/src/features/offerings/services/types.ts b/frontend/src/features/offerings/services/types.ts index 8cea23d..c647eca 100644 --- a/frontend/src/features/offerings/services/types.ts +++ b/frontend/src/features/offerings/services/types.ts @@ -9,6 +9,10 @@ export interface OfferingDto { ctaLabel: string; featured: boolean; displayOrder: number; + /** Id of the category, or null/absent when the offering has none. */ + categoryId?: string | null; + /** Name of the category (renames show up here automatically). */ + category?: string | null; } export interface CreateOfferingRequest { @@ -21,8 +25,17 @@ export interface CreateOfferingRequest { featured: boolean; /** Omit to auto-generate from title; set to explicitly override. */ slug?: string; + /** Category id; null clears the category. */ + categoryId?: string | null; } export type UpdateOfferingRequest = CreateOfferingRequest; +export interface OfferingCategoryDto { + id: string; + name: string; + sortOrder: number; + offeringCount: number; +} + export type MoveDirection = 'up' | 'down'; diff --git a/frontend/src/features/offerings/services/useCreateOffering.ts b/frontend/src/features/offerings/services/useCreateOffering.ts index 5a3908a..049557a 100644 --- a/frontend/src/features/offerings/services/useCreateOffering.ts +++ b/frontend/src/features/offerings/services/useCreateOffering.ts @@ -9,7 +9,7 @@ export function useCreateOffering( return useMutation({ mutationFn: (data) => api.post('/api/v1/offerings', data), onSuccess: (data, variables, ...rest) => { - queryClient.invalidateQueries({ queryKey: ['offerings', 'admin'] }); + queryClient.invalidateQueries({ queryKey: ['offerings', 'list'] }); options?.onSuccess?.(data, variables, ...rest); }, onError: options?.onError, diff --git a/frontend/src/features/offerings/services/useCreateOfferingCategory.ts b/frontend/src/features/offerings/services/useCreateOfferingCategory.ts new file mode 100644 index 0000000..7a286e5 --- /dev/null +++ b/frontend/src/features/offerings/services/useCreateOfferingCategory.ts @@ -0,0 +1,15 @@ +import { useMutation, useQueryClient } from '@tanstack/react-query'; +import { api } from '@/lib/api-client'; +import { OFFERING_CATEGORIES_KEY } from './useOfferingCategories'; +import type { OfferingCategoryDto } from './types'; + +export function useCreateOfferingCategory() { + const queryClient = useQueryClient(); + return useMutation({ + mutationFn: (name) => + api.post('/api/v1/offerings/categories', { name }), + onSuccess: () => { + queryClient.invalidateQueries({ queryKey: OFFERING_CATEGORIES_KEY }); + }, + }); +} diff --git a/frontend/src/features/offerings/services/useDeleteOffering.ts b/frontend/src/features/offerings/services/useDeleteOffering.ts index 4e2fc09..10d92d2 100644 --- a/frontend/src/features/offerings/services/useDeleteOffering.ts +++ b/frontend/src/features/offerings/services/useDeleteOffering.ts @@ -8,7 +8,7 @@ export function useDeleteOffering( return useMutation({ mutationFn: (id) => api.delete(`/api/v1/offerings/${id}`), onSuccess: (data, variables, ...rest) => { - queryClient.invalidateQueries({ queryKey: ['offerings', 'admin'] }); + queryClient.invalidateQueries({ queryKey: ['offerings', 'list'] }); options?.onSuccess?.(data, variables, ...rest); }, onError: options?.onError, diff --git a/frontend/src/features/offerings/services/useDeleteOfferingCategory.ts b/frontend/src/features/offerings/services/useDeleteOfferingCategory.ts new file mode 100644 index 0000000..9d81c42 --- /dev/null +++ b/frontend/src/features/offerings/services/useDeleteOfferingCategory.ts @@ -0,0 +1,14 @@ +import { useMutation, useQueryClient } from '@tanstack/react-query'; +import { api } from '@/lib/api-client'; +import { OFFERING_CATEGORIES_KEY } from './useOfferingCategories'; + +export function useDeleteOfferingCategory() { + const queryClient = useQueryClient(); + return useMutation({ + mutationFn: (id) => api.delete(`/api/v1/offerings/categories/${id}`), + onSuccess: () => { + queryClient.invalidateQueries({ queryKey: OFFERING_CATEGORIES_KEY }); + queryClient.invalidateQueries({ queryKey: ['offerings', 'list'] }); + }, + }); +} diff --git a/frontend/src/features/offerings/services/useMoveOffering.ts b/frontend/src/features/offerings/services/useMoveOffering.ts index 62d0e9f..642c4a5 100644 --- a/frontend/src/features/offerings/services/useMoveOffering.ts +++ b/frontend/src/features/offerings/services/useMoveOffering.ts @@ -2,7 +2,7 @@ import { useMutation, useQueryClient, type UseMutationOptions } from '@tanstack/ import { api } from '@/lib/api-client'; import type { MoveDirection, OfferingDto } from './types'; -const OFFERINGS_KEY = ['offerings', 'admin']; +const OFFERINGS_KEY = ['offerings', 'list']; /** * Moves one offering a step up or down. The API has no move endpoint (the collection is reordered diff --git a/frontend/src/features/offerings/services/useOfferingCategories.ts b/frontend/src/features/offerings/services/useOfferingCategories.ts new file mode 100644 index 0000000..1194542 --- /dev/null +++ b/frontend/src/features/offerings/services/useOfferingCategories.ts @@ -0,0 +1,12 @@ +import { useQuery } from '@tanstack/react-query'; +import { api } from '@/lib/api-client'; +import type { OfferingCategoryDto } from './types'; + +export const OFFERING_CATEGORIES_KEY = ['offerings', 'categories']; + +export function useOfferingCategories() { + return useQuery({ + queryKey: OFFERING_CATEGORIES_KEY, + queryFn: () => api.get('/api/v1/offerings/categories'), + }); +} diff --git a/frontend/src/features/offerings/services/useOfferings.ts b/frontend/src/features/offerings/services/useOfferings.ts index 5fee1e9..0a1a13b 100644 --- a/frontend/src/features/offerings/services/useOfferings.ts +++ b/frontend/src/features/offerings/services/useOfferings.ts @@ -4,7 +4,7 @@ import type { OfferingDto } from './types'; export function useOfferings() { return useQuery({ - queryKey: ['offerings', 'admin'], + queryKey: ['offerings', 'list'], queryFn: () => api.get('/api/v1/offerings'), }); } diff --git a/frontend/src/features/offerings/services/useRenameOfferingCategory.ts b/frontend/src/features/offerings/services/useRenameOfferingCategory.ts new file mode 100644 index 0000000..66d3b4c --- /dev/null +++ b/frontend/src/features/offerings/services/useRenameOfferingCategory.ts @@ -0,0 +1,19 @@ +import { useMutation, useQueryClient } from '@tanstack/react-query'; +import { api } from '@/lib/api-client'; +import { OFFERING_CATEGORIES_KEY } from './useOfferingCategories'; +import type { OfferingCategoryDto } from './types'; + +type RenameVariables = { id: string; name: string }; + +export function useRenameOfferingCategory() { + const queryClient = useQueryClient(); + return useMutation({ + mutationFn: ({ id, name }) => + api.put(`/api/v1/offerings/categories/${id}`, { name }), + onSuccess: () => { + // The category name is part of every offering that uses it, so refresh both lists. + queryClient.invalidateQueries({ queryKey: OFFERING_CATEGORIES_KEY }); + queryClient.invalidateQueries({ queryKey: ['offerings', 'list'] }); + }, + }); +} diff --git a/frontend/src/features/offerings/services/useReorderOfferings.ts b/frontend/src/features/offerings/services/useReorderOfferings.ts index 6e92f74..fa9d473 100644 --- a/frontend/src/features/offerings/services/useReorderOfferings.ts +++ b/frontend/src/features/offerings/services/useReorderOfferings.ts @@ -8,7 +8,7 @@ export function useReorderOfferings( return useMutation({ mutationFn: (orderedIds) => api.put('/api/v1/offerings/order', { orderedIds }), onSuccess: (data, variables, ...rest) => { - queryClient.invalidateQueries({ queryKey: ['offerings', 'admin'] }); + queryClient.invalidateQueries({ queryKey: ['offerings', 'list'] }); options?.onSuccess?.(data, variables, ...rest); }, onError: options?.onError, diff --git a/frontend/src/features/offerings/services/useUpdateOffering.ts b/frontend/src/features/offerings/services/useUpdateOffering.ts index e3b0245..28690b5 100644 --- a/frontend/src/features/offerings/services/useUpdateOffering.ts +++ b/frontend/src/features/offerings/services/useUpdateOffering.ts @@ -11,7 +11,7 @@ export function useUpdateOffering( return useMutation({ mutationFn: ({ id, ...body }) => api.put(`/api/v1/offerings/${id}`, body), onSuccess: (data, variables, ...rest) => { - queryClient.invalidateQueries({ queryKey: ['offerings', 'admin'] }); + queryClient.invalidateQueries({ queryKey: ['offerings', 'list'] }); options?.onSuccess?.(data, variables, ...rest); }, onError: options?.onError, diff --git a/frontend/src/i18n/locales/en/translation.json b/frontend/src/i18n/locales/en/translation.json index 98db0ae..4f86ac9 100644 --- a/frontend/src/i18n/locales/en/translation.json +++ b/frontend/src/i18n/locales/en/translation.json @@ -323,6 +323,27 @@ "offerings": { "title": "Offerings", "addButton": "Add Offering", + "categories": { + "manageButton": "Manage categories", + "title": "Manage categories", + "emptyState": "No categories yet. Add the first one.", + "offeringCount_one": "{{count}} offering", + "offeringCount_other": "{{count}} offerings", + "newLabel": "New category", + "addButton": "Add", + "editButton": "Rename category", + "confirmEditButton": "Confirm name", + "cancelButton": "Cancel", + "deleteButton": "Delete category", + "deleteConfirm": "Are you sure?", + "deleteConfirmButton": "Delete", + "errors": { + "nameRequired": "Enter a name.", + "nameTooLong": "The name can be at most 100 characters.", + "duplicate": "A category named '{{name}}' already exists.", + "inUse": "This category is still used by {{count}} offering(s). Move them to another category first." + } + }, "emptyState": { "heading": "No offerings yet", "description": "Add your first offering to get started." @@ -365,6 +386,8 @@ "removeFeatureButton": "Remove", "ctaLabelLabel": "Button text", "featuredLabel": "Featured", + "categoryLabel": "Category", + "noCategory": "No category", "submitButton": "Save", "successToast": "Offering saved successfully" } diff --git a/frontend/src/i18n/locales/nl/translation.json b/frontend/src/i18n/locales/nl/translation.json index fa2c9df..3edb0eb 100644 --- a/frontend/src/i18n/locales/nl/translation.json +++ b/frontend/src/i18n/locales/nl/translation.json @@ -323,6 +323,27 @@ "offerings": { "title": "Aanbiedingen", "addButton": "Aanbieding toevoegen", + "categories": { + "manageButton": "Categorieën beheren", + "title": "Categorieën beheren", + "emptyState": "Nog geen categorieën. Voeg de eerste toe.", + "offeringCount_one": "{{count}} aanbieding", + "offeringCount_other": "{{count}} aanbiedingen", + "newLabel": "Nieuwe categorie", + "addButton": "Toevoegen", + "editButton": "Categorie hernoemen", + "confirmEditButton": "Naam bevestigen", + "cancelButton": "Annuleren", + "deleteButton": "Categorie verwijderen", + "deleteConfirm": "Weet je het zeker?", + "deleteConfirmButton": "Verwijderen", + "errors": { + "nameRequired": "Vul een naam in.", + "nameTooLong": "De naam mag maximaal 100 tekens bevatten.", + "duplicate": "Er bestaat al een categorie met de naam '{{name}}'.", + "inUse": "Deze categorie wordt nog gebruikt door {{count}} aanbieding(en). Verplaats die eerst naar een andere categorie." + } + }, "emptyState": { "heading": "Nog geen aanbiedingen", "description": "Voeg je eerste aanbieding toe om te beginnen." @@ -365,6 +386,8 @@ "removeFeatureButton": "Verwijderen", "ctaLabelLabel": "Knoptekst", "featuredLabel": "Uitgelicht", + "categoryLabel": "Categorie", + "noCategory": "Geen categorie", "submitButton": "Opslaan", "successToast": "Aanbieding succesvol opgeslagen" }