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>
);
}