feat: printing problems shown and handled; printing set-up on v2 (platform-v2 step 6.10)

- a ticket that doesn't print is a problem for whoever sent it and the managers:
  GET /api/print-problems (the order, table, dishes, printer, since when, tries,
  last error, who sent it) and three ways out: print again, send to another
  printer, handled (services/print_problems.py; print_jobs.resolved_by /
  redirected_to, Alembic 0036); live event print.problems from the print paths
- phone: the red printer button opens the problems sheet, the table page warns
  (usePrintProblems replaces the 8 s poll); counter POS: a red button under the
  modes with the shared panel (@xenia/ordering PrintProblemsPanel + pure rules);
  manager: a card on the overview (top), the Tables page and the order page
- manager: Settings -> Printing (printers with reachability, test print, network
  scan; ticket layout + test ticket, beep, fonts with previews, dot leader,
  dividers) and Management -> Prep zones (cards + zone dialog with the ticket
  language, printers, copies, sorting, category order, kitchen screen) rebuilt in
  src/pages/printing; v1 PrintFontsTab, PrepZonesConfigPage, PendingPrints and
  /api/orders/pending-prints removed
- access: printer add/edit/delete/scan need core.settings.manage, prep zone
  changes catalog.menu.manage (were any dashboard user)
- tests: test_print_problems.py, @xenia/ordering printProblems, manager
  printing.test.mjs, e2e print_problems.mjs (done-when) + manager.mjs printing

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This commit is contained in:
2026-11-19 01:40:07 +02:00
co-authored by Claude Opus 5.5
parent 070c9cf625
commit f31bdf42aa
57 changed files with 2557 additions and 2221 deletions
+10 -4
View File
@@ -10,7 +10,8 @@ import useChatStore from '../store/chatStore'
import useKdsReadyStore from '../store/kdsReadyStore'
import useInstallPromptStore, { apkAvailable } from '../store/installPromptStore'
import useOfflineQueueCount from '../hooks/useOfflineQueueCount'
import useFailedPrintCount from '../hooks/useFailedPrintCount'
import usePrintProblems from '../hooks/usePrintProblems'
import PrintProblemsSheet from './PrintProblemsSheet'
import { fade } from '../logic/colour'
// ─── Nav item registry ────────────────────────────────────────────────────────
@@ -148,6 +149,7 @@ function FailedPrintButton({ count, onClick }) {
return (
<button
onClick={onClick}
data-testid="print-problems-button"
style={{
position: 'relative',
display: 'inline-flex', alignItems: 'center', justifyContent: 'center',
@@ -650,7 +652,8 @@ export default function AppShell({ children, title, rightActions }) {
const { totalUnread: chatUnread } = useChatStore()
const { readyCount } = useKdsReadyStore()
const offlineCacheCount = useOfflineQueueCount()
const failedPrintCount = useFailedPrintCount()
const prints = usePrintProblems() // 6.10: tickets that didn't print, live
const [showPrints, setShowPrints] = useState(false)
function openNotifs() {
setShowNotifs(true)
@@ -690,8 +693,8 @@ export default function AppShell({ children, title, rightActions }) {
{/* Offline cache badge — visible only when ops are pending */}
<CacheButton count={offlineCacheCount} />
{/* Failed print badge — navigates to order log */}
<FailedPrintButton count={failedPrintCount} onClick={() => navigate('/order-log?filter=failed')} />
{/* Tickets that didn't print (6.10): opens them with what can be done */}
<FailedPrintButton count={prints.problems.length} onClick={() => setShowPrints(true)} />
{/* Bell */}
<BellButton onClick={openNotifs} count={unreadCount || 0} />
@@ -700,6 +703,9 @@ export default function AppShell({ children, title, rightActions }) {
<UserMenu />
</header>
{showPrints && <PrintProblemsSheet problems={prints.problems} printers={prints.printers}
onChanged={prints.reload} onClose={() => setShowPrints(false)} />}
{/* ── Side drawer ───────────────────────────────────────── */}
<SideDrawer open={drawerOpen} onClose={() => setDrawerOpen(false)} />
@@ -0,0 +1,84 @@
// Tickets that didn't print, on the phone (plan step 6.10): opened from the red printer button
// in the header (all of them) or from a table's warning (that order's). Each says where it
// belongs, which printer, since when and what's on it; then Print again, Send to another
// printer, or Handled (told the kitchen by voice). The list comes back over the live event.
import { useState } from 'react'
import { useNavigate } from 'react-router-dom'
import { useFormat, useTranslation } from '@xenia/i18n'
import { actionRequest, itemsText, otherPrinters, placeOf } from '@xenia/ordering/printProblems'
import client from '../api/client'
import { apiError } from '../api/errors'
export default function PrintProblemsSheet({ problems, printers, onClose, onChanged, showPlace = true }) {
const { t } = useTranslation('common')
return (
<div className="modal-overlay" onClick={onClose}>
<div className="modal-sheet" onClick={e => e.stopPropagation()} data-testid="print-problems-sheet">
<div className="modal-handle" />
<h2 className="modal-title">{t('printProblems.title')}</h2>
{problems.length === 0 && <p style={{ textAlign: 'center', color: 'var(--muted)' }}>{t('printProblems.none')}</p>}
{problems.map(p => <Problem key={p.job_id} problem={p} printers={printers} onChanged={onChanged} showPlace={showPlace} onClose={onClose} />)}
<button className="btn btn--secondary" onClick={onClose}>{t('printProblems.close')}</button>
</div>
</div>
)
}
function Problem({ problem: p, printers, onChanged, showPlace, onClose }) {
const { t } = useTranslation('common')
const { formatTime } = useFormat()
const navigate = useNavigate()
const others = otherPrinters(p, printers)
const [to, setTo] = useState(others[0] ? String(others[0].id) : '')
const [busy, setBusy] = useState(null)
const [note, setNote] = useState(null) // { ok, text }
async function act(kind, printerId) {
setBusy(kind)
setNote(null)
try {
const [url, body] = actionRequest(kind, p, printerId)
const { data } = await client.post(url, body)
if (kind === 'retry' && !data.ok) setNote({ ok: false, text: t('printProblems.stillNot', { printer: data.printer }) })
onChanged()
} catch (err) { setNote({ ok: false, text: apiError(err, t('printProblems.failed')) }) } finally { setBusy(null) }
}
return (
<div data-testid="print-problem" data-job={p.job_id} data-order={p.order_id}
style={{ border: '2px solid var(--x-danger)', background: 'var(--x-danger-soft)', borderRadius: 14, padding: 12, display: 'grid', gap: 8 }}>
<div style={{ display: 'flex', alignItems: 'baseline', gap: 8, flexWrap: 'wrap' }}>
{showPlace && (
<button onClick={() => { onClose(); navigate(p.table_id != null ? `/tables/${p.table_id}` : `/orders/${p.order_id}`) }}
style={{ background: 'none', border: 'none', padding: 0, fontSize: 18, fontWeight: 800, color: 'var(--x-ink)', textDecoration: 'underline', cursor: 'pointer' }}>
{placeOf(p)}
</button>
)}
<span style={{ fontWeight: 700, color: 'var(--x-danger-ink)' }}>🖨 {t('printProblems.notOn', { printer: p.printer.name })}</span>
</div>
<div style={{ fontSize: 13, color: 'var(--x-ink-2)' }}>
{t('printProblems.since', { time: formatTime(p.since) })} · {t('printProblems.tries', { count: p.attempts })}
</div>
<div style={{ fontSize: 15, color: 'var(--x-ink)' }}>{itemsText(p)}</div>
<button className="btn btn--secondary" disabled={!!busy} onClick={() => act('retry')} data-testid="problem-retry">
{busy === 'retry' ? '…' : t('printProblems.retry')}
</button>
{others.length > 0 && (
<div style={{ display: 'flex', gap: 8 }}>
<select value={to} onChange={e => setTo(e.target.value)} aria-label={t('printProblems.sendTo')} data-testid="problem-printer"
style={{ flex: 1, height: 44, borderRadius: 10, border: '1px solid var(--border)', background: 'var(--bg3)', color: 'var(--text)', padding: '0 10px', fontSize: 15 }}>
{others.map(o => <option key={o.id} value={o.id}>{o.name}</option>)}
</select>
<button className="btn btn--accent" disabled={!!busy || !to} onClick={() => act('redirect', Number(to))} data-testid="problem-redirect">
{busy === 'redirect' ? '…' : t('printProblems.send')}
</button>
</div>
)}
<button className="btn btn--secondary" disabled={!!busy} onClick={() => act('handled')} data-testid="problem-handled">
{busy === 'handled' ? '…' : t('printProblems.handled')}
</button>
<div style={{ fontSize: 12, color: 'var(--x-ink-3)' }}>{t('printProblems.handledHint')}</div>
{note && <p role="alert" className="error-msg">{note.text}</p>}
</div>
)
}
@@ -0,0 +1,31 @@
// A table's tickets that didn't print (plan step 6.10), on the table's page: "Didn't print on
// Kitchen · since 21:03 · Burger, Freddo", tapping opens what can be done (the sheet).
import { useState } from 'react'
import { useFormat, useTranslation } from '@xenia/i18n'
import { itemsText, problemsOf } from '@xenia/ordering/printProblems'
import usePrintProblems from '../hooks/usePrintProblems'
import PrintProblemsSheet from './PrintProblemsSheet'
export default function TablePrintWarning({ orderId }) {
const { t } = useTranslation('common')
const { formatTime } = useFormat()
const { problems, printers, reload } = usePrintProblems()
const [open, setOpen] = useState(false)
const mine = orderId ? problemsOf(problems, orderId) : []
if (!mine.length) return null
return (
<>
<button onClick={() => setOpen(true)} data-testid="table-print-warning"
style={{ margin: '10px 12px 0', textAlign: 'left', border: '2px solid var(--x-danger)', background: 'var(--x-danger-soft)', borderRadius: 14, padding: 12, display: 'grid', gap: 4, cursor: 'pointer', fontFamily: 'inherit' }}>
{mine.map(p => (
<span key={p.job_id} style={{ display: 'grid', gap: 2 }}>
<span style={{ fontWeight: 800, color: 'var(--x-danger-ink)' }}>🖨 {t('printProblems.notOn', { printer: p.printer.name })} · {t('printProblems.since', { time: formatTime(p.since) })}</span>
<span style={{ fontSize: 13, color: 'var(--x-ink)' }}>{itemsText(p)}</span>
</span>
))}
<span style={{ fontSize: 13, fontWeight: 700, color: 'var(--x-danger-ink)' }}>{t('printProblems.whatNow')} ›</span>
</button>
{open && <PrintProblemsSheet problems={mine} printers={printers} showPlace={false} onChanged={reload} onClose={() => setOpen(false)} />}
</>
)
}
@@ -1,29 +0,0 @@
import { useState, useEffect } from 'react'
import client from '../api/client'
// Polls /api/orders/pending-prints every 8s and returns the count of pending print jobs.
export default function useFailedPrintCount() {
const [count, setCount] = useState(0)
useEffect(() => {
let cancelled = false
async function refresh() {
try {
const res = await client.get('/api/orders/pending-prints')
if (!cancelled) setCount(res.data?.count ?? 0)
} catch {
// Network error — leave count as-is
}
}
refresh()
const id = setInterval(refresh, 8000)
return () => {
cancelled = true
clearInterval(id)
}
}, [])
return count
}
+25
View File
@@ -0,0 +1,25 @@
// Tickets that didn't print (plan step 6.10; replaces the 8-second poll of the failed-print
// count): GET /api/print-problems → { problems, printers }, reloaded by the live event
// `print.problems` (and a closed order, a reconnect, every minute as a safety net). The server
// only lists the orders this waiter may act on.
import { useCallback, useEffect, useState } from 'react'
import { PRINT_EVENT } from '@xenia/ordering/printProblems'
import client from '../api/client'
const SAFETY_MS = 60_000
export default function usePrintProblems() {
const [data, setData] = useState(null)
const load = useCallback(async () => {
try { setData((await client.get('/api/print-problems')).data) } catch { /* offline: keep what we had */ }
}, [])
useEffect(() => {
const first = setTimeout(load, 0)
const onEvent = e => { if ([PRINT_EVENT, 'order_closed', 'ready'].includes(e.detail?.type)) load() }
window.addEventListener('live-event', onEvent)
window.addEventListener('live-reconnected', load)
const id = setInterval(load, SAFETY_MS)
return () => { clearTimeout(first); clearInterval(id); window.removeEventListener('live-event', onEvent); window.removeEventListener('live-reconnected', load) }
}, [load])
return { data, problems: data?.problems ?? [], printers: data?.printers ?? [], reload: load }
}
+4
View File
@@ -3,6 +3,7 @@ import { useNavigate, useParams, useSearchParams } from 'react-router-dom'
import { useAllowed, useCan, useModule } from '@xenia/access'
import OrderSummary from '../components/OrderSummary'
import TabletRequests from '../components/TabletRequests'
import TablePrintWarning from '../components/TablePrintWarning'
import TableHistory from '../components/TableHistory'
import useConnectionStore from '../store/connectionStore'
import client from '../api/client'
@@ -1728,6 +1729,9 @@ export default function TableDetailPage() {
</div>
)}
{/* tickets of this order that didn't print (6.10) */}
<TablePrintWarning orderId={order?.id} />
{/* orders from the table's menu tablet waiting for a waiter (6.6) */}
{!isStandalone && <TabletRequests tableId={Number(tableId)} />}