Two things the shop asked for, and one it will notice. **A message on an exception.** A closure or a late opening can now carry a reason, and it reaches the panel. It shows while the door is shut and disappears the moment the shop opens — a notice explaining a late opening is worse than useless once the door is open. It outranks a free message on purpose: "closed this afternoon, back tomorrow" is what someone standing outside needs, and "new collection in store" can wait. Say so if you would rather it were the other way. The first version keyed this off the day's `isOpen`, which means "this day has opening hours" — so a day opening at 14:00 counted as open all morning, exactly when the reason is needed. A test caught it; the rule now reads the state at this minute. **Reusable phrases.** The same handful of notices get written over and over. /admin/modeles keeps them, translated once, and offers them wherever a message is composed — exceptions, closure periods, the banner. Picking one costs no translation at all: the saved English is reused directly, where the service takes the better part of ten seconds. Exception notes and holiday labels are translated too, which they were not before. After the save rather than during it, so a slow service never costs the shop its dates. **Previewing the future.** The dashboard can render the panel at any moment within about a year: "what will the window say while I'm away?" is worth answering before someone is standing in front of a locked door. The whole pipeline was already a function of "now", so this costs passing a different instant. An unparseable or absurd value falls back to the present rather than confidently rendering nonsense. Checked against a three-week holiday, which surfaced something worth knowing: the automatic "opens on…" line stays empty, because the resolver's search is bounded to fourteen days. During a long closure the message is the only thing that tells customers when the shop is back — which is a good reason for this feature to exist. Co-Authored-By: Claude Opus 5 <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_012cSY9pVhZmJUKNN7wf1Myd
88 lines
2.7 KiB
TypeScript
88 lines
2.7 KiB
TypeScript
/**
|
||
* The screen payload contract.
|
||
*
|
||
* This is the frozen boundary of the whole system: the resolver fills it, the
|
||
* renderer reads it, and a snapshot test pins it. Every string the panel shows
|
||
* is computed here, server-side — the renderer performs no business logic, it
|
||
* only draws. That is what makes the display testable without a device.
|
||
*
|
||
* Bump SCREEN_SCHEMA_VERSION when the shape changes, never silently.
|
||
*/
|
||
|
||
export const SCREEN_SCHEMA_VERSION = 1;
|
||
|
||
/**
|
||
* How much free text the bottom banner can hold before it stops fitting.
|
||
* Shared by the message editor's counter and the renderer, so the warning the
|
||
* user sees and the space actually available can never drift apart.
|
||
*/
|
||
export const MESSAGE_MAX_CHARS = 120;
|
||
|
||
export type ScreenStatus = 'OPEN' | 'CLOSED' | 'CLOSING_SOON' | 'OPENING_SOON';
|
||
|
||
/**
|
||
* Where the banner text came from: the reason written on today's exception,
|
||
* a free message somebody composed, or the automatic notice raised when the
|
||
* week departs from the reference schedule.
|
||
*/
|
||
export type ScreenBannerKind = 'EXCEPTION' | 'MESSAGE' | 'SCHEDULE_TODAY' | 'SCHEDULE_WEEK';
|
||
|
||
export type ScreenToday = {
|
||
date_fr: string;
|
||
date_en: string;
|
||
status: ScreenStatus;
|
||
/** The single word shown in very large type. */
|
||
status_fr: string;
|
||
status_en: string;
|
||
/** "10:00 – 13:00 · 14:00 – 18:30", empty when closed all day. */
|
||
hours_text: string;
|
||
/** "Ferme à 18:30" / "Ouvre demain à 10:00", empty when there is nothing ahead. */
|
||
next_change_fr: string;
|
||
next_change_en: string;
|
||
is_exception: boolean;
|
||
};
|
||
|
||
export type ScreenWeekDay = {
|
||
label_fr: string;
|
||
label_en: string;
|
||
hours_text: string;
|
||
is_today: boolean;
|
||
is_closed: boolean;
|
||
is_exception: boolean;
|
||
};
|
||
|
||
export type ScreenBanner = {
|
||
kind: ScreenBannerKind;
|
||
text_fr: string;
|
||
text_en: string;
|
||
};
|
||
|
||
export type ScreenPayload = {
|
||
schema: number;
|
||
/** ISO 8601 with the shop's UTC offset, e.g. "2026-09-20T10:15:00+02:00". */
|
||
generated_at: string;
|
||
shop_name: string;
|
||
logo_url: string;
|
||
today: ScreenToday;
|
||
/** Always seven entries, Monday through Sunday of the current week. */
|
||
week: ScreenWeekDay[];
|
||
/** `null` when the shop has nothing to say, so the week block takes the room. */
|
||
banner: ScreenBanner | null;
|
||
};
|
||
|
||
/**
|
||
* Automatic banner wording. Pre-translated on purpose: these lines must never
|
||
* depend on the translation service being reachable.
|
||
*/
|
||
export const AUTO_BANNERS: Record<'SCHEDULE_TODAY' | 'SCHEDULE_WEEK', { fr: string; en: string }> =
|
||
{
|
||
SCHEDULE_TODAY: {
|
||
fr: "Changement d'horaire aujourd'hui",
|
||
en: 'Opening hours changed today',
|
||
},
|
||
SCHEDULE_WEEK: {
|
||
fr: 'Horaires exceptionnels cette semaine',
|
||
en: 'Unusual opening hours this week',
|
||
},
|
||
};
|