/** * NotificationDropdown Component * Dropdown panel showing recent notifications */ import { useEffect, useRef } from 'react'; import { Link } from 'react-router-dom'; import { CheckCheck, Settings, Bell } from 'lucide-react'; import { useNotificationStore } from '../../../stores/notificationStore'; import NotificationItem from './NotificationItem'; interface NotificationDropdownProps { isOpen: boolean; onClose: () => void; } export default function NotificationDropdown({ isOpen, onClose }: NotificationDropdownProps) { const dropdownRef = useRef(null); const { notifications, unreadCount, loading, fetchNotifications, markAsRead, markAllAsRead, deleteNotification, } = useNotificationStore(); // Fetch notifications when dropdown opens useEffect(() => { if (isOpen) { fetchNotifications(); } }, [isOpen, fetchNotifications]); // Close on click outside useEffect(() => { function handleClickOutside(event: MouseEvent) { if (dropdownRef.current && !dropdownRef.current.contains(event.target as Node)) { onClose(); } } if (isOpen) { document.addEventListener('mousedown', handleClickOutside); } return () => { document.removeEventListener('mousedown', handleClickOutside); }; }, [isOpen, onClose]); // Close on Escape key useEffect(() => { function handleEscape(event: KeyboardEvent) { if (event.key === 'Escape') { onClose(); } } if (isOpen) { document.addEventListener('keydown', handleEscape); } return () => { document.removeEventListener('keydown', handleEscape); }; }, [isOpen, onClose]); if (!isOpen) return null; const recentNotifications = notifications.slice(0, 10); return (
{/* Header */}

Notificaciones

{unreadCount > 0 && ( )}
{/* Notification List */}
{loading ? (
) : recentNotifications.length === 0 ? (

No tienes notificaciones

) : (
{recentNotifications.map((notification) => ( ))}
)}
{/* Footer */} {notifications.length > 0 && (
Ver todas las notificaciones
)}
); }