Aanbiedingen: planning en aan/uit per pakket, admin-lijst /offerings/all, Annuleren op het pakketformulier

Co-Authored-By: Claude Sonnet 5.5 <noreply@anthropic.com>
This commit is contained in:
2026-11-15 11:42:26 +01:00
co-authored by Claude Sonnet 5.5
parent 321234dfa6
commit 8af156c238
29 changed files with 916 additions and 73 deletions
@@ -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<OfferingFormData>({
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
<Label htmlFor="offering-featured">{t('offerings.form.featuredLabel')}</Label>
</div>
<Button type="submit" disabled={isSubmitting} data-testid="offering-form-submit">
{isSubmitting ? '…' : t('offerings.form.submitButton')}
</Button>
<div className="space-y-3 rounded-md border p-3" data-testid="offering-schedule">
<div className="flex items-center gap-2">
<input
id="offering-active"
type="checkbox"
data-testid="offering-active"
className="size-4 rounded border-input"
{...register('isActive')}
/>
<Label htmlFor="offering-active">{t('offerings.form.activeLabel')}</Label>
</div>
<div className="grid gap-4 sm:grid-cols-2">
<div className="space-y-2">
<Label htmlFor="offering-starts">{t('offerings.form.startsLabel')}</Label>
<Input id="offering-starts" type="datetime-local" data-testid="offering-starts" {...register('startsAt')} />
</div>
<div className="space-y-2">
<Label htmlFor="offering-ends">{t('offerings.form.endsLabel')}</Label>
<Input
id="offering-ends"
type="datetime-local"
data-testid="offering-ends"
aria-invalid={errors.endsAt !== undefined}
{...register('endsAt')}
/>
{errors.endsAt && <FieldError message={t('offerings.form.endBeforeStart')} testId="offering-ends-error" />}
</div>
</div>
<p className="text-xs text-muted-foreground">{t('offerings.form.scheduleHint')}</p>
</div>
<div className="flex flex-col-reverse gap-2 sm:flex-row sm:justify-end">
<Button type="button" variant="outline" onClick={onCancel} disabled={isSubmitting} data-testid="offering-form-cancel">
{t('common.cancel')}
</Button>
<Button type="submit" disabled={isSubmitting} data-testid="offering-form-submit">
{isSubmitting ? '…' : t('offerings.form.submitButton')}
</Button>
</div>
</form>
);
}
@@ -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 <DragOverlay> 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}
</Badge>
)}
<div className="mt-1 flex flex-wrap items-center gap-2">
<Badge variant={statusVariant[status]} data-testid={`offering-row-${offering.id}-status`}>
{t(`offerings.banners.status.${status}`)}
</Badge>
{status === 'live' && (
<Badge data-testid={`offering-row-${offering.id}-shown`}>{t('offerings.banners.shownBadge')}</Badge>
)}
{(offering.startsAt || offering.endsAt) && (
<span className="text-xs text-muted-foreground" data-testid={`offering-row-${offering.id}-period`}>
{fmt(offering.startsAt) ?? '…'} – {fmt(offering.endsAt) ?? '…'}
</span>
)}
</div>
</TableCell>
<TableCell>{offering.price}</TableCell>
<TableCell>
@@ -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 })}
>
<Star className={`size-4 ${offering.featured ? 'fill-yellow-400 text-yellow-400' : ''}`} />
</Button>
@@ -101,6 +127,17 @@ export function OfferingRow({ offering, isFirst, isLast, onDeleteRequested }: Of
>
<ChevronDown className="size-4" />
</Button>
<Button
variant="ghost"
size="icon"
data-testid={`offering-row-${offering.id}-toggle-active`}
aria-label={toggleLabel}
title={toggleLabel}
disabled={updateOffering.isPending}
onClick={() => updateOffering.mutate({ ...fullBody, isActive: !offering.isActive })}
>
<Power className={`size-4 ${offering.isActive ? '' : 'text-muted-foreground'}`} aria-hidden="true" />
</Button>
<Button variant="ghost" size="icon" asChild data-testid={`offering-row-${offering.id}-edit-link`}>
<Link to="/offerings/$id/edit" params={{ id: offering.id }} aria-label={t('offerings.actions.edit')}>
<Pencil className="size-4" />