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(); }}> {unreadCount > 0 && ( {unreadCount} )} 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 )} markNotificationsRead()} className="w-full py-2 text-[10px] font-black text-gray-400 uppercase tracking-widest hover:text-emerald-600 transition-colors bg-white rounded-lg border border-gray-100" > Mark all as read ); }; export default NotificationPopover;
Recent Activity
{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