feat: call a waiter from a menu tablet at a table (platform-v2 step 5.7b)

- backend: menu tablet device config `table` (ref, validated against active
  tables) and `call_waiter`; GET /api/menu-tablet/menu gives the table and
  whether it can call; POST /api/menu-tablet/call sends a `table_call` staff
  message ("Table 5: the guests call a waiter.", venue language) to the table's
  waiters (its open order's, else the zone's), at most once a minute per tablet
  (menu_tablet.call_too_soon with the seconds left; menu_tablet.no_table).
- terminal: "Call a waiter" only on a tablet at a table; "A waiter is on the
  way to table 5", then a countdown before it can call again; a failed call
  says to ask at the counter.
- waiter: the call shows with its own look and "Open the table".
- manager: tables as the choices of a device setting.
- tests: backend +2 (535 → 533 passed total), e2e menu_tablet.mjs +3.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This commit is contained in:
2026-11-18 00:04:39 +02:00
co-authored by Claude Opus 5.5
parent cc81e0a31f
commit f8d0d29d8f
19 changed files with 254 additions and 12 deletions
@@ -4,8 +4,9 @@
// compact / expanded / full view, photos, descriptions, grouped or one A–Z list, whose prices,
// sold-out style, search, one category or all, languages, back to the start after a while, light /
// dark. Keeps the last menu for offline; a menu change arrives live (`menu_tablet.changed`).
// A tablet set at a table (5.7b) can call the table's waiters (once a minute at most).
import { useCallback, useEffect, useMemo, useRef, useState } from 'react'
import { Search, X } from 'lucide-react'
import { BellRing, Search, X } from 'lucide-react'
import { useFormat, useLanguage, useTranslation } from '@xenia/i18n'
import { applyTheme, Dialog, getStoredTheme, Input } from '@xenia/ui'
import client from '../../api/client'
@@ -90,6 +91,7 @@ export default function MenuTabletApp() {
{q && <button type="button" onClick={() => setQ('')} aria-label={t('menuTablet.clear')} className="absolute right-2 top-1/2 -translate-y-1/2 p-1 text-ink-3"><X size={16} /></button>}
</div>
)}
{data.table?.can_call && <CallWaiter table={data.table} />}
{langs.length > 1 && (
<div className="flex rounded-control border border-line overflow-hidden" role="group" aria-label={t('menuTablet.language')}>
{langs.map(l => (
@@ -207,3 +209,41 @@ function Details({ product: p, cfg, onClose }) {
</Dialog>
)
}
/** "Call a waiter" (5.7b): a message to the table's waiters; then it waits before it can call again. */
function CallWaiter({ table }) {
const { t } = useTranslation('terminal')
const [state, setState] = useState({ status: 'idle', until: 0 })
const [left, setLeft] = useState(0) // seconds until it can call again
useEffect(() => {
if (state.status === 'idle') return undefined
const id = setInterval(() => {
const s = Math.max(0, Math.ceil((state.until - Date.now()) / 1000))
setLeft(s)
if (s === 0) setState({ status: 'idle', until: 0 })
}, 1000)
return () => clearInterval(id)
}, [state])
const call = async () => {
try {
const { data } = await client.post('/api/menu-tablet/call', {}, quiet)
setLeft(data.again_in)
setState({ status: 'sent', until: Date.now() + data.again_in * 1000 })
} catch (err) {
const x = err?.xenia
if (x?.code === 'menu_tablet.call_too_soon') { setLeft(x.params?.seconds || 30); setState({ status: 'sent', until: Date.now() + (x.params?.seconds || 30) * 1000 }) }
else setState({ status: 'failed', until: Date.now() + 8000 })
}
}
return (
<div className="flex items-center gap-2" data-testid="menu-call" data-status={state.status}>
{state.status === 'sent' && <span className="text-label text-success-ink" role="status" data-testid="menu-call-sent">{t('menuTablet.called', { table: table.name })}</span>}
{state.status === 'failed' && <span className="text-label text-danger-ink" role="status" data-testid="menu-call-failed">{t('menuTablet.callFailed')}</span>}
<button type="button" onClick={call} disabled={state.status === 'sent'} data-testid="menu-call-button"
className="flex items-center gap-2 px-4 py-2 rounded-control bg-accent text-accent-fg text-label font-semibold disabled:opacity-50 whitespace-nowrap">
<BellRing size={18} aria-hidden="true" />
{state.status === 'sent' ? t('menuTablet.callAgainIn', { seconds: left }) : t('menuTablet.call')}
</button>
</div>
)
}