// Archive View Component const { useState, useEffect } = React; const ArchiveView = () => { const toast = useToast(); const [jobs, setJobs] = useState([]); const [loading, setLoading] = useState(true); const [confirmDelete, setConfirmDelete] = useState(null); // jobId useEffect(() => { fetch('/queue/archived').then(r => r.json()).then(data => { if (data.status === 'success') setJobs(data.jobs || []); }).catch(console.error).finally(() => setLoading(false)); }, []); const handleDelete = (id) => { setConfirmDelete(id); }; const executeDelete = async () => { if (!confirmDelete) return; try { const r = await fetch(`/queue/job/${confirmDelete}/permanent`, { method: 'DELETE' }); if (r.ok) { toast('Lavoro eliminato', 'success'); setJobs(j => j.filter(x => x.id !== confirmDelete)); } setConfirmDelete(null); } catch (e) { toast('Errore eliminazione', 'error'); setConfirmDelete(null); } }; const handleRestore = async (id) => { try { const r = await fetch(`/queue/job/${id}/restore`, { method: 'POST' }); if (r.ok) { toast('Lavoro ripristinato in coda', 'success'); setJobs(j => j.filter(x => x.id !== id)); } else { const data = await r.json(); toast(data.detail || 'Errore ripristino', 'error'); } } catch (e) { toast('Errore ripristino', 'error'); } }; const getStatusInfo = (job) => { const isSuccess = job.result?.status === 'success'; const isCancelled = job.status === 'cancelled' || job.result?.status === 'cancelled'; if (isCancelled) { return { color: 'bg-orange-500', bgLight: 'bg-orange-100', textColor: 'text-orange-700', label: 'Annullato', percent: 0 }; } if (isSuccess) { return { color: 'bg-green-500', bgLight: 'bg-green-100', textColor: 'text-green-700', label: 'Completato', percent: 100 }; } return { color: 'bg-red-500', bgLight: 'bg-red-100', textColor: 'text-red-700', label: 'Fallito', percent: 0 }; }; const formatDate = (dateString) => { if (!dateString) return '-'; return new Date(dateString).toLocaleDateString('it-IT', { day: '2-digit', month: 'short', hour: '2-digit', minute: '2-digit' }); }; return (
{/* Header */}

Archivio

Cronologia dei lavori archiviati

{loading ? (

Caricamento archivio...

) : jobs.length === 0 ? (

Archivio vuoto

I lavori archiviati appariranno qui

) : (
{jobs.map(job => { const statusInfo = getStatusInfo(job); const isSuccess = job.result?.status === 'success'; const isCancelled = job.status === 'cancelled' || job.result?.status === 'cancelled'; const fullName = `${job.personal_data?.first_name || ''} ${job.personal_data?.last_name || ''}`.trim(); const initials = fullName ? fullName.split(' ').map(n => n[0]).join('').substring(0, 2).toUpperCase() : '?'; return (
{/* Colored Top Border */}
{/* Row 1: Name & Status Badge */}

{fullName || 'N/A'}

{statusInfo.label}
{/* Row 2: Progress Badge & Date */}
{statusInfo.percent}% {formatDate(job.archived_at || job.updated_at)}
{/* Row 3: Avatar & Actions */}
{/* User Avatar */}
{initials}
{/* Action Buttons */}
); })}
)} {/* Confirmation Modal */} {confirmDelete && ( setConfirmDelete(null)} /> )}
); }; window.ArchiveView = ArchiveView;