feat(terminal): the customer display, with an idle screen each venue designs
Plan step 3.4. Owner (2026-11-16): the idle screen is configurable per venue. - routers/customer_display.py (module customer_display, /api/display): the counter POS pushes its state (POST /api/display/state: idle | cart | paid with lines, total, paid, change); only the displays linked to that POS get `display.state`; the last state is kept in memory for a display that reconnects (GET /api/display/state). pos_counter's device scope includes customer_display.state. - The idle screen: setting customer_display.idle (name, logo, logo + name, blank, one image, slideshow, QR code to the online ordering / QR menu / any link; a line of text; dark or light); images uploaded to /app/data/display_media (JPG/PNG/WebP/GIF ≤ 5 MB, random names, served publicly on the LAN); a change sends `display.settings` to every display. New key customer_display.manage (owners, store managers; migration 0022). - Terminal: CustomerDisplayApp (cart with a large total, "Thank you" with the change for 12 s, the venue's idle screen, its theme), logic.js (unit-tested); the POS pushes from the sale cart and the payment dialog (tables, online orders too) via useDisplay(). qrcode.react added to the terminal (already in the workspace). - Manager: Settings → Customer display (style cards, venue name, text, look, slide seconds, QR target/link/caption, image upload/pick/order/delete). - Tests: tests/test_customer_display.py (3), terminal display.test.mjs (3); e2e terminal (linked vs unlinked display, < 1 s, paid, QR and slideshow idle screens), manager (the settings tab). Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This commit is contained in:
@@ -1,5 +1,7 @@
|
||||
import { useState } from 'react'
|
||||
import { useCan, useModule } from '@xenia/access'
|
||||
import { useTranslation } from '@xenia/i18n'
|
||||
import CustomerDisplaySettings from './sections/CustomerDisplaySettings'
|
||||
import VenueSettings from './sections/VenueSettings'
|
||||
import AppInfoTab from './tabs/AppInfoTab'
|
||||
import ColoursTab from './tabs/ColoursTab'
|
||||
@@ -10,12 +12,16 @@ import DevelopmentTab from './tabs/DevelopmentTab'
|
||||
import FiscalTab from './tabs/FiscalTab'
|
||||
import { TabGroup } from '../../ui/Tabs'
|
||||
|
||||
const TABS = ['app-info', 'venue', 'security', 'operation', 'colours', 'print-fonts', 'fiscal', 'development']
|
||||
const TABS = ['app-info', 'venue', 'customer-display', 'security', 'operation', 'colours', 'print-fonts', 'fiscal', 'development']
|
||||
|
||||
export default function SettingsPage() {
|
||||
const { t } = useTranslation('manager')
|
||||
const [activeTab, setActiveTab] = useState('app-info')
|
||||
const tabs = TABS.map(id => ({ id, label: t(`settings.tabs.${id}`) }))
|
||||
// the customer display's idle screen (3.4): only where there are displays and the user sets them up
|
||||
const displayOn = useModule('customer_display')
|
||||
const displayKey = useCan('customer_display.manage')
|
||||
const display = displayOn && displayKey
|
||||
const tabs = TABS.filter(id => id !== 'customer-display' || display).map(id => ({ id, label: t(`settings.tabs.${id}`) }))
|
||||
|
||||
return (
|
||||
<div className="flex flex-col h-full min-h-0">
|
||||
@@ -23,6 +29,7 @@ export default function SettingsPage() {
|
||||
<div className="flex-1 overflow-y-auto p-6">
|
||||
{activeTab === 'app-info' && <AppInfoTab />}
|
||||
{activeTab === 'venue' && <div className="max-w-3xl"><VenueSettings /></div>}
|
||||
{activeTab === 'customer-display' && display && <div className="max-w-4xl"><CustomerDisplaySettings /></div>}
|
||||
{activeTab === 'security' && <SecurityTab />}
|
||||
{activeTab === 'operation' && <OperationTab />}
|
||||
{activeTab === 'colours' && <ColoursTab />}
|
||||
|
||||
@@ -0,0 +1,178 @@
|
||||
// Settings → Customer display (plan step 3.4). What the customer displays show between sales,
|
||||
// the venue's own style (owner, 2026-11-16): the name, the logo, both, nothing, one image, a
|
||||
// slideshow of photos, or a QR code (the venue's ordering link, its QR menu, or any link), with
|
||||
// an optional line of text, dark or light. Images are uploaded here (JPG/PNG/WebP/GIF, ≤ 5 MB).
|
||||
// Saving reaches every display at once. Backend: /api/display/settings, /api/display/media.
|
||||
import { useCallback, useEffect, useRef, useState } from 'react'
|
||||
import toast from 'react-hot-toast'
|
||||
import { Check, ImagePlus, Trash2 } from 'lucide-react'
|
||||
import { errorMessage } from '@xenia/api'
|
||||
import { useTranslation } from '@xenia/i18n'
|
||||
import { Button, Field, IconButton, Input, Select, Spinner } from '@xenia/ui'
|
||||
import client from '../../../api/client'
|
||||
import { useSettings } from './useSettings'
|
||||
|
||||
const STYLES = ['name', 'logo', 'name_logo', 'blank', 'image', 'slideshow', 'qr']
|
||||
|
||||
export default function CustomerDisplaySettings() {
|
||||
const { t } = useTranslation('manager')
|
||||
const venue = useSettings()
|
||||
const [data, setData] = useState(null)
|
||||
const [form, setForm] = useState(null)
|
||||
const [busy, setBusy] = useState(false)
|
||||
const [name, setName] = useState(null)
|
||||
const fileRef = useRef(null)
|
||||
|
||||
const load = useCallback(async () => {
|
||||
try {
|
||||
const { data: d } = await client.get('/api/display/settings')
|
||||
setData(d)
|
||||
setForm(f => f ?? d.idle)
|
||||
} catch (err) { toast.error(errorMessage(err, t)) }
|
||||
}, [t])
|
||||
useEffect(() => { load() }, [load])
|
||||
|
||||
if (!data || !form || venue.loading) return <div className="py-8 flex justify-center"><Spinner /></div>
|
||||
const set = (k, v) => setForm(f => ({ ...f, [k]: v }))
|
||||
const media = data.media
|
||||
const needs = { logo: ['logo', 'name_logo'], image: ['image'], slides: ['slideshow'], qr: ['qr'] }
|
||||
const shows = part => needs[part].includes(form.style)
|
||||
|
||||
const save = async () => {
|
||||
setBusy(true)
|
||||
try {
|
||||
const { data: d } = await client.put('/api/display/settings', form)
|
||||
setData(d)
|
||||
setForm(d.idle)
|
||||
toast.success(t('settings.saved'))
|
||||
} catch (err) { toast.error(errorMessage(err, t)) }
|
||||
setBusy(false)
|
||||
}
|
||||
const upload = async e => {
|
||||
const files = [...(e.target.files ?? [])]
|
||||
e.target.value = ''
|
||||
for (const file of files) {
|
||||
const body = new FormData()
|
||||
body.append('file', file)
|
||||
try {
|
||||
const { data: m } = await client.post('/api/display/media', body)
|
||||
setData(d => ({ ...d, media: [...d.media, m] }))
|
||||
if (form.style === 'slideshow') setForm(f => ({ ...f, slides: [...f.slides, m.name] }))
|
||||
} catch (err) { toast.error(errorMessage(err, t)) }
|
||||
}
|
||||
}
|
||||
const remove = async m => {
|
||||
try {
|
||||
await client.delete(`/api/display/media/${m.name}`)
|
||||
setData(d => ({ ...d, media: d.media.filter(x => x.name !== m.name) }))
|
||||
setForm(f => ({ ...f, logo: f.logo === m.name ? null : f.logo, image: f.image === m.name ? null : f.image,
|
||||
slides: f.slides.filter(n => n !== m.name) }))
|
||||
} catch (err) { toast.error(errorMessage(err, t)) }
|
||||
}
|
||||
const toggleSlide = n => set('slides', form.slides.includes(n) ? form.slides.filter(x => x !== n) : [...form.slides, n])
|
||||
|
||||
return (
|
||||
<section className="bg-surface border border-line rounded-card shadow-raised grid gap-5 p-5" data-testid="settings-display">
|
||||
<header className="grid gap-1">
|
||||
<h2 className="text-body font-semibold text-ink">{t('display.title')}</h2>
|
||||
<p className="text-label text-ink-2">{t('display.intro')}</p>
|
||||
</header>
|
||||
|
||||
<div className="grid gap-2" role="radiogroup" aria-label={t('display.style')}>
|
||||
<span className="text-label font-medium text-ink-2">{t('display.style')}</span>
|
||||
<div className="grid gap-2" style={{ gridTemplateColumns: 'repeat(auto-fill, minmax(10rem, 1fr))' }}>
|
||||
{STYLES.map(s => (
|
||||
<button key={s} type="button" role="radio" aria-checked={form.style === s} onClick={() => set('style', s)} data-testid={`display-style-${s}`}
|
||||
className={`p-3 rounded-control border text-left grid gap-0.5 transition-colors duration-fast
|
||||
${form.style === s ? 'border-accent bg-accent-soft text-accent-ink' : 'border-line bg-surface-2 text-ink hover:bg-surface-3'}`}>
|
||||
<span className="text-body font-medium flex items-center gap-1.5">{form.style === s && <Check size={14} aria-hidden="true" />}{t(`display.styles.${s}.name`)}</span>
|
||||
<span className="text-caption text-ink-2">{t(`display.styles.${s}.hint`)}</span>
|
||||
</button>
|
||||
))}
|
||||
</div>
|
||||
</div>
|
||||
|
||||
<div className="grid gap-3 sm:grid-cols-2">
|
||||
<div className="flex items-start gap-2">
|
||||
<Field label={t('display.venueName')} hint={t('display.venueNameHint')} className="flex-1">
|
||||
<Input value={name ?? venue.get('venue.name', '')} onChange={e => setName(e.target.value)} maxLength={80} data-testid="display-venue-name" />
|
||||
</Field>
|
||||
<Button variant="secondary" className="mt-7" disabled={name == null || venue.saving} data-testid="display-venue-name-save"
|
||||
onClick={() => { venue.save('venue.name', name.trim()); setName(null) }}>{t('fees.save')}</Button>
|
||||
</div>
|
||||
{form.style !== 'blank' && (
|
||||
<Field label={t('display.message')} hint={t('display.messageHint')}>
|
||||
<Input value={form.message ?? ''} onChange={e => set('message', e.target.value)} maxLength={120} data-testid="display-message" />
|
||||
</Field>
|
||||
)}
|
||||
<Field label={t('display.theme')}>
|
||||
<Select value={form.theme} onChange={e => set('theme', e.target.value)} data-testid="display-theme">
|
||||
<option value="dark">{t('display.themes.dark')}</option>
|
||||
<option value="light">{t('display.themes.light')}</option>
|
||||
</Select>
|
||||
</Field>
|
||||
{shows('slides') && (
|
||||
<Field label={t('display.slideSeconds')}>
|
||||
<Input inputMode="numeric" value={String(form.slide_seconds)} data-testid="display-slide-seconds"
|
||||
onChange={e => set('slide_seconds', Number(e.target.value.replace(/\D/g, '')) || 0)} />
|
||||
</Field>
|
||||
)}
|
||||
</div>
|
||||
|
||||
{shows('qr') && (
|
||||
<div className="grid gap-3 sm:grid-cols-2">
|
||||
<Field label={t('display.qrTarget')}>
|
||||
<Select value={form.qr_target} onChange={e => set('qr_target', e.target.value)} data-testid="display-qr-target">
|
||||
{['ordering', 'menu', 'custom'].map(q => <option key={q} value={q}>{t(`display.qrTargets.${q}`)}</option>)}
|
||||
</Select>
|
||||
</Field>
|
||||
{form.qr_target === 'custom' && (
|
||||
<Field label={t('display.qrUrl')}>
|
||||
<Input value={form.qr_url ?? ''} onChange={e => set('qr_url', e.target.value)} placeholder="https://" data-testid="display-qr-url" />
|
||||
</Field>
|
||||
)}
|
||||
<Field label={t('display.qrCaption')}>
|
||||
<Input value={form.qr_caption ?? ''} onChange={e => set('qr_caption', e.target.value)} maxLength={80} data-testid="display-qr-caption" />
|
||||
</Field>
|
||||
</div>
|
||||
)}
|
||||
|
||||
{(shows('logo') || shows('image') || shows('slides')) && (
|
||||
<div className="grid gap-3">
|
||||
<div className="flex items-center gap-2">
|
||||
<span className="flex-1 text-label font-medium text-ink-2">
|
||||
{t(shows('logo') ? 'display.pickLogo' : shows('image') ? 'display.pickImage' : 'display.pickSlides')}
|
||||
</span>
|
||||
<input ref={fileRef} type="file" accept="image/jpeg,image/png,image/webp,image/gif" multiple className="hidden" onChange={upload} data-testid="display-upload" />
|
||||
<Button size="sm" variant="secondary" icon={<ImagePlus size={16} />} onClick={() => fileRef.current?.click()}>{t('display.upload')}</Button>
|
||||
</div>
|
||||
{media.length === 0 ? (
|
||||
<p className="text-label text-ink-3">{t('display.noImages')}</p>
|
||||
) : (
|
||||
<ul className="grid gap-3" style={{ gridTemplateColumns: 'repeat(auto-fill, minmax(9rem, 1fr))' }} data-testid="display-media">
|
||||
{media.map(m => {
|
||||
const chosen = shows('logo') ? form.logo === m.name : shows('image') ? form.image === m.name : form.slides.includes(m.name)
|
||||
const pick = () => (shows('logo') ? set('logo', m.name) : shows('image') ? set('image', m.name) : toggleSlide(m.name))
|
||||
return (
|
||||
<li key={m.name} className={`relative rounded-control border-2 overflow-hidden ${chosen ? 'border-accent' : 'border-line'}`}>
|
||||
<button type="button" onClick={pick} aria-pressed={chosen} className="block w-full aspect-video bg-surface-2" data-testid="display-media-pick">
|
||||
<img src={m.url} alt="" className="w-full h-full object-contain" />
|
||||
</button>
|
||||
{chosen && shows('slides') && (
|
||||
<span className="absolute top-1 left-1 min-w-6 h-6 px-1 rounded-full bg-accent text-accent-fg text-caption font-bold flex items-center justify-center">
|
||||
{form.slides.indexOf(m.name) + 1}
|
||||
</span>
|
||||
)}
|
||||
<IconButton size="sm" variant="secondary" label={t('fees.delete')} className="absolute top-1 right-1" onClick={() => remove(m)}><Trash2 size={14} /></IconButton>
|
||||
</li>
|
||||
)
|
||||
})}
|
||||
</ul>
|
||||
)}
|
||||
</div>
|
||||
)}
|
||||
|
||||
<div><Button onClick={save} loading={busy} data-testid="display-save">{t('fees.save')}</Button></div>
|
||||
</section>
|
||||
)
|
||||
}
|
||||
Reference in New Issue
Block a user