import { IconAlertCircle as AlertCircle, IconAlertTriangle as AlertTriangle, IconCircleCheck as CheckCircle2, IconInfoCircle as Info, IconX as X, } from '@tabler/icons-react'; import { useEffect, useRef } from 'react'; import { Button } from '@/components/ui/button'; import { type NotificationType, useNotifications } from '@/hooks/useNotifications'; import { cn } from '@/lib/utils'; function getNotificationIcon(type: NotificationType) { switch (type) { case 'error': return ; case 'warning': return ; case 'success': return ; default: return ; } } function getNotificationStyles(type: NotificationType) { switch (type) { case 'error': return 'bg-destructive border-destructive text-white'; case 'warning': return 'bg-warning border-warning text-black/90'; case 'success': return 'bg-success border-success text-white dark:text-black/90'; default: return 'bg-primary border-primary text-primary-foreground'; } } export function NotificationBar() { const { notifications, hasNotifications, isDrawerOpen, toggleDrawer, dismissNotification } = useNotifications(); const barRef = useRef(null); // Measure bar height and set CSS variable so fixed elements (Nav, Sidebar) can offset their top useEffect(() => { const el = barRef.current; if (!el || !hasNotifications) { document.documentElement.style.removeProperty('--notification-bar-h'); return; } const observer = new ResizeObserver(([entry]) => { const height = entry.borderBoxSize?.[0]?.blockSize ?? entry.contentRect.height; document.documentElement.style.setProperty('--notification-bar-h', `${height}px`); }); observer.observe(el); return () => { observer.disconnect(); document.documentElement.style.removeProperty('--notification-bar-h'); }; }, [hasNotifications]); if (!hasNotifications) { return null; } const latestNotification = notifications[0]; const handleAction = (url: string) => { window.open(url, '_blank', 'noopener,noreferrer'); }; return (
{/* Always visible bar showing latest notification */}
{getNotificationIcon(latestNotification.type)}
{latestNotification.title} {latestNotification.message && ( - {latestNotification.message} )}
{latestNotification.action && (() => { const action = latestNotification.action; return ( ); })()} {notifications.length > 1 && ( )} {latestNotification.dismissible && ( )}
{/* Expanded section showing additional notifications */}
1 ? 'max-h-60' : 'max-h-0' )} >
{notifications.slice(1).map((notification) => (
{getNotificationIcon(notification.type)}
{notification.title} {notification.message && ( - {notification.message} )}
{notification.action && (() => { const action = notification.action; return ( ); })()} {notification.dismissible && ( )}
))}
); }