import React, { useState, useEffect } from 'react'; import { X, Archive, Trash2, RefreshCcw } from 'lucide-react'; import api from '../services/api'; import type { INotification } from '../types'; interface ArchivedNotificationsModalProps { isOpen: boolean; onClose: () => void; } export const ArchivedNotificationsModal: React.FC = ({ isOpen, onClose, }) => { const [notifications, setNotifications] = useState([]); const [isLoading, setIsLoading] = useState(false); const fetchArchived = async () => { setIsLoading(true); try { const response = await api.get('/notifications?includeArchived=true'); // Filtrar apenas as arquivadas (no frontend por segurança, embora o backend já devesse ajudar) // Na verdade, passamos includeArchived=true, o backend retornará unread + archived. // Vamos filtrar para mostrar apenas o "Log" (arquivadas). setNotifications(response.data.filter(n => n.isArchived || n.archivedBy?.length > 0)); } catch (error) { console.error('Error fetching archived notifications:', error); } finally { setIsLoading(false); } }; useEffect(() => { if (isOpen) { fetchArchived(); } }, [isOpen]); const deleteForever = async (id: string) => { if (!window.confirm('Excluir permanentemente este registro do log?')) return; try { await api.delete(`/notifications/${id}`); setNotifications(prev => prev.filter(n => n._id !== id)); } catch (error) { console.error('Error deleting archived notification:', error); } }; if (!isOpen) return null; return (
{/* Header */}

Log de Mensagens (Arquivadas)

Histórico de notificações sistema

{/* Body */}
{isLoading ? (

Carregando histórico...

) : notifications.length === 0 ? (

Nenhuma mensagem arquivada

Mensagens arquivadas aparecerão aqui para consulta.

) : (
{notifications.map((msg) => (
{msg.title} {new Date(msg.createdAt).toLocaleString('pt-BR')}

{msg.message}

))}
)}
{/* Footer */}
); };