/** * Unified Inbox Admin Page * View and manage all communications: contacts, media inquiries, case submissions */ let allItems = []; let currentItem = null; // Initialize page document.addEventListener('DOMContentLoaded', async () => { await loadStats(); await loadInbox(); setupEventListeners(); }); /** * Load statistics */ async function loadStats() { try { const token = localStorage.getItem('admin_token'); const response = await fetch('/api/inbox/stats', { headers: { 'Authorization': `Bearer ${token}` } }); if (!response.ok) throw new Error('Failed to load stats'); const data = await response.json(); const stats = data.stats; document.getElementById('stat-total').textContent = stats.total.all; document.getElementById('stat-new').textContent = stats.total.new; document.getElementById('stat-assigned').textContent = stats.total.assigned; document.getElementById('stat-responded').textContent = stats.total.responded; } catch (error) { console.error('Error loading stats:', error); } } /** * Load inbox items */ async function loadInbox() { try { const token = localStorage.getItem('admin_token'); const type = document.getElementById('filter-type').value; const status = document.getElementById('filter-status').value; const priority = document.getElementById('filter-priority').value; let url = '/api/inbox?limit=50'; if (type && type !== 'all') url += `&type=${type}`; if (status) url += `&status=${status}`; const response = await fetch(url, { headers: { 'Authorization': `Bearer ${token}` } }); if (!response.ok) throw new Error('Failed to load inbox'); const data = await response.json(); allItems = data.items; // Apply client-side priority filter if needed if (priority) { allItems = allItems.filter(item => item._priority === priority); } renderInbox(); } catch (error) { console.error('Error loading inbox:', error); showError('Failed to load inbox'); } } /** * Render inbox items list */ function renderInbox() { const container = document.getElementById('inbox-container'); if (allItems.length === 0) { container.innerHTML = `
No items found matching the selected filters.
${escapeHtml(subtitle)}
${escapeHtml(preview)}
${escapeHtml(message)}