feat: let the quick schedule changes target any day, not just today
Opening later and closing earlier were fixed to today, which was an assumption rather than a requirement: closing next Thursday afternoon is the same decision as closing this one, and the shop knows about it in advance more often than not. The date is a single control and still defaults to today, so the two-click path for the most frequent case is unchanged. The usual hours differ from one weekday to the next, and "opens later" is late relative to them, so the whole sixty-day window is resolved on the server and handed over at once. Sixty small entries cost less than a round trip per change of date. The date control's accessible name is explicit: "du" alone collided with the "Du" field of the range form below it, which the end-to-end run caught as an ambiguous locator — and an ambiguous locator is an ambiguous label for anyone using a screen reader. The end-to-end suite ran before this was pushed, unlike last time. Co-Authored-By: Claude Opus 5 <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_012cSY9pVhZmJUKNN7wf1Myd
This commit is contained in:
@@ -6,7 +6,7 @@ import { formatDateFr, formatHoursText } from '@/lib/schedule/format';
|
||||
import { resolveCivilDay } from '@/lib/schedule/resolver';
|
||||
import type { ScheduleContext } from '@/lib/schedule/types';
|
||||
|
||||
import ExceptionsManager, { type UpcomingDay } from './ExceptionsManager';
|
||||
import ExceptionsManager, { type SelectableDay, type UpcomingDay } from './ExceptionsManager';
|
||||
|
||||
export const metadata = { title: 'Changements ponctuels — ITA ITO' };
|
||||
|
||||
@@ -26,11 +26,7 @@ export default async function ExceptionsPage() {
|
||||
const deletable = new Set(stored.map((row) => row.date.toISOString().slice(0, 10)));
|
||||
|
||||
const upcoming = collectUpcoming(today, context, deletable);
|
||||
|
||||
// What today would normally be, ignoring any exception already recorded:
|
||||
// that is what "opening late" is late relative to.
|
||||
const usual = resolveCivilDay(today, { ...context, exceptions: [] });
|
||||
const effective = resolveCivilDay(today, context);
|
||||
const days = collectSelectableDays(today, context);
|
||||
|
||||
return (
|
||||
<main className="mx-auto max-w-3xl px-4 py-10">
|
||||
@@ -43,17 +39,41 @@ export default async function ExceptionsPage() {
|
||||
<ExceptionsManager
|
||||
canEdit={session?.user?.role === 'admin'}
|
||||
today={today}
|
||||
todayLabel={formatDateFr(today)}
|
||||
usualSlots={usual.slots}
|
||||
usualText={usual.slots.length > 0 ? formatHoursText(usual.slots) : 'Fermé'}
|
||||
effectiveText={effective.slots.length > 0 ? formatHoursText(effective.slots) : 'Fermé'}
|
||||
todayIsException={effective.isException}
|
||||
days={days}
|
||||
upcoming={upcoming}
|
||||
/>
|
||||
</main>
|
||||
);
|
||||
}
|
||||
|
||||
/**
|
||||
* Each day the quick actions can target, with the hours it would normally
|
||||
* have.
|
||||
*
|
||||
* "Opens later" is late relative to the day's usual hours, and those differ
|
||||
* from one weekday to the next — so the whole window is resolved here rather
|
||||
* than asking the server again every time the date changes. Sixty small
|
||||
* entries cost less than a round trip per keystroke.
|
||||
*/
|
||||
function collectSelectableDays(today: string, context: ScheduleContext): SelectableDay[] {
|
||||
const withoutExceptions: ScheduleContext = { ...context, exceptions: [] };
|
||||
|
||||
return Array.from({ length: HORIZON_DAYS + 1 }, (_, offset) => {
|
||||
const date = addCivilDays(today, offset);
|
||||
const usual = resolveCivilDay(date, withoutExceptions);
|
||||
const effective = resolveCivilDay(date, context);
|
||||
|
||||
return {
|
||||
date,
|
||||
label: formatDateFr(date),
|
||||
usualSlots: usual.slots,
|
||||
usualText: usual.slots.length > 0 ? formatHoursText(usual.slots) : 'Fermé',
|
||||
effectiveText: effective.slots.length > 0 ? formatHoursText(effective.slots) : 'Fermé',
|
||||
isException: effective.isException,
|
||||
};
|
||||
});
|
||||
}
|
||||
|
||||
/**
|
||||
* Every day ahead that departs from the reference week, whatever the cause.
|
||||
*
|
||||
|
||||
Reference in New Issue
Block a user