Hero: planning en hero-brede aan/uit verwijderd (hero altijd aan, live zodra er een titel is); migratie, API, admin, tests en docs bijgewerkt
Co-Authored-By: Claude Sonnet 5.5 <noreply@anthropic.com>
This commit is contained in:
@@ -27,9 +27,6 @@ export const emptyHero = (): HeroAdminDto => ({
|
||||
lead: null,
|
||||
display: 'single',
|
||||
buttons: [],
|
||||
isActive: true,
|
||||
startsAt: null,
|
||||
endsAt: null,
|
||||
slides: [],
|
||||
isLive: false,
|
||||
updatedAt: null,
|
||||
@@ -106,10 +103,7 @@ export const heroHandlers = [
|
||||
lead: body.lead,
|
||||
display: body.display,
|
||||
buttons: body.buttons,
|
||||
isActive: body.isActive,
|
||||
startsAt: body.startsAt,
|
||||
endsAt: body.endsAt,
|
||||
isLive: body.isActive && body.title.trim() !== '',
|
||||
isLive: body.title.trim() !== '',
|
||||
updatedAt: '2026-11-16T12:00:00Z',
|
||||
slides: body.slides.map((s, i) => ({
|
||||
id: s.id ?? `20000000-0000-0000-0000-00000000000${i}`,
|
||||
|
||||
@@ -103,7 +103,7 @@ describe('Hero page', () => {
|
||||
expect(await screen.findByTestId('hero-form', {}, T)).toBeInTheDocument();
|
||||
});
|
||||
|
||||
it('saves the texts, the buttons and the schedule, and shows the hero as live', async () => {
|
||||
it('saves the texts and the buttons, and shows the hero as live', async () => {
|
||||
await openPage();
|
||||
|
||||
await userEvent.type(screen.getByTestId('hero-title-input'), 'Websites,{enter}apps{enter}& meer.');
|
||||
@@ -125,9 +125,6 @@ describe('Hero page', () => {
|
||||
{ label: 'Bekijk pakketten', target: '#pakketten' },
|
||||
{ label: 'Plan een gesprek', target: '#contact' },
|
||||
],
|
||||
isActive: true,
|
||||
startsAt: null,
|
||||
endsAt: null,
|
||||
slides: [],
|
||||
});
|
||||
});
|
||||
@@ -168,15 +165,12 @@ describe('Hero page', () => {
|
||||
expect(await screen.findByTestId('hero-button-1-target-error')).toHaveTextContent(/Vul zowel de tekst als het doel|Fill in both the text and the target/);
|
||||
});
|
||||
|
||||
it('wants the end after the start', async () => {
|
||||
it('has no switch and no schedule: the hero is always on', async () => {
|
||||
await openPage();
|
||||
await userEvent.type(screen.getByTestId('hero-title-input'), 'Titel');
|
||||
fireEvent.change(screen.getByTestId('hero-starts'), { target: { value: '2026-12-10T10:00' } });
|
||||
fireEvent.change(screen.getByTestId('hero-ends'), { target: { value: '2026-12-01T10:00' } });
|
||||
|
||||
await userEvent.click(screen.getByTestId('hero-save'));
|
||||
|
||||
expect(await screen.findByTestId('hero-ends-error')).toHaveTextContent(/Het einde moet na het begin liggen\.|The end must be after the start\./);
|
||||
expect(screen.queryByTestId('hero-active')).not.toBeInTheDocument();
|
||||
expect(screen.queryByTestId('hero-starts')).not.toBeInTheDocument();
|
||||
expect(screen.queryByTestId('hero-ends')).not.toBeInTheDocument();
|
||||
});
|
||||
});
|
||||
|
||||
@@ -650,7 +644,7 @@ describe('Order by dragging, wording and calm waiting', () => {
|
||||
const help = screen.getByTestId('hero-help');
|
||||
expect(help).toHaveTextContent(/#contact/);
|
||||
expect(help).toHaveTextContent(/\/privacy/);
|
||||
expect(help).toHaveTextContent(/Planning|Schedule/);
|
||||
expect(help).not.toHaveTextContent(/Planning|Schedule/);
|
||||
});
|
||||
|
||||
it('numbers the slides by their current order, also after the order changed', async () => {
|
||||
|
||||
@@ -22,7 +22,7 @@ import { SortableSlide } from '../components/SortableSlide';
|
||||
import { UnsavedChangesGuard } from '../components/UnsavedChangesGuard';
|
||||
import { UploadProgress, type UploadItem } from '../components/UploadProgress';
|
||||
import { mediaUrl } from '../lib/media';
|
||||
import { fromLocalInput, heroFormSchema, toLocalInput, type HeroFormData } from '../schemas/hero';
|
||||
import { heroFormSchema, type HeroFormData } from '../schemas/hero';
|
||||
import { heroImageQuery, useHero, useHeroUploadLimits, useSaveHero, useUploadHeroImage } from '../services/hooks';
|
||||
import type { HeroAdminDto, HeroFocusRequest, HeroImageDto, HeroSaveRequest } from '../services/types';
|
||||
|
||||
@@ -37,9 +37,6 @@ function toForm(hero: HeroAdminDto): HeroFormData {
|
||||
lead: hero.lead ?? '',
|
||||
display: hero.display,
|
||||
buttons,
|
||||
isActive: hero.isActive,
|
||||
startsAt: toLocalInput(hero.startsAt),
|
||||
endsAt: toLocalInput(hero.endsAt),
|
||||
slides: hero.slides.map((s) => ({ id: s.id, imageId: s.imageId, alt: s.alt, decorative: s.decorative, isActive: s.isActive })),
|
||||
};
|
||||
}
|
||||
@@ -51,9 +48,6 @@ function toRequest(values: HeroFormData, focusEdits: Record<string, HeroFocusReq
|
||||
lead: values.lead || null,
|
||||
display: values.display,
|
||||
buttons: values.buttons.filter((b) => b.label !== '' && b.target !== ''),
|
||||
isActive: values.isActive,
|
||||
startsAt: fromLocalInput(values.startsAt),
|
||||
endsAt: fromLocalInput(values.endsAt),
|
||||
slides: values.slides.map((s) => ({ id: s.id, imageId: s.imageId, alt: s.decorative ? null : s.alt, decorative: s.decorative, isActive: s.isActive })),
|
||||
imageFocus: Object.entries(focusEdits).map(([imageId, edit]) => ({ imageId, ...edit })),
|
||||
};
|
||||
@@ -117,7 +111,7 @@ export function HeroPage() {
|
||||
<details className="max-w-3xl rounded-md border p-3 text-sm" data-testid="hero-help">
|
||||
<summary className="cursor-pointer font-medium">{t('hero.help.heading')}</summary>
|
||||
<dl className="mt-3 space-y-2">
|
||||
{(['title', 'tagline', 'lead', 'buttons', 'display', 'slides', 'focus', 'schedule'] as const).map((key) => (
|
||||
{(['title', 'tagline', 'lead', 'buttons', 'display', 'slides', 'focus'] as const).map((key) => (
|
||||
<div key={key}>
|
||||
<dt className="font-medium">{t(`hero.help.${key}.name`)}</dt>
|
||||
<dd className="text-muted-foreground">{t(`hero.help.${key}.text`)}</dd>
|
||||
@@ -387,26 +381,6 @@ function HeroEditor({ hero }: { hero: HeroAdminDto }) {
|
||||
))}
|
||||
</section>
|
||||
|
||||
<section className="space-y-3">
|
||||
<h2 className="text-lg font-medium">{t('hero.schedule.title')}</h2>
|
||||
<label className="flex items-center gap-2 text-sm">
|
||||
<input type="checkbox" className="size-4 rounded border-input" data-testid="hero-active" {...register('isActive')} />
|
||||
{t('hero.schedule.active')}
|
||||
</label>
|
||||
<div className="grid gap-3 sm:grid-cols-2">
|
||||
<div className="space-y-1">
|
||||
<Label htmlFor="hero-starts">{t('hero.schedule.starts')}</Label>
|
||||
<Input id="hero-starts" type="datetime-local" data-testid="hero-starts" {...register('startsAt')} />
|
||||
</div>
|
||||
<div className="space-y-1">
|
||||
<Label htmlFor="hero-ends">{t('hero.schedule.ends')}</Label>
|
||||
<Input id="hero-ends" type="datetime-local" data-testid="hero-ends" {...register('endsAt')} />
|
||||
<FieldError message={err(heroErrors.endsAt?.message)} testId="hero-ends-error" />
|
||||
</div>
|
||||
</div>
|
||||
<p className="text-xs text-muted-foreground">{t('hero.schedule.hint')}</p>
|
||||
</section>
|
||||
|
||||
<section
|
||||
className={`space-y-3 rounded-md ${draggingFiles ? 'ring-2 ring-primary ring-offset-4' : ''}`}
|
||||
onDragOver={(event) => {
|
||||
|
||||
@@ -1,5 +1,5 @@
|
||||
import { describe, expect, it } from 'vitest';
|
||||
import { fromLocalInput, heroFormSchema, isAllowedButtonTarget, toLocalInput } from './hero';
|
||||
import { heroFormSchema, isAllowedButtonTarget } from './hero';
|
||||
|
||||
// The same cases as ButtonTargetValidatorTests in src/SlpModularCms.Modules.Hero.Tests/HeroRulesTests.cs.
|
||||
describe('isAllowedButtonTarget', () => {
|
||||
@@ -21,9 +21,6 @@ const base = {
|
||||
lead: '',
|
||||
display: 'single' as const,
|
||||
buttons: [{ label: '', target: '' }, { label: '', target: '' }],
|
||||
isActive: true,
|
||||
startsAt: '',
|
||||
endsAt: '',
|
||||
slides: [],
|
||||
};
|
||||
|
||||
@@ -49,12 +46,3 @@ describe('heroFormSchema', () => {
|
||||
expect(heroFormSchema.safeParse({ ...base, slides }).success).toBe(true);
|
||||
});
|
||||
});
|
||||
|
||||
describe('local date inputs', () => {
|
||||
it('round-trips an instant', () => {
|
||||
const iso = '2026-12-01T09:30:00.000Z';
|
||||
expect(fromLocalInput(toLocalInput(iso))).toBe(iso);
|
||||
expect(toLocalInput(null)).toBe('');
|
||||
expect(fromLocalInput('')).toBeNull();
|
||||
});
|
||||
});
|
||||
|
||||
@@ -62,35 +62,12 @@ export const heroFormSchema = z
|
||||
lead: z.string().trim().max(LEAD_MAX, 'hero.errors.leadTooLong'),
|
||||
display: z.enum(['single', 'slideshow']),
|
||||
buttons: z.array(buttonSchema).length(2),
|
||||
isActive: z.boolean(),
|
||||
/** datetime-local value ("YYYY-MM-DDTHH:mm") in the browser's time zone, or ''. */
|
||||
startsAt: z.string(),
|
||||
endsAt: z.string(),
|
||||
slides: z.array(slideSchema),
|
||||
})
|
||||
.superRefine((v, ctx) => {
|
||||
if (v.title.replace(/\r\n/g, '\n').split('\n').length > TITLE_MAX_LINES) {
|
||||
ctx.addIssue({ code: 'custom', path: ['title'], message: 'hero.errors.titleTooManyLines' });
|
||||
}
|
||||
if (v.startsAt !== '' && v.endsAt !== '' && fromLocalInput(v.endsAt)! <= fromLocalInput(v.startsAt)!) {
|
||||
ctx.addIssue({ code: 'custom', path: ['endsAt'], message: 'hero.errors.endAfterStart' });
|
||||
}
|
||||
});
|
||||
|
||||
export type HeroFormData = z.infer<typeof heroFormSchema>;
|
||||
|
||||
/** ISO instant to the value of a datetime-local input (browser time zone). */
|
||||
export function toLocalInput(iso: string | null): string {
|
||||
if (!iso) return '';
|
||||
const d = new Date(iso);
|
||||
if (Number.isNaN(d.getTime())) return '';
|
||||
const pad = (n: number) => String(n).padStart(2, '0');
|
||||
return `${d.getFullYear()}-${pad(d.getMonth() + 1)}-${pad(d.getDate())}T${pad(d.getHours())}:${pad(d.getMinutes())}`;
|
||||
}
|
||||
|
||||
/** Value of a datetime-local input to an ISO instant, or null when empty. */
|
||||
export function fromLocalInput(value: string): string | null {
|
||||
if (!value) return null;
|
||||
const d = new Date(value);
|
||||
return Number.isNaN(d.getTime()) ? null : d.toISOString();
|
||||
}
|
||||
|
||||
@@ -58,9 +58,6 @@ export interface HeroAdminDto {
|
||||
lead: string | null;
|
||||
display: HeroDisplay;
|
||||
buttons: HeroButtonDto[];
|
||||
isActive: boolean;
|
||||
startsAt: string | null;
|
||||
endsAt: string | null;
|
||||
slides: HeroSlideAdminDto[];
|
||||
isLive: boolean;
|
||||
updatedAt: string | null;
|
||||
@@ -81,9 +78,6 @@ export interface HeroSaveRequest {
|
||||
lead: string | null;
|
||||
display: HeroDisplay;
|
||||
buttons: HeroButtonDto[];
|
||||
isActive: boolean;
|
||||
startsAt: string | null;
|
||||
endsAt: string | null;
|
||||
slides: HeroSlideRequest[];
|
||||
/** Changed focus points of images; they take effect with this save. */
|
||||
imageFocus: HeroImageFocusRequest[];
|
||||
|
||||
@@ -634,13 +634,6 @@
|
||||
"label": "Button {{n}}: text",
|
||||
"target": "Button {{n}}: target"
|
||||
},
|
||||
"schedule": {
|
||||
"title": "Schedule",
|
||||
"active": "Hero is switched on",
|
||||
"starts": "Visible from",
|
||||
"ends": "Visible until",
|
||||
"hint": "Outside this period, or when the hero is switched off, the website keeps its standard hero."
|
||||
},
|
||||
"slides": {
|
||||
"title": "Images",
|
||||
"add": "Add image",
|
||||
@@ -717,8 +710,7 @@
|
||||
"buttonIncomplete": "Fill in both the text and the target of the button, or leave both empty.",
|
||||
"buttonTargetInvalid": "Choose a part of the page (for example #contact), a page of the site (for example /privacy) or a full web address (https://…).",
|
||||
"altTooLong": "The description can have at most 300 characters.",
|
||||
"altRequired": "Give a description or choose ‘Decoration only’.",
|
||||
"endAfterStart": "The end must be after the start."
|
||||
"altRequired": "Give a description or choose ‘Decoration only’."
|
||||
},
|
||||
"upload": {
|
||||
"tooLarge": "The image is too large (at most {{max}} MB).",
|
||||
@@ -762,10 +754,6 @@
|
||||
"focus": {
|
||||
"name": "Focus",
|
||||
"text": "Show where the subject is in the photo, so a crop never cuts it off. For portrait screens, such as a phone, you can choose a separate point."
|
||||
},
|
||||
"schedule": {
|
||||
"name": "Schedule",
|
||||
"text": "The hero is only visible in the period from–until. Outside that period the website keeps its standard hero."
|
||||
}
|
||||
},
|
||||
"unsaved": {
|
||||
|
||||
@@ -634,13 +634,6 @@
|
||||
"label": "Knop {{n}}: tekst",
|
||||
"target": "Knop {{n}}: doel"
|
||||
},
|
||||
"schedule": {
|
||||
"title": "Planning",
|
||||
"active": "Hero is aangezet",
|
||||
"starts": "Zichtbaar vanaf",
|
||||
"ends": "Zichtbaar tot",
|
||||
"hint": "Buiten deze periode, of als de hero is uitgezet, blijft de standaard hero van de website staan."
|
||||
},
|
||||
"slides": {
|
||||
"title": "Afbeeldingen",
|
||||
"add": "Afbeelding toevoegen",
|
||||
@@ -717,8 +710,7 @@
|
||||
"buttonIncomplete": "Vul zowel de tekst als het doel van de knop in, of laat beide leeg.",
|
||||
"buttonTargetInvalid": "Kies een onderdeel van de pagina (bijvoorbeeld #contact), een pagina van de site (bijvoorbeeld /privacy) of een volledig webadres (https://…).",
|
||||
"altTooLong": "De beschrijving mag maximaal 300 tekens bevatten.",
|
||||
"altRequired": "Geef een beschrijving of kies ‘Alleen versiering’.",
|
||||
"endAfterStart": "Het einde moet na het begin liggen."
|
||||
"altRequired": "Geef een beschrijving of kies ‘Alleen versiering’."
|
||||
},
|
||||
"upload": {
|
||||
"tooLarge": "De afbeelding is te groot (maximaal {{max}} MB).",
|
||||
@@ -762,10 +754,6 @@
|
||||
"focus": {
|
||||
"name": "Focus",
|
||||
"text": "Geef aan waar het onderwerp op de foto staat, zodat een uitsnede er niets van afhakt. Voor staande schermen, zoals een telefoon, kun je een apart punt kiezen."
|
||||
},
|
||||
"schedule": {
|
||||
"name": "Planning",
|
||||
"text": "De hero is alleen zichtbaar in de periode van–tot. Buiten die periode blijft de standaard hero van de website staan."
|
||||
}
|
||||
},
|
||||
"unsaved": {
|
||||
|
||||
Reference in New Issue
Block a user