// The tables now, in the manager (plan step 6.9; the map since 6.8): each table's state, total, // time open, waiters, flags and a booking kept for it soon (RESERVED). A table with an order // opens its order page; a free one opens a new order there. Quick actions set the table's flags // and can tell its waiters (or everyone) a message. Tickets that didn't print are listed below // with what can be done about them (6.10). // Everything stays current through the live events. // 2026-11-20: the toolbar is the shared one (view, state chips, zones as a multi-select), a click on // the card opens the table (no separate button), and the tables' QR codes are a view here (?view=qr; // was the page /online/qr) for whoever manages the QR menu. import { useState } from 'react' import { useNavigate, useSearchParams } from 'react-router-dom' import { Clock, LayoutGrid, Lock, Map as MapIcon, Printer, QrCode, Zap } from 'lucide-react' import { useCan, useModule } from '@xenia/access' import { useFormat, useTranslation } from '@xenia/i18n' import { Dropdown, EmptyState, FilterChip, IconButton, Page, Segmented, Spinner, Toolbar, ToolbarSpacer, cx } from '@xenia/ui' import client from '../../api/client' import { useLiveQuery } from '../../live/useLiveQuery' import LiveFloor from '../floor/LiveFloor' import { useDuration } from '../overview/hooks' import { TABLE_STATES, durationParts, orderTotal, tableCards, tableName } from '../overview/overviewLogic' import { Money, Pill } from '../overview/parts' import PrintProblemsCard from './PrintProblemsCard' import TableQrCodes from '../online/TableQrCodes' import { BORDER, SOFT, SOLID } from '../overview/tones' import QuickActions from './QuickActions' import { NO_ZONE, cardTarget, filterCards, flagsByTable, personName } from './orderLogic' const ORDER_EVENTS = ['order_updated', 'order_paid', 'order_closed', 'order_refunded'] const STATE_TONE = { open: 'success', partially_paid: 'info', paid: 'accent', free: 'neutral' } export default function TablesPage() { const { t } = useTranslation('manager') const tc = useTranslation('common').t const navigate = useNavigate() const qrModule = useModule('connect_menu') const qrAllowed = useCan('connect_menu.manage') const qrOn = qrModule && qrAllowed const [params, setParams] = useSearchParams() const views = ['list', 'map', ...(qrOn ? ['qr'] : [])] const view = views.includes(params.get('view')) ? params.get('view') : 'list' const setView = v => setParams(p => { const n = new URLSearchParams(p); n.set('view', v); return n }, { replace: true }) const [states, setStates] = useState([]) const [zones, setZones] = useState([]) const [quick, setQuick] = useState(null) // a card const { data: tables = [], isPending: loadingTables } = useLiveQuery({ queryKey: ['tables'], queryFn: () => client.get('/api/tables/').then(r => r.data), events: ['table_list_changed', 'reservation_updated'], refetchInterval: 60_000, }) const { data: orders = [], isPending: loadingOrders } = useLiveQuery({ queryKey: ['orders-active'], queryFn: () => client.get('/api/orders/').then(r => r.data), events: ORDER_EVENTS, refetchInterval: 60_000, }) const { data: groups = [] } = useLiveQuery({ queryKey: ['table-groups'], queryFn: () => client.get('/api/tables/groups').then(r => r.data), events: ['table_list_changed'] }) const { data: flagDefs = [] } = useLiveQuery({ queryKey: ['flag-defs'], queryFn: () => client.get('/api/flags/defs').then(r => r.data), staleTime: 60_000 }) const { data: flagRows = [] } = useLiveQuery({ queryKey: ['flag-assignments'], queryFn: () => client.get('/api/flags/assignments').then(r => r.data), events: ['table_flags_changed'] }) const { data: staff = [] } = useLiveQuery({ queryKey: ['waiters'], queryFn: () => client.get('/api/waiters/').then(r => r.data), staleTime: 60_000 }) const cards = tableCards(tables, orders) const shown = filterCards(cards, { states, zones }) const flags = flagsByTable(flagDefs, flagRows) const name = id => personName(staff.find(s => s.id === id)) || `#${id}` const toggleState = s => setStates(list => (list.includes(s) ? list.filter(x => x !== s) : [...list, s])) if (loadingTables || loadingOrders) return
const viewIcon = { list: , map: , qr: } const oneZone = zones.length === 1 && zones[0] !== NO_ZONE ? Number(zones[0]) : null return ( ({ value: v, label: v === 'qr' ? t('orders.tables.qrCodes') : tc(`floorMap.${v}`), icon: viewIcon[v], testId: `tables-view-${v}` }))} /> {view === 'list' && TABLE_STATES.map(s => ( toggleState(s)} data-testid={`tables-state-${s}`} count={cards.filter(c => c.state === s).length}> {t(`overview.tableState.${s}`)} ))} {view !== 'qr' && ( ({ value: String(g.id), label: g.name, dot: g.color || undefined })), { value: NO_ZONE, label: t('orders.tables.noZone') }, ]} /> )} {view === 'qr' && } {view === 'map' && ( navigate(`/orders/${id}`)} /> )} {view === 'list' && (shown.length === 0 ? : (
{shown.map(card => ( 1 ? groups.find(g => g.id === card.table.group_id)?.name : null} flags={flags[card.table.id] ?? []} waiterName={name} onOpen={() => navigate(cardTarget(card))} onQuick={() => setQuick(card)} /> ))}
))} {view !== 'qr' && navigate(`/orders/${id}`)} />} {quick && setQuick(null)} />}
) } function TableCard({ card, zone, flags, waiterName, onOpen, onQuick }) { const { t } = useTranslation('manager') const { formatTime } = useFormat() const since = useDuration() const { table, order, state, pendingPrint } = card const tone = STATE_TONE[state] const booking = table.upcoming_reservation const open = order ? durationParts(order.opened_at) : null const long = !!open && open.h * 60 + open.m >= 90 // the v1 card's "been here a while" return (
) }