// Orders from the table's menu tablet that wait for a waiter (plan step 6.6, D-30): when the // venue (or the tablet) says a waiter confirms tablet orders first, they show here on the table, // with what the guests chose and their note. Accept sends it to the table's order and the // kitchen; Decline tells the tablet, with a reason the guests see. Refreshes on the live event // `tablet_order_updated` and after a reconnect. Shows nothing when none wait. import { useCallback, useEffect, useState } from 'react' import { useCan, useModule } from '@xenia/access' import { useTranslation } from '@xenia/i18n' import client from '../api/client' import { apiError } from '../api/errors' import { money } from '../i18n' export default function TabletRequests({ tableId }) { const { t } = useTranslation('waiter') const moduleOn = useModule('menu_tablet') const canOpen = useCan('ordering.orders.open') const on = moduleOn && canOpen const [list, setList] = useState([]) const [declining, setDeclining] = useState(null) const [reason, setReason] = useState('') const [busy, setBusy] = useState(null) const [problem, setProblem] = useState(null) const load = useCallback(async () => { if (!on) return try { setList((await client.get('/api/menu-tablet/requests', { params: { table_id: tableId } })).data) } catch { /* offline: keep */ } }, [on, tableId]) useEffect(() => { const first = setTimeout(load, 0) const onEvent = e => { if (['tablet_order_updated', 'ready'].includes(e.detail?.type) && (!e.detail?.data?.table_id || e.detail.data.table_id === tableId)) load() } window.addEventListener('live-event', onEvent) window.addEventListener('live-reconnected', load) return () => { clearTimeout(first); window.removeEventListener('live-event', onEvent); window.removeEventListener('live-reconnected', load) } }, [load, tableId]) const answer = async (id, action, body) => { setBusy(id) setProblem(null) try { await client.post(`/api/menu-tablet/requests/${id}/${action}`, body ?? {}) setDeclining(null) await load() } catch (err) { setProblem(apiError(err, t('tabletOrder.title'))) } finally { setBusy(null) } } if (!on || list.length === 0) return null return (
{list.map(r => (
📱 {t('tabletOrder.title')}
{t('tabletOrder.body')}
{r.lines.map((l, i) => (
{l.quantity}× {l.name}{l.entries?.length ? · {l.entries.join(', ')} : null} {money(l.total)}
))}
{r.note &&
{t('tabletOrder.note', { note: r.note })}
} {declining === r.id ? (
) : (
)}
))} {problem &&
{problem}
}
) }