feat(signage): venue badges, widgets' own look, widgets placed inside stacks, Save and leave, shared controls (owner review 5)

- Badges: the venue's list (setting signage.badges: names el/en, colours, an icon from a food and
  drink set) edited under Signage -> "Message & settings"; sent with the venue to screens and
  previews; several badges per product (MenuList.badges lists, a single one still read) in the
  shared multiple Dropdown; a board's badge colour / text colour override them (None = each own).
- Widgets: colour, background plate, font, bold / italic / underline, text size, QR colours;
  widgets in a stack's part get every setting, vertical alignment, and a custom box inside their
  place, picked (stack, then widget) and dragged on the preview (selection by path "2.1.0").
- Menu slides: vertical alignment of the list (board_valign); "Where the list sits" is now
  "Horizontal alignment".
- Message of the day: one component in the settings tab, on the Overview and from its widget.
- Leaving a slide with changes: "Save and leave" (ConfirmDialog altLabel).
- @xenia/ui: ColourField (with colour.js helpers), FieldRow (framed only while wrapped), Slider,
  IconPicker, Segmented multiple; native selects on the Overview and signage replaced by Dropdown,
  the device settings' colour input by ColourField.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This commit is contained in:
2026-11-21 14:17:27 +02:00
co-authored by Claude Opus 5.5
parent aaa0914778
commit aa3fe85053
51 changed files with 1378 additions and 432 deletions
@@ -0,0 +1,102 @@
// The venue's badges for menu boards (owner review 5, 2026-11-21), under Signage → Message & settings:
// each with its name in Greek and English, its colours (background, text: "Automatic" = white or
// black, whichever reads) and an icon from a set for food and drink venues. Their colours are the
// defaults: a board may give all its badges a colour of its own (Text look). Saved all at once.
import { useEffect, useMemo, useState } from 'react'
import toast from 'react-hot-toast'
import { ArrowDown, ArrowUp, Plus, Trash2 } from 'lucide-react'
import { errorMessage } from '@xenia/api'
import { useLanguage, useTranslation } from '@xenia/i18n'
import { BADGE_ICONS, badgeColours, badgeName } from '@xenia/signage'
import { Button, ColourField, Field, FieldRow, IconButton, IconPicker, Input, Spinner, useConfirm } from '@xenia/ui'
import * as api from './signageApi'
import { MENU_COLOURS, moved } from './signageLogic'
import { setBadges as shareBadges } from './useBadges'
const newKey = taken => {
let n = 1
while (taken.has(`badge-${n}`)) n++
return `badge-${n}`
}
export default function BadgesSettings() {
const { t } = useTranslation('manager')
const { language } = useLanguage()
const [saved, setSaved] = useState(null)
const [list, setList] = useState(null)
const [busy, setBusy] = useState(false)
const [confirm, confirmDialog] = useConfirm()
useEffect(() => {
api.getBadges().then(r => { setSaved(r.badges); setList(r.badges) }).catch(err => toast.error(errorMessage(err, t)))
}, [t])
const dirty = useMemo(() => JSON.stringify(list) !== JSON.stringify(saved), [list, saved])
if (!list) return <section className="rounded-card border border-line bg-surface p-4 flex justify-center"><Spinner /></section>
const set = (i, patch) => setList(l => l.map((b, j) => (j === i ? { ...b, ...patch } : b)))
const setName = (i, lang, v) => setList(l => l.map((b, j) => (j === i ? { ...b, names: { ...b.names, [lang]: v } } : b)))
const add = () => setList(l => [...l, { key: newKey(new Set(l.map(b => b.key))), names: { el: '', en: '' }, colour: MENU_COLOURS.newBadge, text_colour: null, icon: null }])
const remove = async i => {
const b = list[i]
if (await confirm({ title: t('signage.badgesSettings.removeTitle', { name: badgeName(b, language) || b.key }), body: t('signage.badgesSettings.removeBody'),
confirmLabel: t('fees.delete'), tone: 'danger', testId: 'signage-badge-remove-confirm' })) setList(l => l.filter((_, j) => j !== i))
}
const save = async () => {
if (list.some(b => !b.names?.el?.trim() && !b.names?.en?.trim())) { toast.error(t('signage.badgesSettings.needName')); return }
setBusy(true)
try {
const r = await api.putBadges(list.map(b => ({ ...b, names: Object.fromEntries(Object.entries(b.names || {}).filter(([, v]) => v?.trim())) })))
setSaved(r.badges); setList(r.badges); shareBadges(r.badges)
toast.success(t('settings.saved'))
} catch (err) { toast.error(errorMessage(err, t)) }
setBusy(false)
}
return (
<section className="rounded-card border border-line bg-surface p-4 grid gap-3" data-testid="signage-badges">
<div className="flex flex-wrap items-start gap-3">
<div className="grid gap-1 flex-1 min-w-[16rem]">
<h2 className="text-body font-semibold text-ink">{t('signage.badgesSettings.title')}</h2>
<p className="text-label text-ink-2">{t('signage.badgesSettings.hint')}</p>
</div>
<Button variant="secondary" disabled={!dirty || busy} onClick={() => setList(saved)}>{t('signage.undo')}</Button>
<Button loading={busy} disabled={!dirty} onClick={save} data-testid="signage-badges-save">{t('fees.save')}</Button>
</div>
<div className="grid gap-2">
{list.map((b, i) => {
const Icon = BADGE_ICONS[b.icon]
return (
<div key={b.key} className="grid gap-2 rounded-control border border-line bg-surface-2 p-3" data-testid="signage-badge-row" data-key={b.key}>
<div className="flex items-center gap-2">
{/* as the TV draws it */}
<span className="inline-flex items-center gap-1.5 rounded-full px-2.5 py-0.5 text-caption font-extrabold uppercase tracking-wide" style={badgeColours(b)}
data-testid="signage-badge-preview">
{Icon && <Icon size={13} strokeWidth={2.5} aria-hidden="true" />}{badgeName(b, language) || '…'}
</span>
<span className="flex-1" />
<IconButton size="sm" label={t('display.earlier')} disabled={i === 0} onClick={() => setList(l => moved(l, i, i - 1))}><ArrowUp size={14} /></IconButton>
<IconButton size="sm" label={t('display.later')} disabled={i === list.length - 1} onClick={() => setList(l => moved(l, i, i + 1))}><ArrowDown size={14} /></IconButton>
<IconButton size="sm" tone="danger" label={t('fees.delete')} onClick={() => remove(i)} data-testid="signage-badge-remove"><Trash2 size={14} /></IconButton>
</div>
<FieldRow className="-mx-3 -mb-3" min="11rem">
<Field label={t('signage.badgesSettings.nameEl')}>
<Input value={b.names?.el || ''} maxLength={24} onChange={e => setName(i, 'el', e.target.value)} data-testid="signage-badge-name-el" />
</Field>
<Field label={t('signage.badgesSettings.nameEn')}>
<Input value={b.names?.en || ''} maxLength={24} onChange={e => setName(i, 'en', e.target.value)} data-testid="signage-badge-name-en" />
</Field>
<ColourField label={t('signage.badgesSettings.colour')} value={b.colour} onChange={colour => set(i, { colour })} testId="signage-badge-bg" />
<ColourField label={t('signage.badgesSettings.text')} value={b.text_colour || badgeColours(b).color} onChange={text_colour => set(i, { text_colour })} testId="signage-badge-fg"
auto={{ label: t('signage.look.badgeTextAuto'), on: !b.text_colour, pick: () => set(i, { text_colour: null }) }} />
<IconPicker label={t('signage.badgesSettings.icon')} icons={BADGE_ICONS} value={b.icon} onChange={icon => set(i, { icon })} testId="signage-badge-icon" />
</FieldRow>
</div>
)
})}
</div>
{list.length < 30 && (
<div><Button variant="secondary" icon={<Plus size={14} />} onClick={add} data-testid="signage-badge-add">{t('signage.badgesSettings.add')}</Button></div>
)}
{confirmDialog}
</section>
)
}