diff --git a/admin.html b/admin.html index 7919df7..5f251d1 100644 --- a/admin.html +++ b/admin.html @@ -141,6 +141,7 @@ + @@ -178,6 +179,7 @@
+
@@ -337,10 +339,13 @@ function esc(s) { function setFilter(f) { currentFilter = f; document.querySelectorAll('.tab').forEach(t => t.classList.toggle('active', t.dataset.filter===f)); - // scroll active tab into view (mobile) const active = document.querySelector('.tab.active'); if (active) active.scrollIntoView({behavior:'smooth',inline:'center',block:'nearest'}); - renderOrders(); + if (f === 'archived') { + loadArchived(); + } else { + loadOrders(); + } } // ── Modal ── @@ -356,6 +361,7 @@ async function openModal(id) { document.getElementById('detailDate').textContent = o.created_at||'-'; document.getElementById('detailStatus').value = o.status||'received'; document.getElementById('noteInput').value = ''; + document.getElementById('archiveBtn').textContent = o.archived ? '📂 Unarchive' : '📦 Archive'; document.getElementById('notesList').innerHTML = '
Loading...
'; document.getElementById('detailModal').classList.add('open'); document.body.style.overflow = 'hidden'; @@ -398,6 +404,35 @@ async function loadNotes(id) { document.getElementById('notesList').innerHTML = html; } +// ── Archive Toggle ── + +async function toggleArchive() { + if (!currentOrderId) return; + const o = orders.find(x => x.id === currentOrderId); + if (!o) return; + const currentlyArchived = o.archived || false; + const action = currentlyArchived ? 'unarchive' : 'archive'; + if (!confirm('Are you sure you want to ' + action + ' order #' + currentOrderId + '?')) return; + const r = await fetch(API + '/admin/archive', {method:'POST',headers:{'Authorization':'Bearer '+token,'Content-Type':'application/json'},body:JSON.stringify({submission_id:currentOrderId,archived:!currentlyArchived})}); + if (r.ok) { + o.archived = !currentlyArchived; + document.getElementById('archiveBtn').textContent = o.archived ? '📂 Unarchive' : '📦 Archive'; + loadOrders(); + } +} + +async function loadArchived() { + try { + const r = await fetch(API + '/admin/submissions?include_archived=1&per_page=200', {headers:{'Authorization':'Bearer '+token}}); + if (r.status === 401) { logout(); return; } + if (!r.ok) return; + const d = await r.json(); + orders = (d.submissions || []).filter(o => o.archived); + renderStats(d); + renderOrders(); + } catch(e) {} +} + // ── Theme ── function toggleTheme() {