From 8af156c238b162bed3639c95aa23beeb0f3f184b Mon Sep 17 00:00:00 2001 From: Sluijsens Date: Sun, 15 Nov 2026 11:42:26 +0100 Subject: [PATCH] Aanbiedingen: planning en aan/uit per pakket, admin-lijst /offerings/all, Annuleren op het pakketformulier Co-Authored-By: Claude Sonnet 5.5 --- .../offerings/components/OfferingForm.tsx | 59 +++++- .../offerings/components/OfferingRow.tsx | 67 ++++-- .../src/features/offerings/mocks/handlers.ts | 24 ++- .../offerings/pages/OfferingFormPage.tsx | 13 +- .../offerings/pages/OfferingSchedule.test.tsx | 135 ++++++++++++ .../pages/OfferingsListPage.test.tsx | 4 +- .../offerings/schemas/offering.test.ts | 18 ++ .../features/offerings/schemas/offering.ts | 62 +++--- .../offerings/schemas/offeringBanner.ts | 6 + .../src/features/offerings/services/types.ts | 9 + .../offerings/services/useOfferings.ts | 2 +- frontend/src/i18n/locales/en/translation.json | 9 +- frontend/src/i18n/locales/nl/translation.json | 9 +- openapi/slpsoftware.v1.json | 48 +++++ .../Controllers/OfferingsControllerTests.cs | 10 +- .../Controllers/OfferingsRoutesTests.cs | 6 +- .../Services/OfferingsScheduleTests.cs | 124 +++++++++++ .../Controllers/OfferingsController.cs | 4 + .../Data/Entities/Offering.cs | 6 + .../Data/OfferingsDbContext.cs | 1 + ...1115100000_AddOfferingSchedule.Designer.cs | 200 ++++++++++++++++++ .../20261115100000_AddOfferingSchedule.cs | 43 ++++ .../OfferingsDbContextModelSnapshot.cs | 13 +- .../Models/CreateOfferingRequest.cs | 11 +- .../Models/OfferingDto.cs | 23 ++ .../Models/OfferingSchedule.cs | 18 ++ .../Models/UpdateOfferingRequest.cs | 11 +- .../Services/IOfferingsService.cs | 9 +- .../Services/OfferingsService.cs | 45 +++- 29 files changed, 916 insertions(+), 73 deletions(-) create mode 100644 frontend/src/features/offerings/pages/OfferingSchedule.test.tsx create mode 100644 src/SlpModularCms.Modules.Offerings.Tests/Services/OfferingsScheduleTests.cs create mode 100644 src/SlpModularCms.Modules.Offerings/Migrations/20261115100000_AddOfferingSchedule.Designer.cs create mode 100644 src/SlpModularCms.Modules.Offerings/Migrations/20261115100000_AddOfferingSchedule.cs create mode 100644 src/SlpModularCms.Modules.Offerings/Models/OfferingSchedule.cs diff --git a/frontend/src/features/offerings/components/OfferingForm.tsx b/frontend/src/features/offerings/components/OfferingForm.tsx index 15c2a2c..b270858 100644 --- a/frontend/src/features/offerings/components/OfferingForm.tsx +++ b/frontend/src/features/offerings/components/OfferingForm.tsx @@ -11,15 +11,18 @@ import { Select, SelectContent, SelectItem, SelectTrigger, SelectValue } from '@ import { useOfferingCategories } from '../services/useOfferingCategories'; import { slugifyPreview } from '@/lib/slugify'; import { offeringFormSchema, type OfferingFormData } from '../schemas/offering'; +import { toLocalInput } from '../schemas/offeringBanner'; import type { OfferingDto } from '../services/types'; interface OfferingFormProps { initialValues?: OfferingDto; onSubmit: (values: OfferingFormData) => void; + /** Leaves the form without saving (back to the list). */ + onCancel: () => void; isSubmitting: boolean; } -export function OfferingForm({ initialValues, onSubmit, isSubmitting }: OfferingFormProps) { +export function OfferingForm({ initialValues, onSubmit, onCancel, isSubmitting }: OfferingFormProps) { const { t } = useTranslation(); const { @@ -32,7 +35,14 @@ export function OfferingForm({ initialValues, onSubmit, isSubmitting }: Offering } = useForm({ resolver: zodResolver(offeringFormSchema), mode: 'onTouched', - defaultValues: initialValues ?? { + defaultValues: initialValues + ? { + ...initialValues, + isActive: initialValues.isActive ?? true, + startsAt: toLocalInput(initialValues.startsAt ?? null), + endsAt: toLocalInput(initialValues.endsAt ?? null), + } + : { title: '', description: '', price: '', @@ -42,6 +52,9 @@ export function OfferingForm({ initialValues, onSubmit, isSubmitting }: Offering featured: false, slug: '', categoryId: null, + isActive: true, + startsAt: '', + endsAt: '', }, }); @@ -291,9 +304,45 @@ export function OfferingForm({ initialValues, onSubmit, isSubmitting }: Offering - +
+
+ + +
+
+
+ + +
+
+ + + {errors.endsAt && } +
+
+

