The page opens on the gesture the shop actually makes: changing today's hours from a phone, behind the counter. "Closed today", "opens later at" and "closes earlier at" are one tap plus a time, and each shows the hours it would produce before it is applied. The derivation is the delicate part and is pure and tested. Opening at 14:00 drops a 10:00-13:00 morning rather than keeping it, and trims the slot the new time falls inside rather than dropping it. Closing early is the mirror. Both are computed against what the day would normally be, ignoring any exception already recorded, since that is what "late" is late relative to. The upcoming list is built by resolving each of the next sixty days, not by reading the exception table. Vacations and public holidays are never materialised as rows, so the table alone would quietly omit most of what is actually in effect. Each entry is badged with the rule that produced it, and only stored exceptions offer a delete. Ranges are capped at 92 days and point at the holidays page beyond that: a typo in a year field should produce an error, not thirty thousand rows. Editing the French note clears the English one. A translation of text that has changed is worse than no translation. Three exports were removed from the actions module before committing: every export in a 'use server' file becomes a publicly callable endpoint, and those three had ended up unused. Co-Authored-By: Claude Opus 5 <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_012cSY9pVhZmJUKNN7wf1Myd
91 lines
3.2 KiB
TypeScript
91 lines
3.2 KiB
TypeScript
import { auth } from '@/lib/auth';
|
|
import { prisma } from '@/lib/db';
|
|
import { addCivilDays, toCivilDate } from '@/lib/schedule/civil';
|
|
import { loadScheduleContext, loadSettings } from '@/lib/schedule/context';
|
|
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';
|
|
|
|
export const metadata = { title: 'Changements ponctuels — ITA ITO' };
|
|
|
|
/** How far ahead the list looks. Far enough for a season, short enough to read. */
|
|
const HORIZON_DAYS = 60;
|
|
|
|
export default async function ExceptionsPage() {
|
|
const [session, settings] = await Promise.all([auth(), loadSettings()]);
|
|
const now = new Date();
|
|
const context = await loadScheduleContext(now, settings);
|
|
const today = toCivilDate(now, settings.timezone);
|
|
|
|
const stored = await prisma.scheduleException.findMany({
|
|
where: { date: { gte: new Date(`${today}T00:00:00.000Z`) } },
|
|
select: { date: true },
|
|
});
|
|
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);
|
|
|
|
return (
|
|
<main className="mx-auto max-w-3xl px-4 py-10">
|
|
<h1 className="text-2xl">Changements ponctuels</h1>
|
|
<p className="mt-2 max-w-prose text-[var(--ink-muted)]">
|
|
Une fermeture ou un horaire différent pour une date précise. Ces changements priment sur les
|
|
horaires fixes.
|
|
</p>
|
|
|
|
<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}
|
|
upcoming={upcoming}
|
|
/>
|
|
</main>
|
|
);
|
|
}
|
|
|
|
/**
|
|
* Every day ahead that departs from the reference week, whatever the cause.
|
|
*
|
|
* Built by resolving each day rather than by listing the exception table,
|
|
* because vacations and public holidays are never materialised as rows — so
|
|
* the table alone would quietly omit most of what is actually in effect.
|
|
*/
|
|
function collectUpcoming(
|
|
today: string,
|
|
context: ScheduleContext,
|
|
deletable: Set<string>,
|
|
): UpcomingDay[] {
|
|
const days: UpcomingDay[] = [];
|
|
|
|
for (let offset = 0; offset <= HORIZON_DAYS; offset += 1) {
|
|
const date = addCivilDays(today, offset);
|
|
const day = resolveCivilDay(date, context);
|
|
if (!day.isException) {
|
|
continue;
|
|
}
|
|
days.push({
|
|
date,
|
|
label: formatDateFr(date),
|
|
isToday: offset === 0,
|
|
isClosed: !day.isOpen,
|
|
hoursText: day.slots.length > 0 ? formatHoursText(day.slots) : 'Fermé',
|
|
kind: day.exceptionKind ?? 'MANUAL',
|
|
note: day.noteFr,
|
|
canDelete: deletable.has(date),
|
|
});
|
|
}
|
|
|
|
return days;
|
|
}
|