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 > +