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
@@ -0,0 +1,103 @@
// Prep zones (plan step 6.10; replaces the v1 Management → Prep zones page): where each dish's
// ticket prints and how the kitchen screen treats it. A card per zone (its printers, whether it
// prints, the ticket's sorting, the kitchen screen's shortcuts); New / Edit open the zone's
// dialog, Delete asks first. Products are put in zones from the product editor.
import { useState } from 'react'
import { useMutation, useQueryClient } from '@tanstack/react-query'
import toast from 'react-hot-toast'
import { CookingPot, Pencil, Plus, Printer, Trash2 } from 'lucide-react'
import { useCan } from '@xenia/access'
import { errorMessage } from '@xenia/api'
import { useTranslation } from '@xenia/i18n'
import { Button, Dialog, EmptyState, IconButton, Spinner } from '@xenia/ui'
import client from '../../api/client'
import { useLiveQuery } from '../../live/useLiveQuery'
import { Pill } from '../overview/parts'
import ZoneDialog from './ZoneDialog'
export default function PrepZonesPage() {
const { t } = useTranslation('manager')
const qc = useQueryClient()
const canEdit = useCan('catalog.menu.manage')
const [editing, setEditing] = useState(null) // a zone, or {} for a new one
const [deleting, setDeleting] = useState(null)
const { data: zones, isPending } = useLiveQuery({ queryKey: ['prep-zones'], queryFn: () => client.get('/api/prep-zones').then(r => r.data) })
const { data: printers = [] } = useLiveQuery({ queryKey: ['printers'], queryFn: () => client.get('/api/system/printers').then(r => r.data), staleTime: 60_000 })
const { data: categories = [] } = useLiveQuery({ queryKey: ['categories'], queryFn: () => client.get('/api/products/categories').then(r => r.data), staleTime: 60_000 })
const remove = useMutation({
mutationFn: id => client.delete(`/api/prep-zones/${id}`),
onSuccess: () => { toast.success(t('printing.zones.deleted')); setDeleting(null); qc.invalidateQueries({ queryKey: ['prep-zones'] }) },
onError: err => toast.error(errorMessage(err, t)),
})
const nameOf = id => printers.find(p => p.id === id)?.name ?? `#${id}`
return (
<div className="h-full overflow-y-auto p-4 lg:p-6" data-testid="prep-zones-page">
<div className="max-w-6xl mx-auto grid gap-4">
<header className="flex flex-wrap items-center gap-3">
<div className="flex-1 min-w-0">
<h1 className="text-title font-semibold text-ink">{t('printing.zones.title')}</h1>
<p className="text-label text-ink-2">{t('printing.zones.intro')}</p>
</div>
{canEdit && <Button icon={<Plus size={16} />} onClick={() => setEditing({})} data-testid="zone-new">{t('printing.zones.new')}</Button>}
</header>
{isPending ? <div className="py-10 flex justify-center"><Spinner /></div>
: !zones?.length ? <EmptyState icon={<CookingPot size={28} />} title={t('printing.zones.none')} description={t('printing.zones.noneHint')} />
: (
<div className="grid gap-3 grid-cols-[repeat(auto-fill,minmax(18rem,1fr))]">
{zones.map(z => (
<section key={z.id} className="rounded-card border border-line bg-surface shadow-raised p-4 grid gap-3 content-start" data-testid="zone-card" data-name={z.name}>
<header className="flex items-start gap-2">
<div className="flex-1 min-w-0">
<h2 className="text-body-lg font-semibold text-ink truncate">{z.name}</h2>
{z.notification_name && <p className="text-label text-accent-ink">{z.notification_name}</p>}
{z.description && <p className="text-caption text-ink-3">{z.description}</p>}
</div>
{canEdit && (<>
<IconButton size="sm" variant="ghost" label={t('printing.zones.edit', { name: z.name })} onClick={() => setEditing(z)} data-testid="zone-edit"><Pencil size={14} /></IconButton>
<IconButton size="sm" variant="ghost" label={t('printing.zones.delete', { name: z.name })} onClick={() => setDeleting(z)}><Trash2 size={14} /></IconButton>
</>)}
</header>
<div className="grid gap-1 text-label">
<span className="flex flex-wrap items-center gap-1.5">
<span className="w-16 shrink-0 text-caption font-semibold uppercase tracking-wide text-ink-3">{t('printing.zones.main')}</span>
{z.master_printer_id ? <Pill tone="accent"><Printer size={12} aria-hidden="true" />{nameOf(z.master_printer_id)}{z.auto_print !== 'none' && z.master_copies > 1 ? ` ×${z.master_copies}` : ''}</Pill>
: <span className="text-ink-3">{t('printing.zones.noPrinter')}</span>}
</span>
{z.secondary_printer_ids?.length > 0 && (
<span className="flex flex-wrap items-center gap-1.5">
<span className="w-16 shrink-0 text-caption font-semibold uppercase tracking-wide text-ink-3">{t('printing.zones.also')}</span>
{z.secondary_printer_ids.map(id => <Pill key={id}><Printer size={12} aria-hidden="true" />{nameOf(id)}</Pill>)}
{z.auto_print === 'all' && z.secondary_copies > 1 && <span className="text-ink-3">×{z.secondary_copies}</span>}
</span>
)}
</div>
<footer className="flex flex-wrap gap-1.5 pt-2 border-t border-line">
<Pill tone={z.auto_print === 'none' ? 'warning' : 'success'}>{t(`printing.zones.autoShort.${z.auto_print}`)}</Pill>
<Pill>{t(`printing.zones.sortShort.${z.sort_items_by}`)}</Pill>
{z.group_by_category && <Pill>{t('printing.zones.byCategory')}</Pill>}
{z.print_checkboxes && <Pill>{t('printing.zones.checkboxes')}</Pill>}
{z.language && <Pill>{z.language.toUpperCase()}</Pill>}
{z.bypass_kds ? <Pill tone="danger">{t('printing.zones.skipKds')}</Pill> : z.bypass_pending && <Pill tone="warning">{t('printing.zones.startReady')}</Pill>}
{z.auto_ready_to_served && <Pill tone="info">{t('printing.zones.readyServed')}</Pill>}
</footer>
</section>
))}
</div>
)}
</div>
{editing && <ZoneDialog zone={editing.id ? editing : null} printers={printers} categories={categories}
onClose={() => setEditing(null)} onSaved={() => { setEditing(null); qc.invalidateQueries({ queryKey: ['prep-zones'] }) }} />}
{deleting && (
<Dialog open size="sm" onClose={() => setDeleting(null)} title={t('printing.zones.deleteTitle', { name: deleting.name })}
description={t('printing.zones.deleteBody')}
footer={<>
<Button variant="secondary" onClick={() => setDeleting(null)}>{t('printing.back')}</Button>
<Button variant="danger" loading={remove.isPending} onClick={() => remove.mutate(deleting.id)} data-testid="zone-delete-confirm">{t('printing.zones.deleteYes')}</Button>
</>} />
)}
</div>
)
}