{t('offerings.form.scheduleHint')}

+
+ +
+ + +
); } diff --git a/frontend/src/features/offerings/components/OfferingRow.tsx b/frontend/src/features/offerings/components/OfferingRow.tsx index e620c4a..1bf14a5 100644 --- a/frontend/src/features/offerings/components/OfferingRow.tsx +++ b/frontend/src/features/offerings/components/OfferingRow.tsx @@ -1,15 +1,21 @@ import { useSortable } from '@dnd-kit/sortable'; import { CSS } from '@dnd-kit/utilities'; import { useTranslation } from 'react-i18next'; -import { GripVertical, Star, ChevronUp, ChevronDown, Pencil, Trash2 } from 'lucide-react'; +import { GripVertical, Star, ChevronUp, ChevronDown, Pencil, Power, 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'; import { useMoveOffering } from '../services/useMoveOffering'; +import { scheduleStatus } from '../schemas/offeringBanner'; import type { OfferingDto } from '../services/types'; +const fmt = (iso: string | null) => + iso ? new Date(iso).toLocaleString('nl-NL', { dateStyle: 'short', timeStyle: 'short' }) : null; + +const statusVariant = { live: 'default', scheduled: 'secondary', expired: 'outline', off: 'outline' } as const; + interface OfferingRowProps { offering: OfferingDto; isFirst: boolean; @@ -23,6 +29,26 @@ export function OfferingRow({ offering, isFirst, isLast, onDeleteRequested }: Of const updateOffering = useUpdateOffering(); const moveUp = useMoveOffering('up'); const moveDown = useMoveOffering('down'); + const status = scheduleStatus(offering); + + // PUT replaces the whole offering: everything that is not changed has to be sent along, the + // switch and the schedule included, or a click on the star or the power button would reset them. + const fullBody = { + id: offering.id, + title: offering.title, + description: offering.description, + price: offering.price, + priceNote: offering.priceNote, + features: offering.features, + ctaLabel: offering.ctaLabel, + // Leaving the category out would clear it. + categoryId: offering.categoryId ?? null, + featured: offering.featured, + isActive: offering.isActive, + startsAt: offering.startsAt, + endsAt: offering.endsAt, + }; + const toggleLabel = t(offering.isActive ? 'offerings.actions.turnOff' : 'offerings.actions.turnOn'); // The moving visual is rendered by instead (see OfferingsList) — a portal // outside the document flow, so it can't grow the page's scrollable area the way @@ -53,6 +79,19 @@ export function OfferingRow({ offering, isFirst, isLast, onDeleteRequested }: Of {offering.category} )} +
+ + {t(`offerings.banners.status.${status}`)} + + {status === 'live' && ( + {t('offerings.banners.shownBadge')} + )} + {(offering.startsAt || offering.endsAt) && ( + + {fmt(offering.startsAt) ?? '…'} – {fmt(offering.endsAt) ?? '…'} + + )} +
{offering.price} @@ -61,20 +100,7 @@ export function OfferingRow({ offering, isFirst, isLast, onDeleteRequested }: Of size="icon" data-testid={`offering-row-${offering.id}-featured-toggle`} aria-label={offering.featured ? t('offerings.actions.unmarkFeatured') : t('offerings.actions.markFeatured')} - onClick={() => - updateOffering.mutate({ - id: offering.id, - title: offering.title, - description: offering.description, - price: offering.price, - priceNote: offering.priceNote, - features: offering.features, - ctaLabel: offering.ctaLabel, - // PUT replaces the whole offering: leaving the category out would clear it. - categoryId: offering.categoryId ?? null, - featured: !offering.featured, - }) - } + onClick={() => updateOffering.mutate({ ...fullBody, featured: !offering.featured })} > @@ -101,6 +127,17 @@ export function OfferingRow({ offering, isFirst, isLast, onDeleteRequested }: Of > +