feat(waiter): table bookings on the phone; shared ReasonPicker (platform-v2 step 4.8c)

- Waiter: Bookings (side drawer, for whoever has connect_orders.manage or
  reservations.manage, with the online-orders app on): requests made online are
  confirmed or declined with a reason the guest sees; confirmed ones are seated at a free
  table (its seats shown, a warning mark when the party is bigger) or cancelled / marked
  as a no-show; the food ordered ahead and its kitchen time; live updates.
- Backend: the bookings routes take reservations.manage too (require_any).
- @xenia/ui ReasonPicker + reasonText (gallery, unit test), first piece moved from the
  terminal (4.6 → 4.8): the counter's online reject and booking decline dialogs use it;
  the waiter loads @xenia/ui styles.css (the .x-* components; tokens as before).
- Tests: waiter e2e +2 (request listed with the key, confirmed and seated from the phone);
  terminal.mjs and qr_table.mjs green.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This commit is contained in:
2026-11-17 10:10:14 +02:00
co-authored by Claude Opus 5.5
parent 1e8271e370
commit f57894dcb7
16 changed files with 387 additions and 37 deletions
+2
View File
@@ -25,6 +25,7 @@ import ChatListPage from './pages/ChatListPage'
import ChatThreadPage from './pages/ChatThreadPage'
import ShiftOverviewPage from './pages/ShiftOverviewPage'
import OrderLogPage from './pages/OrderLogPage'
import BookingsPage from './pages/BookingsPage'
import { NotificationProvider } from './context/NotificationContext'
import { LiveProvider } from './context/LiveContext'
import ConnectivityBar from './components/ConnectivityBar'
@@ -504,6 +505,7 @@ function Routed() {
<Route path="/settings/favorites" element={<FavoritesSetupPage />} />
<Route path="/shift-overview" element={<ShiftOverviewPage />} />
<Route path="/order-log" element={<OrderLogPage />} />
<Route path="/bookings" element={<BookingsPage />} />
<Route path="/messages" element={<ChatListRoute />} />
<Route path="/messages/:conversationId" element={<ChatThreadPage />} />
</Route>
+18 -1
View File
@@ -275,6 +275,19 @@ const DRAWER_NAV_ITEMS = [
},
{ ...NAV_REGISTRY.orders },
{ ...NAV_REGISTRY.messages },
{
// table bookings (4.8): for whoever handles online orders or manages reservations
key: 'bookings',
label: 'nav.bookings',
href: '/bookings',
match: (loc) => loc.pathname === '/bookings',
icon: (
<svg width="22" height="22" viewBox="0 0 24 24" fill="none">
<rect x="3" y="5" width="18" height="16" rx="2" stroke="currentColor" strokeWidth="2"/>
<path d="M3 10h18M8 3v4M16 3v4M9 15l2 2 4-4" stroke="currentColor" strokeWidth="2" strokeLinecap="round" strokeLinejoin="round"/>
</svg>
),
},
{
key: 'shift-overview',
label: 'nav.shiftSummary',
@@ -375,6 +388,10 @@ function SideDrawer({ open, onClose }) {
const { t } = useTranslation('waiter')
const navigate = useNavigate()
const chatOn = useChatOn()
const bookingsModule = useModule('connect_orders')
const bookingsOnline = useCan('connect_orders.manage')
const bookingsManage = useCan('reservations.manage')
const bookingsOn = bookingsModule && (bookingsOnline || bookingsManage)
const location = useLocation()
const { activeZoneTab, setActiveZoneTab } = useTableViewStore()
@@ -425,7 +442,7 @@ function SideDrawer({ open, onClose }) {
<div style={{ fontSize: 10, fontWeight: 700, color: 'var(--muted)', textTransform: 'uppercase', letterSpacing: 1, padding: '4px 10px 8px' }}>
{t('shell.navigation')}
</div>
{DRAWER_NAV_ITEMS.filter(shown(chatOn)).map(item => {
{DRAWER_NAV_ITEMS.filter(shown(chatOn)).filter(item => item.key !== 'bookings' || bookingsOn).map(item => {
const isStandaloneActive = location.pathname === '/tables' && activeZoneTab === 'standalone'
const active = item.key === 'standalone'
? isStandaloneActive
+1 -1
View File
@@ -1,6 +1,6 @@
import { StrictMode } from 'react'
import { createRoot } from 'react-dom/client'
import '@xenia/ui/tokens.css' // shared --x-* tokens: the waiter's --bg/--text… are made of them (4.6)
import '@xenia/ui/styles.css' // shared --x-* tokens (the waiter's --bg/--text… are made of them, 4.6) + the .x-* components (4.8)
import './index.css'
// The theme before anything renders (no light flash on a dark phone): the user's light/dark
+183
View File
@@ -0,0 +1,183 @@
import { useCallback, useEffect, useState } from 'react'
import { useFormat, useTranslation } from '@xenia/i18n'
import { ReasonPicker, reasonText } from '@xenia/ui'
import AppShell from '../components/AppShell'
import client from '../api/client'
import { apiError } from '../api/errors'
import db from '../db/posdb'
// Table bookings on the phone (plan step 4.8), the counter's flow (terminal BookingPanel):
// requests made online are confirmed or declined (the guest sees the answer and the reason);
// today's confirmed bookings are seated at a free table (their food's order moves there) or
// cancelled / marked as a no-show. For whoever handles online orders or manages reservations.
const DECLINE_REASONS = ['full', 'closed', 'party']
const OPEN = ['open', 'partially_paid', 'paid']
export default function BookingsPage() {
const { t } = useTranslation('waiter')
const [data, setData] = useState(null)
const [error, setError] = useState('')
const [busy, setBusy] = useState(null)
const [declining, setDeclining] = useState(null)
const [free, setFree] = useState([])
const load = useCallback(async () => {
try {
const r = await client.get('/api/connect/bookings')
setData(r.data)
setError('')
} catch (err) { setError(apiError(err, t('bookings.loadFailed'))) }
try {
const [tables, orders] = await Promise.all([db.pos_tables.toArray(), db.pos_orders.toArray()])
const busyTables = new Set(orders.filter(o => OPEN.includes(o.status)).map(o => o.table_id))
setFree(tables.filter(tb => tb.is_active !== false && !busyTables.has(tb.id)))
} catch { setFree([]) }
}, [t])
useEffect(() => {
load()
const onLive = e => { if (['reservation_updated', 'order_updated', 'online_reservation'].includes(e.detail?.type)) load() }
window.addEventListener('live-event', onLive)
window.addEventListener('live-reconnected', load)
return () => { window.removeEventListener('live-event', onLive); window.removeEventListener('live-reconnected', load) }
}, [load])
async function run(booking, path, body) {
setBusy(booking.id)
setError('')
try {
await client.post(`/api/connect/bookings/${booking.id}/${path}`, body ?? {})
setDeclining(null)
} catch (err) { setError(apiError(err, t('bookings.failed'))) } finally {
setBusy(null)
load()
}
}
const requested = data?.requested ?? []
const upcoming = data?.upcoming ?? []
return (
<AppShell title={t('bookings.title')}>
<div style={{ padding: '12px 12px 96px', display: 'flex', flexDirection: 'column', gap: 10 }} data-testid="bookings">
{error && <p className="error-msg" role="alert">{error}</p>}
{!data && !error && <p style={{ textAlign: 'center', color: 'var(--muted)', padding: 24 }}>{t('common.loading')}</p>}
{data && (
<>
<h2 style={sectionTitle}>{t('bookings.requests', { count: requested.length })}</h2>
{requested.length === 0 && <p style={empty}>{t('bookings.noRequests')}</p>}
{requested.map(b => (
<BookingCard key={b.id} booking={b}>
<div style={{ display: 'flex', gap: 8 }}>
<button className="btn btn--accent" style={{ flex: 1 }} disabled={busy === b.id} onClick={() => run(b, 'confirm')} data-testid="booking-confirm">
{t('bookings.confirm')}
</button>
<button className="btn btn--secondary" style={{ flex: 1 }} disabled={busy === b.id} onClick={() => setDeclining(b)} data-testid="booking-decline">
{t('bookings.decline')}
</button>
</div>
</BookingCard>
))}
<h2 style={{ ...sectionTitle, marginTop: 12 }}>{t('bookings.upcoming', { count: upcoming.length })}</h2>
{upcoming.length === 0 && <p style={empty}>{t('bookings.noUpcoming')}</p>}
{upcoming.map(b => (
<BookingCard key={b.id} booking={b}>
<SeatControls booking={b} free={free} busy={busy === b.id} onSeat={tableId => run(b, 'arrive', { table_id: tableId })}
onCancel={status => run(b, 'cancel', { status })} />
</BookingCard>
))}
</>
)}
</div>
{declining && <DeclineSheet booking={declining} busy={busy === declining.id} onClose={() => setDeclining(null)} onDecline={reason => run(declining, 'decline', { reason })} />}
</AppShell>
)
}
const sectionTitle = { fontSize: 12, fontWeight: 700, color: 'var(--muted)', textTransform: 'uppercase', letterSpacing: 0.6, margin: '4px 2px 0' }
const empty = { color: 'var(--muted)', fontSize: 14, padding: '6px 2px' }
function BookingCard({ booking: b, children }) {
const { t } = useTranslation('waiter')
const { formatTime, formatDate, formatDateTime, formatMoney } = useFormat()
const today = formatDate(b.reserved_for) === formatDate(new Date())
return (
<div data-testid="booking-card" data-booking={b.id} data-status={b.status}
style={{ background: 'var(--bg2)', border: '1px solid var(--border)', borderRadius: 14, padding: 14, display: 'flex', flexDirection: 'column', gap: 8 }}>
<div style={{ display: 'flex', alignItems: 'baseline', gap: 8 }}>
<span style={{ fontSize: 17, fontWeight: 800, color: 'var(--text)', flex: 1 }}>
{today ? t('bookings.today', { time: formatTime(b.reserved_for) }) : formatDateTime(b.reserved_for, 'datetimeShort')}
</span>
{b.ref && <span style={{ fontSize: 12, color: 'var(--muted)' }}>{b.ref}</span>}
</div>
<div style={{ fontSize: 15, fontWeight: 700, color: 'var(--text)' }}>
{b.guest_name} · {t('bookings.people', { count: b.party_size })}
{b.table_label && <span style={{ color: 'var(--muted)', fontWeight: 500 }}> · {b.table_label}</span>}
</div>
{b.phone && <a href={`tel:${b.phone}`} style={{ fontSize: 14, color: 'var(--accent)' }}>{b.phone}</a>}
{b.note && <div style={{ fontSize: 13, color: 'var(--x-warning-ink)', background: 'var(--x-warning-soft)', borderRadius: 8, padding: '6px 10px' }}>{b.note}</div>}
{b.lines?.length > 0 && (
<div style={{ fontSize: 13, color: 'var(--text2)', borderTop: '1px solid var(--border)', paddingTop: 6 }}>
<div style={{ fontWeight: 700, marginBottom: 2 }}>
{b.order_id ? t('bookings.foodSent') : b.fire_at ? t('bookings.foodAt', { time: formatTime(b.fire_at) }) : t('bookings.foodOnConfirm')}
</div>
{b.lines.map((l, i) => <div key={i}>{l.quantity}× {l.name}</div>)}
<div style={{ fontWeight: 700, marginTop: 2 }}>{formatMoney(b.total)}</div>
</div>
)}
{children}
</div>
)
}
function SeatControls({ booking, free, busy, onSeat, onCancel }) {
const { t } = useTranslation('waiter')
const [table, setTable] = useState('')
const options = free.map(tb => ({ id: tb.id, name: tb.label || `T${tb.number}`, seats: tb.seat_count }))
return (
<div style={{ display: 'flex', flexDirection: 'column', gap: 8 }}>
<select value={table} onChange={e => setTable(e.target.value)} aria-label={t('bookings.table')} data-testid="booking-table"
style={{ height: 44, borderRadius: 10, border: '1px solid var(--border)', background: 'var(--bg3)', color: 'var(--text)', padding: '0 10px', fontSize: 15 }}>
<option value="">{t('bookings.noTable')}</option>
{options.map(o => (
<option key={o.id} value={o.id}>
{o.name}{o.seats ? ` · ${t('seats.table', { count: o.seats })}` : ''}
{o.seats && booking.party_size > o.seats ? ' ⚠' : ''}
</option>
))}
</select>
<button className="btn btn--accent" disabled={busy} onClick={() => onSeat(table ? Number(table) : null)} data-testid="booking-arrive">
{t('bookings.arrive')}
</button>
<div style={{ display: 'flex', gap: 8 }}>
<button className="btn btn--secondary" style={{ flex: 1 }} disabled={busy} onClick={() => onCancel('cancelled')} data-testid="booking-cancel">{t('bookings.cancel')}</button>
<button className="btn btn--secondary" style={{ flex: 1 }} disabled={busy} onClick={() => onCancel('no_show')} data-testid="booking-noshow">{t('bookings.noShow')}</button>
</div>
</div>
)
}
function DeclineSheet({ booking, busy, onClose, onDecline }) {
const { t } = useTranslation('waiter')
const [choice, setChoice] = useState(null)
const [other, setOther] = useState('')
const options = DECLINE_REASONS.map(r => ({ value: r, label: t(`bookings.reasons.${r}`) }))
const reason = reasonText(choice, options, other)
return (
<div className="modal-overlay" onClick={busy ? undefined : onClose}>
<div className="modal-sheet" onClick={e => e.stopPropagation()} data-testid="decline-sheet">
<div className="modal-handle" />
<h2 className="modal-title">{t('bookings.declineTitle', { name: booking.guest_name })}</h2>
<p style={{ textAlign: 'center', color: 'var(--muted)', fontSize: 13, margin: '0 0 14px' }}>{t('bookings.declineBody')}</p>
<ReasonPicker options={options} value={choice} onChange={setChoice} other={other} onOther={setOther}
otherLabel={t('bookings.reasons.other')} ariaLabel={t('bookings.reason')} testIdPrefix="decline" />
<div style={{ display: 'flex', gap: 10, marginTop: 16 }}>
<button className="btn btn--secondary" style={{ flex: 1 }} onClick={onClose} disabled={busy}>{t('common.back')}</button>
<button className="btn btn--danger" style={{ flex: 1 }} disabled={!reason || busy} onClick={() => onDecline(reason)} data-testid="decline-confirm">
{t('bookings.decline')}
</button>
</div>
</div>
</div>
)
}