import React, { useEffect, useState } from 'react'; import { motion, AnimatePresence } from 'framer-motion'; import { Bell, CheckCircle2, MessageSquare, X } from 'lucide-react'; import { useNavigate } from 'react-router-dom'; import useTicketStore from "../../store/ticketStore"; const NotificationToast = () => { const notifications = useTicketStore(state => state.notifications); const [currentToast, setCurrentToast] = useState(null); const navigate = useNavigate(); useEffect(() => { if (notifications.length > 0) { const latest = notifications[0]; // Only show if it's unread and hasn't been shown in this session as a toast // We use the ID to track which one we've already toasted const shownToasts = JSON.parse(sessionStorage.getItem('shownToasts') || '[]'); if (!latest.read && !shownToasts.includes(latest.id)) { setCurrentToast(latest); // Add to shown list sessionStorage.setItem('shownToasts', JSON.stringify([...shownToasts, latest.id])); // Auto hide after 5 seconds const timer = setTimeout(() => { setCurrentToast(null); }, 5000); return () => clearTimeout(timer); } } }, [notifications]); if (!currentToast) return null; const getIcon = () => { if (currentToast.title.includes('Resolved')) return ; return ; }; return ( {currentToast && (
{ navigate(`/ticket/${currentToast.ticketId}`); setCurrentToast(null); }} className="bg-white border border-gray-100 shadow-2xl rounded-2xl p-4 flex gap-4 cursor-pointer hover:shadow-emerald-500/10 transition-all group relative overflow-hidden" > {/* Progress bar background */}
{getIcon()}

{currentToast.title}

{currentToast.message}

)}
); }; export default NotificationToast;