import { useState, useEffect } from 'react'; import { useQuery, useMutation } from '@tanstack/react-query'; import { X, Printer, Loader2 } from 'lucide-react'; import { api } from '../api/client'; import { Card, CardContent } from './Card'; import { Button } from './Button'; interface ReprintModalProps { archiveId: number; archiveName: string; onClose: () => void; onSuccess: () => void; } export function ReprintModal({ archiveId, archiveName, onClose, onSuccess }: ReprintModalProps) { const [selectedPrinter, setSelectedPrinter] = useState(null); // Close on Escape key useEffect(() => { const handleKeyDown = (e: KeyboardEvent) => { if (e.key === 'Escape') onClose(); }; window.addEventListener('keydown', handleKeyDown); return () => window.removeEventListener('keydown', handleKeyDown); }, [onClose]); const { data: printers, isLoading: loadingPrinters } = useQuery({ queryKey: ['printers'], queryFn: api.getPrinters, }); const reprintMutation = useMutation({ mutationFn: () => { if (!selectedPrinter) throw new Error('No printer selected'); return api.reprintArchive(archiveId, selectedPrinter); }, onSuccess: () => { onSuccess(); onClose(); }, }); const activePrinters = printers?.filter((p) => p.is_active) || []; return (
{/* Header */}

Re-print

Send {archiveName} to a printer

{/* Printer selection */} {loadingPrinters ? (
) : activePrinters.length === 0 ? (
No active printers available
) : (
{activePrinters.map((printer) => ( ))}
)} {/* Error message */} {reprintMutation.isError && (
{(reprintMutation.error as Error).message || 'Failed to start print'}
)} {/* Actions */}
); }