feat(signage): reviews typed in by hand and their widget; Add a widget at the top of the widgets, the list in layers (new widgets on top)

Reviews (name, stars, text, date, where) under Signage -> Message & settings, shown
one at a time by the reviews widget (a minimum of stars, seconds each); not pulled
from Google (owner's choice). The widgets section: one "Add a widget" menu at its
top instead of a button per kind; the cards are layers, the top one drawn over the
others, so a new widget goes on top; the arrows bring forward / send backward.
Plan 6R.19, F-113.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This commit is contained in:
2026-11-22 14:21:17 +02:00
co-authored by Claude Opus 5.5
parent f26e51273c
commit 189bd2777b
14 changed files with 339 additions and 52 deletions
@@ -1,11 +1,13 @@
// The settings of the widgets added in 6R.15 (owner 2026-11-22): a shape, a scrolling text, a
// countdown, the opening hours, the guests' Wi-Fi and the contact details. The last three read the
// countdown, the opening hours, the guests' Wi-Fi and the contact details; the reviews (6R.19). The last three read the
// venue (Settings → Identity, the Schedule page's opening hours): when that is missing the card says
// so with a link to where it is set. Used by WidgetsEditor (its row and the part under it).
import { useEffect, useState } from 'react'
import { Link } from 'react-router-dom'
import { useTranslation } from '@xenia/i18n'
import { ColourField, Dropdown, Field, Input, Notice, NumberInput, Segmented, Slider, Switch } from '@xenia/ui'
import { useHours, useIdentity } from '../../shell/useIdentity'
import * as api from './signageApi'
import { CONTACT_KEYS, WIDGET_COLOURS } from './signageLogic'
const SHAPES = ['rectangle', 'circle', 'triangle', 'polygon', 'star', 'custom']
@@ -77,6 +79,17 @@ export function MoreInlineFields({ w, set }) {
</Field>
)
}
if (w.kind === 'reviews') {
return (<>
<Field label={t(`${k}.reviews.min`)}>
<Segmented fill value={w.reviews_min || 4} onChange={reviews_min => set({ reviews_min })} data-testid="signage-widget-reviews-min"
options={[1, 2, 3, 4, 5].map(n => ({ value: n, label: `${n}+` }))} />
</Field>
<Field label={t(`${k}.reviews.seconds`)}>
<NumberInput value={w.reviews_seconds ?? 8} min={3} max={120} suffix="s" onChange={v => set({ reviews_seconds: v ?? 3 })} />
</Field>
</>)
}
if (w.kind === 'contact') {
return (
<Field label={t(`${k}.contact.shows`)} className="col-span-2">
@@ -159,6 +172,17 @@ export function MoreBelowFields({ w, set }) {
</div>
)
}
if (w.kind === 'reviews') {
return (
<div className="grid gap-3">
<div className="flex gap-2 flex-wrap">
<Switch boxed className="h-control" checked={w.reviews_stars !== false} onChange={on => set({ reviews_stars: on })} label={t(`${k}.reviews.stars`)} />
<Switch boxed className="h-control" checked={w.reviews_name !== false} onChange={on => set({ reviews_name: on })} label={t(`${k}.reviews.name`)} />
</div>
<ReviewsNote />
</div>
)
}
if (w.kind === 'wifi' || w.kind === 'contact') {
const missing = w.kind === 'wifi' ? identity && !identity.wifi?.ssid : identity && !(w.contact_fields || ['phone', 'website', 'instagram']).some(x => identity.contact?.[x])
return missing
@@ -171,3 +195,14 @@ export function MoreBelowFields({ w, set }) {
}
return null
}
/** Where the reviews come from, or a warning (with the way there) while there are none. */
function ReviewsNote() {
const { t } = useTranslation('manager')
const [count, setCount] = useState(null)
useEffect(() => { api.getReviews().then(r => setCount(r.reviews.length)).catch(() => {}) }, [])
const link = <Link to="/management/signage?tab=settings" className="text-accent-ink font-medium underline">{t('signage.widgets.reviews.where')}</Link>
return count === 0
? <Notice tone="warning" title={t('signage.widgets.reviews.missing')} data-testid="signage-widget-reviews-missing">{link}</Notice>
: <p className="text-caption text-ink-3 -mt-2">{t('signage.widgets.reviews.hint')} {link}</p>
}
@@ -0,0 +1,79 @@
// The venue's reviews (6R.19, owner 2026-11-22), under Signage → Message & settings: typed in by hand
// (who, stars, what they wrote, when, where it was posted) and shown one at a time by the reviews
// widget. Not pulled from Google (the owner's choice: no API key, no billing). Saved all at once.
import { useEffect, useMemo, useState } from 'react'
import toast from 'react-hot-toast'
import { ArrowDown, ArrowUp, Plus, Star, Trash2 } from 'lucide-react'
import { errorMessage } from '@xenia/api'
import { useTranslation } from '@xenia/i18n'
import { Button, Field, FieldRow, IconButton, Input, Segmented, Spinner, Textarea } from '@xenia/ui'
import * as api from './signageApi'
import { moved } from './signageLogic'
const clean = list => list.map(r => ({ name: r.name.trim(), stars: r.stars, text: r.text.trim(), date: r.date || null, source: (r.source || '').trim() || null }))
export default function ReviewsSettings() {
const { t } = useTranslation('manager')
const [saved, setSaved] = useState(null)
const [list, setList] = useState(null)
const [busy, setBusy] = useState(false)
useEffect(() => {
api.getReviews().then(r => { setSaved(r.reviews); setList(r.reviews) }).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((r, j) => (j === i ? { ...r, ...patch } : r)))
const bad = list.some(r => !r.name?.trim() || !r.text?.trim())
const save = async () => {
setBusy(true)
try { const r = await api.putReviews(clean(list)); setSaved(r.reviews); setList(r.reviews); 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-reviews">
<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.reviews.title')}</h2>
<p className="text-label text-ink-2">{t('signage.reviews.hint')}</p>
</div>
<Button variant="secondary" disabled={!dirty || busy} onClick={() => setList(saved)}>{t('signage.undo')}</Button>
<Button loading={busy} disabled={!dirty || bad} onClick={save} data-testid="signage-reviews-save">{t('fees.save')}</Button>
</div>
{list.length === 0 && <p className="text-label text-ink-3">{t('signage.reviews.none')}</p>}
<div className="grid gap-2">
{list.map((r, i) => (
<div key={i} className="grid gap-2 rounded-control border border-line bg-surface-2 p-3" data-testid="signage-review-row">
<div className="flex items-center gap-2">
<Segmented value={r.stars} onChange={stars => set(i, { stars })} aria-label={t('signage.reviews.stars')} data-testid="signage-review-stars"
options={[1, 2, 3, 4, 5].map(n => ({ value: n, label: String(n), icon: <Star size={14} aria-hidden="true" /> }))} />
<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={() => setList(l => l.filter((_, j) => j !== i))}><Trash2 size={14} /></IconButton>
</div>
<Field label={t('signage.reviews.text')} error={!r.text?.trim() ? ' ' : undefined}>
<Textarea rows={2} value={r.text} maxLength={400} onChange={e => set(i, { text: e.target.value })} data-testid="signage-review-text" />
</Field>
<FieldRow className="-mx-3 -mb-3" min="11rem">
<Field label={t('signage.reviews.name')} error={!r.name?.trim() ? ' ' : undefined}>
<Input value={r.name} maxLength={60} onChange={e => set(i, { name: e.target.value })} data-testid="signage-review-name" />
</Field>
<Field label={t('signage.reviews.source')}>
<Input value={r.source || ''} maxLength={40} placeholder="Google" onChange={e => set(i, { source: e.target.value })} />
</Field>
<Field label={t('signage.reviews.date')}>
<Input type="date" value={r.date || ''} onChange={e => set(i, { date: e.target.value || null })} />
</Field>
</FieldRow>
</div>
))}
</div>
{list.length < 100 && (
<div><Button variant="secondary" icon={<Plus size={14} />} onClick={() => setList(l => [...l, { name: '', stars: 5, text: '', date: null, source: null }])} data-testid="signage-review-add">
{t('signage.reviews.add')}
</Button></div>
)}
</section>
)
}
@@ -9,6 +9,7 @@ import { errorMessage } from '@xenia/api'
import { useFormat, useLanguage, useTranslation } from '@xenia/i18n'
import { Button, Dropdown, Field, Input, Spinner } from '@xenia/ui'
import BadgesSettings from './BadgesSettings'
import ReviewsSettings from './ReviewsSettings'
import MessageOfTheDay from './MessageOfTheDay'
import PerformanceSettings from './PerformanceSettings'
import * as api from './signageApi'
@@ -88,6 +89,7 @@ export default function SignageSettingsTab() {
</section>
<BadgesSettings />
<ReviewsSettings />
<PerformanceSettings />
</div>
)
@@ -20,12 +20,15 @@
// ("2", "2.1.0": see WidgetCanvas).
// 6R.15 (owner 2026-11-22): a shape, a scrolling text, a countdown, the opening hours, Wi-Fi and contact
// details (MoreWidgetFields).
// Owner 2026-11-22: "Add a widget" at the top of the section (a menu of every kind), and the list is
// in layers: the card at the top is the widget drawn over the others, so a new widget goes on top
// (last in the slide's list, first here); the arrows bring a widget forward / send it backward.
// Up to the venue's limit (10 recommended; Signage → Message & settings → Performance).
import { Fragment, useEffect, useRef, useState } from 'react'
import {
AlignCenter, AlignLeft, AlignRight, AlignVerticalJustifyCenter, AlignVerticalJustifyEnd, AlignVerticalJustifyStart, ArrowDown, ArrowUp, Bold, Italic, Palette, RotateCcw, Underline, BookImage, CalendarDays, ChevronDown, Clock, CloudSun, Columns3, GripVertical,
ImageIcon, LayoutList, MessageSquare, Plus, QrCode, Rows3, Store, Trash2, Type, UtensilsCrossed,
CalendarClock, Contact, MoveHorizontal, Shapes, Timer, Wifi,
CalendarClock, Contact, MessageSquareQuote, MoveHorizontal, Shapes, Timer, Wifi,
} from 'lucide-react'
import { cellWidgets, evenShares, setShare } from '@xenia/signage'
import { useTranslation } from '@xenia/i18n'
@@ -41,7 +44,8 @@ import {
} from './signageLogic'
const ICON = { logo: ImageIcon, name: Store, date: CalendarDays, clock: Clock, message: MessageSquare, text: Type, qr: QrCode, weather: CloudSun, menu: UtensilsCrossed, hstack: Columns3, vstack: Rows3,
shape: Shapes, ticker: MoveHorizontal, countdown: Timer, hours: CalendarClock, wifi: Wifi, contact: Contact }
shape: Shapes, ticker: MoveHorizontal, countdown: Timer, hours: CalendarClock, wifi: Wifi, contact: Contact, reviews: MessageSquareQuote }
const MORE_KINDS = ['shape', 'ticker', 'countdown', 'hours', 'wifi', 'contact', 'reviews'] // MoreWidgetFields
const iconOf = w => (w.kind === 'stack' ? (w.direction === 'column' ? Rows3 : Columns3) : ICON[w.kind] || LayoutList)
const kindLabel = (t, w) => t(`signage.widgets.kinds.${w.kind === 'stack' ? (w.direction === 'column' ? 'vstack' : 'hstack') : w.kind}`)
const ROW = 'grid gap-4 items-end grid-cols-[repeat(auto-fill,minmax(11rem,1fr))]'
@@ -71,11 +75,12 @@ export default function WidgetsEditor({ widgets = [], onChange, media, onMedia,
const top = selected != null && !String(selected).includes('.') ? Number(selected) : null
onSelect?.(top == null ? null : String(pickedAfterMove(top, from, to)))
}
// the cards are shown top layer first: above a card is after it in the slide's list
const over = (e, i) => {
if (!drag) return
e.preventDefault()
const r = e.currentTarget.getBoundingClientRect()
const at = e.clientY < r.top + r.height / 2 ? i : i + 1
const at = e.clientY < r.top + r.height / 2 ? i + 1 : i
if (at !== drag.at) setDrag(d => ({ ...d, at }))
}
const drop = () => {
@@ -85,16 +90,20 @@ export default function WidgetsEditor({ widgets = [], onChange, media, onMedia,
const line = i => drag && drag.at === i && drag.at !== drag.from && drag.at !== drag.from + 1 && (
<div className="h-0.5 -my-1.5 rounded-full bg-accent" data-testid="signage-widget-drop-line" aria-hidden="true" />
)
const full = widgets.length >= most
return (
<Section title={t('signage.widgets.title')} testid="signage-widgets">
<Section title={t('signage.widgets.title')} testid="signage-widgets"
aside={<AddWidgetMenu kinds={[...WIDGET_KINDS, 'hstack', 'vstack']} onPick={add} disabled={full} label={t('signage.widgets.add')} testid="signage-widget-add" />}>
<p className="text-caption text-ink-3 -mt-1">{t(widgets.length ? 'signage.widgets.dragHint' : 'signage.widgets.none')}</p>
{widgets.map((w, i) => {
{full && <p className="text-caption text-ink-3 -mt-1" data-testid="signage-widgets-full">{t('signage.widgets.full', { count: most })}</p>}
{[...widgets.keys()].reverse().map(i => {
const w = widgets[i]
const Icon = iconOf(w)
const custom = w.position === 'custom'
const on = selected != null && (String(selected) === String(i) || String(selected).startsWith(`${i}.`))
return (
<div key={i} className="grid gap-3">
{line(i)}
{line(i + 1)}
<div onPointerDown={() => onSelect?.(String(i))} onDragOver={e => over(e, i)} onDrop={drop}
className={`grid gap-4 rounded-card border p-4 transition-colors duration-fast ${on ? 'border-accent bg-accent-soft/40 ring-1 ring-accent' : 'border-line bg-surface-2'}
${drag?.from === i ? 'opacity-50' : ''}`}
@@ -106,9 +115,9 @@ export default function WidgetsEditor({ widgets = [], onChange, media, onMedia,
<Icon size={16} className="text-ink-2 shrink-0" aria-hidden="true" />
<span className="text-body font-semibold text-ink">{kindLabel(t, w)}</span>
<span className="flex-1" />
<IconButton size="sm" label={t('signage.widgets.earlier')} disabled={i === 0} onClick={e => { e.stopPropagation(); move(i, i - 1) }}
<IconButton size="sm" label={t('signage.widgets.forward')} disabled={i === widgets.length - 1} onClick={e => { e.stopPropagation(); move(i, i + 1) }}
data-testid="signage-widget-up"><ArrowUp size={16} /></IconButton>
<IconButton size="sm" label={t('signage.widgets.later')} disabled={i === widgets.length - 1} onClick={e => { e.stopPropagation(); move(i, i + 1) }}
<IconButton size="sm" label={t('signage.widgets.backward')} disabled={i === 0} onClick={e => { e.stopPropagation(); move(i, i - 1) }}
data-testid="signage-widget-down"><ArrowDown size={16} /></IconButton>
<IconButton size="sm" tone="danger" label={t('fees.delete')} data-testid="signage-widget-remove"
onClick={e => { e.stopPropagation(); onChange(widgets.filter((_, j) => j !== i)); onSelect?.(null) }}><Trash2 size={16} /></IconButton>
@@ -135,20 +144,7 @@ export default function WidgetsEditor({ widgets = [], onChange, media, onMedia,
</div>
)
})}
{line(widgets.length)}
{widgets.length < most && (
<div className="flex flex-wrap items-center gap-1.5">
{[...WIDGET_KINDS, 'hstack', 'vstack'].map(k => {
const Icon = ICON[k]
return (
<Button key={k} size="sm" variant="secondary" icon={<Plus size={14} />} onClick={() => add(k)} data-testid={`signage-widget-add-${k}`}>
<span className="inline-flex items-center gap-1.5"><Icon size={14} aria-hidden="true" />{t(`signage.widgets.kinds.${k}`)}</span>
</Button>
)
})}
</div>
)}
{widgets.length >= most && <p className="text-caption text-ink-3" data-testid="signage-widgets-full">{t('signage.widgets.full', { count: most })}</p>}
{line(0)}
</Section>
)
}
@@ -182,7 +178,7 @@ function VerticalField({ w, set }) {
}
// which widgets have text (their colour, font, style and size), a QR code's own colours, a plate
const TEXT_KINDS = ['name', 'date', 'clock', 'message', 'text', 'qr', 'weather', 'ticker', 'countdown', 'hours', 'wifi', 'contact']
const TEXT_KINDS = ['name', 'date', 'clock', 'message', 'text', 'qr', 'weather', 'ticker', 'countdown', 'hours', 'wifi', 'contact', 'reviews']
/**
* A widget's own look (owner review 5), folded under "Text and colours": its colour (text and
@@ -254,7 +250,7 @@ function MessageHint() {
/** The options only some widgets have, on the same row as where / size / alignment. */
function InlineFields({ w, set }) {
const { t } = useTranslation('manager')
if (['shape', 'ticker', 'countdown', 'hours', 'wifi', 'contact'].includes(w.kind)) return <MoreInline w={w} set={set} />
if (MORE_KINDS.includes(w.kind)) return <MoreInline w={w} set={set} />
if (w.kind === 'message') {
return (
<Field label={t('signage.widgets.ownText')} className="col-span-2">
@@ -311,7 +307,7 @@ function InlineFields({ w, set }) {
/** What needs more room, under the row: the picture, hints, the QR's own link, a menu's list, a stack's parts. */
function BelowFields({ w, set, media, onMedia, extras, path, depth, selected, onSelect }) {
const { t } = useTranslation('manager')
if (['shape', 'ticker', 'countdown', 'hours', 'wifi', 'contact'].includes(w.kind)) return <MoreBelow w={w} set={set} />
if (MORE_KINDS.includes(w.kind)) return <MoreBelow w={w} set={set} />
if (w.kind === 'logo') {
return <MediaPick kind="image" value={w.media_id} entry={media[String(w.media_id)]} testid="signage-widget-logo"
onChange={item => { onMedia(item); set({ media_id: item.id }) }} />
@@ -532,23 +528,28 @@ function ShareBar({ column, shares, labels, onChange }) {
)
}
/** "Add a widget" to a part: every widget (and a slide from the Slides library) in a small panel
* over the page; widgets add up, a slide takes the part's place. */
/** "Add a widget" to a part: every widget (and a slide from the Slides library); widgets add up, a slide takes the part's place. */
function AddToPart({ kinds, onPick }) {
const { t } = useTranslation('manager')
return <AddWidgetMenu kinds={[...kinds, 'slide']} onPick={onPick} label={t('signage.widgets.stack.add')} testid="signage-stack-add" />
}
/** "Add a widget": a button that opens every kind in a small panel over the page (the section's, owner 2026-11-22; a part's). */
function AddWidgetMenu({ kinds, onPick, label, testid, disabled = false }) {
const { t } = useTranslation('manager')
const [open, setOpen] = useState(false)
const btn = useRef(null)
const choose = k => { onPick(k); setOpen(false) }
return (
<>
<Button ref={btn} size="sm" variant="secondary" icon={<Plus size={14} />} onClick={() => setOpen(o => !o)} aria-expanded={open} aria-haspopup="menu" data-testid="signage-stack-add">
{t('signage.widgets.stack.add')}
<Button ref={btn} size="sm" variant="secondary" icon={<Plus size={14} />} disabled={disabled} onClick={() => setOpen(o => !o)} aria-expanded={open} aria-haspopup="menu" data-testid={testid}>
{label}
</Button>
<Popover open={open} anchor={btn} onClose={() => setOpen(false)} role="menu" className="w-[22rem] grid grid-cols-2 gap-1.5 p-2" data-testid="signage-stack-add-menu">
{[...kinds, 'slide'].map(k => {
<Popover open={open} anchor={btn} onClose={() => setOpen(false)} role="menu" className="w-[22rem] grid grid-cols-2 gap-1.5 p-2" data-testid={`${testid}-menu`}>
{kinds.map(k => {
const Icon = k === 'slide' ? BookImage : ICON[k]
return (
<button key={k} type="button" role="menuitem" onClick={() => choose(k)} data-testid={`signage-stack-add-${k}`}
<button key={k} type="button" role="menuitem" onClick={() => choose(k)} data-testid={`${testid}-${k}`}
className={`flex items-center gap-2 px-2.5 py-2 rounded-control text-left text-label text-ink hover:bg-surface-2 ${k === 'slide' ? 'col-span-2' : ''}`}>
<Icon size={15} className="text-ink-2 shrink-0" aria-hidden="true" />
{k === 'slide' ? t('signage.widgets.stack.aSlideInstead') : t(`signage.widgets.kinds.${k}`)}
@@ -49,6 +49,10 @@ export const refreshWeather = () => client.post('/api/signage/weather/refresh').
export const getBadges = () => client.get('/api/signage/badges').then(data)
export const putBadges = badges => client.put('/api/signage/badges', { badges }).then(data)
// the venue's reviews, typed in by hand (6R.19)
export const getReviews = () => client.get('/api/signage/reviews').then(data)
export const putReviews = reviews => client.put('/api/signage/reviews', { reviews }).then(data)
// limits that keep the TVs smooth (owner review 6): widgets per slide
export const getPerformance = () => client.get('/api/signage/performance').then(data)
export const putPerformance = body => client.put('/api/signage/performance', body).then(data)
@@ -137,9 +137,9 @@ export function mediaLookup(map) {
// ── menu boards and widgets (5.6b) ───────────────────────────────────────────
export const WIDGET_KINDS = ['logo', 'name', 'date', 'clock', 'message', 'text', 'qr', 'weather', 'menu', 'shape', 'ticker', 'countdown', 'hours', 'wifi', 'contact']
export const WIDGET_KINDS = ['logo', 'name', 'date', 'clock', 'message', 'text', 'qr', 'weather', 'menu', 'shape', 'ticker', 'countdown', 'hours', 'wifi', 'contact', 'reviews']
/** What a stack's part can show (2026-11-21): a widget, a stack one level deep, a library slide. */
export const CELL_KINDS = ['logo', 'name', 'date', 'clock', 'message', 'text', 'qr', 'weather', 'menu', 'shape', 'ticker', 'countdown', 'hours', 'wifi', 'contact']
export const CELL_KINDS = ['logo', 'name', 'date', 'clock', 'message', 'text', 'qr', 'weather', 'menu', 'shape', 'ticker', 'countdown', 'hours', 'wifi', 'contact', 'reviews']
/** A new widget of a kind ('hstack' / 'vstack': a stack side by side / one over the other), where it
* usually goes: a menu or a stack in a box of its own (they fill a box). */
@@ -152,6 +152,7 @@ export function newWidget(kind) {
return { kind, position: 'custom', size: 'custom', align: 'auto', box: { x: 55, y: 10, w: 40, h: 80 }, board: { select: 'all', columns: 1, sales_point: 'in_store' } }
}
if (kind === 'shape') return { kind, position: 'custom', size: 'custom', align: 'auto', box: { x: 40, y: 30, w: 20, h: 35 }, shape: 'rectangle', radius: 10 }
if (kind === 'reviews') return { kind, position: 'custom', size: 'custom', align: 'auto', box: { x: 25, y: 55, w: 50, h: 32 } }
return { kind, position: NEW_PLACE[kind] || 'top-right', size: 'medium', align: 'auto',
...(kind === 'text' || kind === 'ticker' ? { text: '' } : {}), ...(kind === 'countdown' ? { countdown_to: '17:00' } : {}) }
}