"use client"; import { formatDistanceToNow } from "date-fns"; import { AlertCircle, Bell, CheckCheck, CheckCircle2, Loader2 } from "lucide-react"; import { useRouter } from "next/navigation"; import { convertRenderedToDisplay } from "@/components/chat-comments/comment-item/comment-item"; import { Button } from "@/components/ui/button"; import { ScrollArea } from "@/components/ui/scroll-area"; import { Separator } from "@/components/ui/separator"; import type { Notification } from "@/hooks/use-notifications"; import { cn } from "@/lib/utils"; interface NotificationPopupProps { notifications: Notification[]; unreadCount: number; loading: boolean; markAsRead: (id: number) => Promise; markAllAsRead: () => Promise; onClose?: () => void; } export function NotificationPopup({ notifications, unreadCount, loading, markAsRead, markAllAsRead, onClose, }: NotificationPopupProps) { const router = useRouter(); const handleMarkAllAsRead = async () => { await markAllAsRead(); }; const handleNotificationClick = async (notification: Notification) => { if (!notification.read) { await markAsRead(notification.id); } if (notification.type === "new_mention") { const metadata = notification.metadata as { thread_id?: number; comment_id?: number; }; const searchSpaceId = notification.search_space_id; const threadId = metadata?.thread_id; const commentId = metadata?.comment_id; if (searchSpaceId && threadId) { const url = commentId ? `/dashboard/${searchSpaceId}/new-chat/${threadId}?commentId=${commentId}` : `/dashboard/${searchSpaceId}/new-chat/${threadId}`; onClose?.(); router.push(url); } } }; const formatTime = (dateString: string) => { try { return formatDistanceToNow(new Date(dateString), { addSuffix: true }); } catch { return "Recently"; } }; const getStatusIcon = (notification: Notification) => { const status = notification.metadata?.status as string | undefined; switch (status) { case "in_progress": return ; case "completed": return ; case "failed": return ; default: return ; } }; return (
{/* Header */}

Notifications

{unreadCount > 0 && ( )}
{/* Notifications List */} {loading ? (
) : notifications.length === 0 ? (

No notifications

) : (
{notifications.map((notification, index) => (
{index < notifications.length - 1 && }
))}
)}
); }