Files
xenia-pos-local/waiter_pwa/src/components/PrintProblemsSheet.jsx
T
bonaminandClaude Opus 5.5 f31bdf42aa 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>
2026-11-19 01:40:07 +02:00

85 lines
4.8 KiB
React

// 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>
)
}