"use client"; import { useState } from "react"; import { usePathname } from "next/navigation"; import { Button } from "@/components/ui/button"; import { DropdownMenu, DropdownMenuContent, DropdownMenuItem, DropdownMenuLabel, DropdownMenuSeparator, DropdownMenuTrigger, } from "@/components/ui/dropdown-menu"; import { Badge } from "@/components/ui/badge"; import { ScrollArea } from "@/components/ui/scroll-area"; import { useNotifications } from "@/contexts/notification-context"; import { Bell, Check, CheckCheck, Trash2, ExternalLink, AlertCircle, CheckCircle, Info, AlertTriangle, } from "lucide-react"; import { formatDistanceToNow } from "date-fns"; import { enUS } from "date-fns/locale"; import Link from "next/link"; import { motion, AnimatePresence } from "framer-motion"; export function NotificationDropdown() { const pathname = usePathname(); const isCompanyDashboard = pathname?.startsWith("/dashboard/company"); const notificationsUrl = isCompanyDashboard ? "/dashboard/company/notifications" : "/dashboard/candidate/notifications"; const { notifications, unreadCount, markAsRead, markAllAsRead, removeNotification, clearAllNotifications, } = useNotifications(); const [isOpen, setIsOpen] = useState(false); const getNotificationIcon = (type: string) => { switch (type) { case "success": return ; case "error": return ; case "warning": return ; default: return ; } }; const recentNotifications = notifications.slice(0, 10); return ( {unreadCount > 0 && ( {unreadCount > 9 ? "9+" : unreadCount} )} Notifications {unreadCount > 0 && ( Mark all )} {recentNotifications.length === 0 ? ( No notifications ) : ( {recentNotifications.map((notification, index) => ( !notification.read && markAsRead(notification.id) } > {getNotificationIcon(notification.type)} {notification.title} {!notification.read && ( { e.stopPropagation(); markAsRead(notification.id); }} > )} { e.stopPropagation(); removeNotification(notification.id); }} > {notification.message} {formatDistanceToNow( new Date(notification.createdAt), { addSuffix: true, locale: enUS, } )} {notification.actionUrl && notification.actionLabel && ( setIsOpen(false)} > {notification.actionLabel} )} {!notification.read && ( )} ))} )} {notifications.length > 0 && ( <> { clearAllNotifications(); setIsOpen(false); }} className="flex-1 text-xs" > Clear all setIsOpen(false)} > View all > )} ); }
{notification.message}