From 5386abb9efaa2aaa84ad1e946f5cd3271a6c2cc8 Mon Sep 17 00:00:00 2001 From: Sluijsens Date: Thu, 12 Nov 2026 11:04:50 +0100 Subject: [PATCH] Offerings: banner-tabblad in de admin (lijst, formulier, planning), layout uit de frontend; gate-test bijgewerkt Co-Authored-By: Claude Sonnet 5.5 --- .../components/OfferingBannerDialog.tsx | 190 +++ .../components/OfferingBannersTab.tsx | 146 +++ .../offerings/components/OfferingForm.tsx | 20 - .../src/features/offerings/mocks/handlers.ts | 46 +- .../offerings/pages/OfferingBanners.test.tsx | 141 ++ .../offerings/pages/OfferingFormPage.test.tsx | 34 +- .../offerings/pages/OfferingsListPage.tsx | 39 + .../features/offerings/schemas/offering.ts | 2 - .../offerings/schemas/offeringBanner.ts | 73 ++ .../src/features/offerings/services/types.ts | 30 +- .../services/useDeleteOfferingBanner.ts | 13 + .../offerings/services/useOfferingBanners.ts | 12 + .../services/useSaveOfferingBanner.ts | 18 + frontend/src/i18n/locales/en/translation.json | 1140 +++++++++-------- frontend/src/i18n/locales/nl/translation.json | 1140 +++++++++-------- .../PublicSiteEndpointGateTests.cs | 1 + 16 files changed, 1867 insertions(+), 1178 deletions(-) create mode 100644 frontend/src/features/offerings/components/OfferingBannerDialog.tsx create mode 100644 frontend/src/features/offerings/components/OfferingBannersTab.tsx create mode 100644 frontend/src/features/offerings/pages/OfferingBanners.test.tsx create mode 100644 frontend/src/features/offerings/schemas/offeringBanner.ts create mode 100644 frontend/src/features/offerings/services/useDeleteOfferingBanner.ts create mode 100644 frontend/src/features/offerings/services/useOfferingBanners.ts create mode 100644 frontend/src/features/offerings/services/useSaveOfferingBanner.ts diff --git a/frontend/src/features/offerings/components/OfferingBannerDialog.tsx b/frontend/src/features/offerings/components/OfferingBannerDialog.tsx new file mode 100644 index 0000000..34a94a6 --- /dev/null +++ b/frontend/src/features/offerings/components/OfferingBannerDialog.tsx @@ -0,0 +1,190 @@ +import { useState } from 'react'; +import { useForm } from 'react-hook-form'; +import { zodResolver } from '@hookform/resolvers/zod'; +import { useTranslation } from 'react-i18next'; +import { toast } from 'sonner'; +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 { FormErrorBanner } from '@/components/ui/FormErrorBanner'; +import { Dialog, DialogContent, DialogHeader, DialogTitle } from '@/components/ui/dialog'; +import { NetworkError } from '@/lib/api-client'; +import { + fromLocalInput, + offeringBannerFormSchema, + toLocalInput, + type OfferingBannerFormData, +} from '../schemas/offeringBanner'; +import { useSaveOfferingBanner } from '../services/useSaveOfferingBanner'; +import type { OfferingBannerDto } from '../services/types'; + +interface OfferingBannerDialogProps { + /** Open for editing this banner; null with `creating` = a new one. */ + banner: OfferingBannerDto | null; + creating: boolean; + onClose: () => void; +} + +const EMPTY: OfferingBannerFormData = { + title: '', + text: '', + linkLabel: '', + linkUrl: '', + isActive: true, + startsAt: '', + endsAt: '', +}; + +function toForm(banner: OfferingBannerDto | null): OfferingBannerFormData { + if (!banner) return EMPTY; + return { + title: banner.title, + text: banner.text, + linkLabel: banner.linkLabel ?? '', + linkUrl: banner.linkUrl ?? '', + isActive: banner.isActive, + startsAt: toLocalInput(banner.startsAt), + endsAt: toLocalInput(banner.endsAt), + }; +} + +export function OfferingBannerDialog({ banner, creating, onClose }: OfferingBannerDialogProps) { + const { t } = useTranslation(); + const open = creating || banner !== null; + + return ( + { if (!next) onClose(); }}> + + + + {banner ? t('offerings.banners.editTitle') : t('offerings.banners.createTitle')} + + + {/* Content is unmounted while closed, so every opening starts from fresh form state. */} + + + + ); +} + +function OfferingBannerForm({ banner, onClose }: { banner: OfferingBannerDto | null; onClose: () => void }) { + const { t } = useTranslation(); + const [serverError, setServerError] = useState(null); + const save = useSaveOfferingBanner(); + + const { + register, + handleSubmit, + formState: { errors }, + } = useForm({ + resolver: zodResolver(offeringBannerFormSchema), + mode: 'onTouched', + defaultValues: toForm(banner), + }); + + const onSubmit = async (values: OfferingBannerFormData) => { + setServerError(null); + try { + await save.mutateAsync({ + id: banner?.id, + body: { + title: values.title, + text: values.text, + linkLabel: values.linkLabel || null, + linkUrl: values.linkUrl || null, + isActive: values.isActive, + startsAt: fromLocalInput(values.startsAt), + endsAt: fromLocalInput(values.endsAt), + }, + }); + toast.success(t('offerings.banners.savedToast')); + onClose(); + } catch (err) { + setServerError(err instanceof NetworkError ? t('errors.network') : t('errors.generic')); + } + }; + + return ( + <> + setServerError(null)} + /> + +
+
+ + + +
+ +
+ +