feat(manager): the menu board editor and widgets (platform-v2 step 5.6b)

- Menu board: everything or chosen whole categories (sub-categories
  included, new products join) plus single products found by search; hide a
  product from the board (and show it again); the board's own order with
  arrows on what the server resolved (categories and products; boardOrder
  writes it); a badge per product; grouping, headings, photos, descriptions,
  whose prices (a sales point or none), sold out crossed out or hidden,
  columns, products per page (or as many as fit), seconds per page; colours,
  font, size, background.
- Widgets (text and menu slides): logo, venue name, date (long / short),
  clock (seconds), message of the day (or its own text), QR code (ordering /
  QR menu / a link + caption), weather (1-3 days, says it needs internet);
  where (corners, bars) and size.
- The preview stays in view while the settings scroll.
- @xenia/signage: the venue clock's Intl call names its time zone where the
  i18n guard reads it.
- tests: manager signage.test.mjs +1; e2e signage.mjs builds a menu board in
  the editor (categories, a single product, the order, a badge, hiding, a
  clock) and checks what was saved and resolved.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This commit is contained in:
2026-11-17 22:16:49 +02:00
co-authored by Claude Opus 5.5
parent 152388321e
commit 5f6b51fb8b
11 changed files with 509 additions and 20 deletions
@@ -0,0 +1,77 @@
// The widgets of a text or menu slide (plan step 5.6b): logo, name, date, clock, message of the
// day, QR code, weather; each in a corner or a bar, small / medium / large, with its own options.
// Up to 10 (the server's limit).
import { Plus, Trash2 } from 'lucide-react'
import { useTranslation } from '@xenia/i18n'
import { Button, Field, IconButton, Input, Select, Switch } from '@xenia/ui'
import { MediaPick } from './SignageFields'
import { WIDGET_KINDS, WIDGET_POSITIONS } from './signageLogic'
export default function WidgetsEditor({ widgets = [], onChange, media, onMedia }) {
const { t } = useTranslation('manager')
const set = (i, patch) => onChange(widgets.map((w, j) => (j === i ? { ...w, ...patch } : w)))
const add = kind => onChange([...widgets, { kind, position: kind === 'message' ? 'bottom-bar' : 'top-right', size: 'medium' }])
return (
<fieldset className="grid gap-3 rounded-control border border-line p-3" data-testid="signage-widgets">
<legend className="px-1 text-label font-medium text-ink-2">{t('signage.widgets.title')}</legend>
{widgets.length === 0 && <p className="text-caption text-ink-3">{t('signage.widgets.none')}</p>}
{widgets.map((w, i) => (
<div key={i} className="grid gap-2 rounded-control bg-surface-2 p-2" data-testid="signage-widget" data-kind={w.kind}>
<div className="flex flex-wrap items-end gap-2">
<span className="text-label font-medium text-ink min-w-[6rem] pb-2">{t(`signage.widgets.kinds.${w.kind}`)}</span>
<Field label={t('signage.widgets.position')} className="flex-1 min-w-[9rem]">
<Select value={w.position} onChange={e => set(i, { position: e.target.value })} data-testid="signage-widget-position"
options={WIDGET_POSITIONS.map(p => ({ value: p, label: t(`signage.widgets.positions.${p}`) }))} />
</Field>
<Field label={t('signage.widgets.size')}>
<Select value={w.size || 'medium'} onChange={e => set(i, { size: e.target.value })}
options={['small', 'medium', 'large'].map(s => ({ value: s, label: t(`signage.widgets.sizes.${s}`) }))} />
</Field>
<IconButton variant="ghost" label={t('fees.delete')} onClick={() => onChange(widgets.filter((_, j) => j !== i))} data-testid="signage-widget-remove"><Trash2 size={16} /></IconButton>
</div>
{w.kind === 'logo' && (
<MediaPick kind="image" value={w.media_id} entry={media[String(w.media_id)]} testid="signage-widget-logo"
onChange={item => { onMedia(item); set(i, { media_id: item.id }) }} />
)}
{w.kind === 'message' && (
<Field label={t('signage.widgets.ownText')} hint={t('signage.widgets.ownTextHint')}>
<Input value={w.text || ''} maxLength={200} onChange={e => set(i, { text: e.target.value || null })} data-testid="signage-widget-text" />
</Field>
)}
{w.kind === 'date' && (
<Select value={w.date_style || 'long'} onChange={e => set(i, { date_style: e.target.value })} aria-label={t('signage.widgets.kinds.date')}
options={[{ value: 'long', label: t('signage.widgets.dateLong') }, { value: 'short', label: t('signage.widgets.dateShort') }]} />
)}
{w.kind === 'clock' && <Switch checked={!!w.clock_seconds} onChange={on => set(i, { clock_seconds: on })} label={t('signage.widgets.seconds')} />}
{w.kind === 'qr' && (
<div className="grid gap-2 sm:grid-cols-2">
<Field label={t('display.qrTarget')}>
<Select value={w.qr_target || 'ordering'} onChange={e => set(i, { qr_target: e.target.value })}
options={['ordering', 'menu', 'custom'].map(q => ({ value: q, label: t(`display.qrTargets.${q}`) }))} />
</Field>
{w.qr_target === 'custom' && (
<Field label={t('display.qrUrl')}><Input value={w.qr_url || ''} placeholder="https://" onChange={e => set(i, { qr_url: e.target.value || null })} /></Field>
)}
<Field label={t('display.qrCaption')}><Input value={w.qr_caption || ''} maxLength={80} onChange={e => set(i, { qr_caption: e.target.value || null })} /></Field>
</div>
)}
{w.kind === 'weather' && (
<div className="grid gap-1">
<Select value={String(w.weather_days || 1)} onChange={e => set(i, { weather_days: Number(e.target.value) })} aria-label={t('signage.widgets.weatherDays')}
options={[1, 2, 3].map(n => ({ value: String(n), label: t('signage.widgets.days', { count: n }) }))} />
<p className="text-caption text-ink-3">{t('signage.widgets.weatherNeedsInternet')}</p>
</div>
)}
</div>
))}
{widgets.length < 10 && (
<div className="flex flex-wrap gap-1.5">
{WIDGET_KINDS.map(k => (
<Button key={k} size="sm" variant="secondary" icon={<Plus size={14} />} onClick={() => add(k)} data-testid={`signage-widget-add-${k}`}>
{t(`signage.widgets.kinds.${k}`)}</Button>
))}
</div>
)}
</fieldset>
)
}