From 209acea88a56e7a90b2571aaf58c9739e3e89a83 Mon Sep 17 00:00:00 2001 From: AmirReza Jamali Date: Mon, 13 Jul 2026 15:11:54 +0330 Subject: [PATCH] fix(notifications): dismiss bell badge when dropdown opens Hide the unread count badge after the user opens notifications, and show it again only when new unread items arrive. Co-authored-by: Cursor --- .../Layouts/header/notification/index.tsx | 23 +++++++++++++++---- 1 file changed, 19 insertions(+), 4 deletions(-) diff --git a/src/components/Layouts/header/notification/index.tsx b/src/components/Layouts/header/notification/index.tsx index e2a752a..45c26cc 100644 --- a/src/components/Layouts/header/notification/index.tsx +++ b/src/components/Layouts/header/notification/index.tsx @@ -17,14 +17,16 @@ import { TNotificationDetailsResponse } from "@/lib/api/types/NotificationHistor import { cn, sanitizeHtmlWithStyles } from "@/lib/utils"; import { capitalize, unixToDate } from "@/utils/shared"; import Link from "next/link"; -import { useEffect, useMemo, useState } from "react"; +import { useEffect, useMemo, useRef, useState } from "react"; import { BellIcon } from "./icons"; import NotificationList from "./notification-list"; export function Notification() { const [isOpen, setIsOpen] = useState(false); + const [isBadgeVisible, setIsBadgeVisible] = useState(true); const [unreadNotificationCount, setUnreadNotificationCount] = useState(0); + const previousUnreadCountRef = useRef(0); const [isModalOpen, setIsModalOpen] = useState(false); const [currentNotification, setCurrentNotification] = useState(null); @@ -36,7 +38,14 @@ export function Notification() { const { user } = useUser(); useEffect(() => { - setUnreadNotificationCount(unreadNotifications?.data.length ?? 0); + const count = unreadNotifications?.data.length ?? 0; + setUnreadNotificationCount(count); + + if (count > previousUnreadCountRef.current) { + setIsBadgeVisible(true); + } + + previousUnreadCountRef.current = count; }, [unreadNotifications]); const notificationHistoryHref = useMemo(() => { @@ -56,14 +65,20 @@ export function Notification() { return ( <> - + { + setIsOpen(open); + if (open) setIsBadgeVisible(false); + }} + > - {unreadNotificationCount > 0 && ( + {isBadgeVisible && unreadNotificationCount > 0 && (