Files
Convivo/apps/admin/src/components/PrinterStatusPill.tsx
T
00c89c1b48 feat(printer): badge print queue, Pi worker, captive-portal setup, admin printing view
- migration 20261018170000: pgmq badge_print/badge_print_dlq, print_stations,
  token-gated printer RPCs (claim/complete/fail/heartbeat), admin RPCs,
  welcome_checkin enqueue; badge_print_tests.sql (101 assertions)
- apps/printer: Python worker (Playwright render -> brother_ql via pyusb),
  comitup captive-portal (Wi-Fi + HTTPS endpoint + anon key + token),
  arm64 image build + idempotent Pi setup/install scripts, 77 pytest
- apps/admin: Printing view, station management/DLQ, global printer status
  pill, Print button on Registrations, standalone print renderer entry
  (print.html -> dist-print) with bundled fonts
- docs: printing.md + architecture/schema/rpcs/tests/admin-app updates,
  apps/printer/AGENT.md operating manual
- e2e: printing.spec.ts

Co-authored-by: Stephan Charles <[email protected]>
Co-authored-by: Amelia Hernandez <[email protected]>
Co-authored-by: Markus Franz <[email protected]>
Co-authored-by: Sabrina Hota <[email protected]>
Co-authored-by: Nilüfer Doğan <[email protected]>
2026-10-18 22:25:38 +02:00

55 lines
2.2 KiB
TypeScript

import type { View } from '../App';
import { Tooltip } from './ui';
import { activeStations, aggregateState, printerHint, timeAgo, shortError, usePrintStatus, worstStation } from '../lib/printStatus';
import type { PrintStation, PrintStationState } from '../lib/types';
// Pill label per aggregated state; the worst station refines error/offline text.
function pillText(state: PrintStationState | 'none', station: PrintStation | null): string {
if (state === 'none') return 'No printer';
if (state === 'ready') return 'Printer ready';
if (state === 'printing') return 'Printing…';
if (state === 'offline') return `Printer offline · ${timeAgo(station?.last_seen_at)}`;
const err = station?.last_status?.printer?.errors?.[0];
return err ? `Printer: ${shortError(err)}` : 'Printer error';
}
function tooltipContent(stations: PrintStation[]): string {
return stations
.map((s) => {
const st = s.last_status;
const roll = st?.printer?.label_id ?? 'unknown roll';
const net = st?.network;
const netText = net?.ssid ? `${net.ssid}${net.ip ? ` · ${net.ip}` : ''}` : net?.state ?? 'unknown';
const hint = printerHint(s);
return `${s.name} (${s.state}) — roll: ${roll} · network: ${netText} · last seen: ${timeAgo(s.last_seen_at)}${hint ? ` · ${hint}` : ''}`;
})
.join('\n');
}
/**
* Always-visible printer status for the sidebar (desktop and mobile). The Pi
* has no screen, so staff must see the printer state from every admin view.
*/
export function PrinterStatusPill({ onNavigate }: { onNavigate: (view: View) => void }) {
const { overview } = usePrintStatus();
const stations = activeStations(overview);
const state = aggregateState(stations);
const station = worstStation(stations);
const label = pillText(state, station);
return (
<Tooltip title="Printer status" content={<span style={{ whiteSpace: 'pre-line' }}>{tooltipContent(stations)}</span>}>
<button
type="button"
className={`printer-pill ${state}`}
data-testid="printer-pill"
data-state={state}
onClick={() => onNavigate('printing')}
>
<span className="printer-pill-dot" aria-hidden="true" />
{label}
</button>
</Tooltip>
);
}