Offerings: layout (card|banner) op aanbod, max 1 banner, admin-keuze, additief in GET /api/v1/offerings
Co-Authored-By: Claude Sonnet 5.5 <noreply@anthropic.com>
This commit is contained in:
@@ -42,6 +42,7 @@ export function OfferingForm({ initialValues, onSubmit, isSubmitting }: Offering
|
||||
featured: false,
|
||||
slug: '',
|
||||
categoryId: null,
|
||||
layout: 'card',
|
||||
},
|
||||
});
|
||||
|
||||
@@ -50,6 +51,7 @@ export function OfferingForm({ initialValues, onSubmit, isSubmitting }: Offering
|
||||
const NO_CATEGORY = 'none';
|
||||
const { data: categories, isFetching: isFetchingCategories } = useOfferingCategories();
|
||||
const categoryId = useWatch({ control, name: 'categoryId' });
|
||||
const layout = useWatch({ control, name: 'layout' });
|
||||
const selectedCategory =
|
||||
categoryId != null && categories?.some((c) => c.id === categoryId) ? categoryId : NO_CATEGORY;
|
||||
|
||||
@@ -291,6 +293,24 @@ export function OfferingForm({ initialValues, onSubmit, isSubmitting }: Offering
|
||||
<Label htmlFor="offering-featured">{t('offerings.form.featuredLabel')}</Label>
|
||||
</div>
|
||||
|
||||
<div className="space-y-2">
|
||||
<Label htmlFor="offering-layout">{t('offerings.form.layoutLabel')}</Label>
|
||||
<select
|
||||
id="offering-layout"
|
||||
data-testid="offering-layout"
|
||||
className="h-11 w-full rounded-md border border-input bg-background px-3 text-sm"
|
||||
{...register('layout')}
|
||||
>
|
||||
<option value="card">{t('offerings.form.layoutCard')}</option>
|
||||
<option value="banner">{t('offerings.form.layoutBanner')}</option>
|
||||
</select>
|
||||
{layout === 'banner' && (
|
||||
<p className="text-sm text-muted-foreground" data-testid="offering-layout-banner-hint">
|
||||
{t('offerings.form.layoutBannerHint')}
|
||||
</p>
|
||||
)}
|
||||
</div>
|
||||
|
||||
<Button type="submit" disabled={isSubmitting} data-testid="offering-form-submit">
|
||||
{isSubmitting ? '…' : t('offerings.form.submitButton')}
|
||||
</Button>
|
||||
|
||||
@@ -100,6 +100,7 @@ export const offeringsHandlers = [
|
||||
const newOffering: OfferingDto = {
|
||||
id: crypto.randomUUID(),
|
||||
...body,
|
||||
layout: body.layout ?? 'card',
|
||||
slug,
|
||||
displayOrder: mockOfferings.length,
|
||||
};
|
||||
@@ -189,8 +190,17 @@ export const offeringsHandlers = [
|
||||
}
|
||||
|
||||
// PUT replaces the offering: an absent categoryId clears the category, as in the real API.
|
||||
const updated: OfferingDto = { ...existing, ...body, slug, categoryId: body.categoryId ?? null };
|
||||
mockOfferings = mockOfferings.map((o) => (o.id === id ? updated : o));
|
||||
const updated: OfferingDto = {
|
||||
...existing,
|
||||
...body,
|
||||
slug,
|
||||
categoryId: body.categoryId ?? null,
|
||||
layout: body.layout ?? existing.layout ?? 'card',
|
||||
};
|
||||
// At most one banner: promoting this one turns the current banner back into a card.
|
||||
mockOfferings = mockOfferings.map((o) =>
|
||||
o.id === id ? updated : updated.layout === 'banner' && o.layout === 'banner' ? { ...o, layout: 'card' } : o,
|
||||
);
|
||||
return HttpResponse.json(withCategoryName(updated));
|
||||
}),
|
||||
|
||||
|
||||
@@ -1,8 +1,8 @@
|
||||
import { beforeEach, describe, expect, it } from 'vitest';
|
||||
import { screen } from '@testing-library/react';
|
||||
import { screen, waitFor } from '@testing-library/react';
|
||||
import userEvent from '@testing-library/user-event';
|
||||
import { renderApp, mockAuthenticated } from '@/test/utils';
|
||||
import { resetMockOfferings } from '@/features/offerings/mocks/handlers';
|
||||
import { getMockOfferings, resetMockOfferings } from '@/features/offerings/mocks/handlers';
|
||||
import { _resetSetupStatusCache } from '@/router';
|
||||
|
||||
beforeEach(() => {
|
||||
@@ -119,4 +119,34 @@ describe('OfferingFormPage', () => {
|
||||
|
||||
expect(await screen.findByText(/pro.*al in gebruik|already.*taken/i)).toBeInTheDocument();
|
||||
});
|
||||
|
||||
it('defaults the layout to card and shows a hint only when banner is chosen', async () => {
|
||||
mockAuthenticated();
|
||||
renderApp('/offerings/new');
|
||||
|
||||
const select = await screen.findByTestId('offering-layout', {}, { timeout: 10000 });
|
||||
expect(select).toHaveValue('card');
|
||||
expect(screen.queryByTestId('offering-layout-banner-hint')).not.toBeInTheDocument();
|
||||
|
||||
await userEvent.selectOptions(select, 'banner');
|
||||
expect(await screen.findByTestId('offering-layout-banner-hint')).toBeInTheDocument();
|
||||
});
|
||||
|
||||
it('saves a banner and turns the previous banner back into a card', async () => {
|
||||
mockAuthenticated();
|
||||
const first = 'aaaaaaaa-aaaa-aaaa-aaaa-aaaaaaaaaaaa';
|
||||
const second = 'bbbbbbbb-bbbb-bbbb-bbbb-bbbbbbbbbbbb';
|
||||
|
||||
renderApp(`/offerings/${first}/edit`);
|
||||
await userEvent.selectOptions(await screen.findByTestId('offering-layout', {}, { timeout: 10000 }), 'banner');
|
||||
await userEvent.click(screen.getByTestId('offering-form-submit'));
|
||||
await waitFor(() => expect(getMockOfferings().find((o) => o.id === first)?.layout).toBe('banner'));
|
||||
await screen.findByTestId('offerings-title', {}, { timeout: 10000 });
|
||||
|
||||
renderApp(`/offerings/${second}/edit`);
|
||||
await userEvent.selectOptions(await screen.findByTestId('offering-layout', {}, { timeout: 10000 }), 'banner');
|
||||
await userEvent.click(screen.getByTestId('offering-form-submit'));
|
||||
await waitFor(() => expect(getMockOfferings().find((o) => o.id === second)?.layout).toBe('banner'));
|
||||
expect(getMockOfferings().find((o) => o.id === first)?.layout).toBe('card');
|
||||
});
|
||||
});
|
||||
|
||||
@@ -25,6 +25,8 @@ export const offeringFormSchema = z.object({
|
||||
.or(z.literal('')),
|
||||
/** Id of the chosen category; null/absent = no category. */
|
||||
categoryId: z.string().nullable().optional(),
|
||||
/** 'banner' = the wide strip under the cards; at most one per site. */
|
||||
layout: z.enum(['card', 'banner']).optional(),
|
||||
});
|
||||
|
||||
export type OfferingFormData = z.infer<typeof offeringFormSchema>;
|
||||
|
||||
@@ -1,3 +1,5 @@
|
||||
export type OfferingLayout = 'card' | 'banner';
|
||||
|
||||
export interface OfferingDto {
|
||||
id: string;
|
||||
slug: string;
|
||||
@@ -13,6 +15,8 @@ export interface OfferingDto {
|
||||
categoryId?: string | null;
|
||||
/** Name of the category (renames show up here automatically). */
|
||||
category?: string | null;
|
||||
/** Presentation on the website; absent (older API) means 'card'. */
|
||||
layout?: OfferingLayout;
|
||||
}
|
||||
|
||||
export interface CreateOfferingRequest {
|
||||
@@ -27,6 +31,8 @@ export interface CreateOfferingRequest {
|
||||
slug?: string;
|
||||
/** Category id; null clears the category. */
|
||||
categoryId?: string | null;
|
||||
/** Omit to keep the current value (older clients do). */
|
||||
layout?: OfferingLayout;
|
||||
}
|
||||
|
||||
export type UpdateOfferingRequest = CreateOfferingRequest;
|
||||
|
||||
@@ -386,6 +386,10 @@
|
||||
"addFeatureButton": "Add feature",
|
||||
"removeFeatureButton": "Remove",
|
||||
"ctaLabelLabel": "Button text",
|
||||
"layoutLabel": "Display",
|
||||
"layoutCard": "Card",
|
||||
"layoutBanner": "Banner (wide strip below the cards)",
|
||||
"layoutBannerHint": "Only one banner is allowed: an existing banner turns back into a regular card.",
|
||||
"featuredLabel": "Featured",
|
||||
"categoryLabel": "Category",
|
||||
"noCategory": "No category",
|
||||
|
||||
@@ -386,6 +386,10 @@
|
||||
"addFeatureButton": "Kenmerk toevoegen",
|
||||
"removeFeatureButton": "Verwijderen",
|
||||
"ctaLabelLabel": "Knoptekst",
|
||||
"layoutLabel": "Weergave",
|
||||
"layoutCard": "Kaart",
|
||||
"layoutBanner": "Banner (brede strook onder de kaarten)",
|
||||
"layoutBannerHint": "Er kan maar één banner zijn: een bestaande banner wordt weer een gewone kaart.",
|
||||
"featuredLabel": "Uitgelicht",
|
||||
"categoryLabel": "Categorie",
|
||||
"noCategory": "Geen categorie",
|
||||
|
||||
Reference in New Issue
Block a user