import React from 'react'; import { Bell, CheckCircle2, MessageSquare, Ticket, Trash2 } from 'lucide-react'; import { useNavigate } from 'react-router-dom'; import { Popover, PopoverContent, PopoverTrigger } from "../../components/ui/popover"; import { Button } from "../../components/ui/button"; import useTicketStore from "../../store/ticketStore"; const NotificationPopover = ({ isAdmin = false }) => { const navigate = useNavigate(); const { notifications = [], markNotificationsRead } = useTicketStore(); const currentRole = isAdmin ? 'admin' : 'user'; // Filter to only show notifications meant for this role. // Legacy notifications without recipientRole are shown to everyone for backwards compat. const myNotifications = notifications.filter( n => !n.recipientRole || n.recipientRole === currentRole ); const unreadCount = myNotifications.filter(n => !n.read).length; const getIcon = (type) => { switch (type) { case 'resolution': return ; case 'message': return ; case 'new_ticket': return ; default: return ; } }; return ( { if (!open) markNotificationsRead(); }}>

Notifications

Recent Activity

{unreadCount > 0 && ( {unreadCount} NEW )}
{myNotifications.length > 0 ? (
{myNotifications.map((notif) => (
{ // Correct route: /admin/ticket/:id for admins, /ticket/:id for users const route = isAdmin ? `/admin/ticket/${notif.ticketId}` : `/ticket/${notif.ticketId}`; navigate(route); }} className={`p-4 hover:bg-gray-50/80 transition cursor-pointer flex gap-3 ${!notif.read ? 'bg-emerald-50/20' : ''}`} >
{getIcon(notif.type)}

{notif.title}

{notif.message}

{new Date(notif.timestamp).toLocaleString([], { month: 'short', day: 'numeric', hour: '2-digit', minute: '2-digit' })}

))}
) : (

All caught up

No new activity to show

)}
); }; export default NotificationPopover;