From 6aa4b62df3f6b596f81194614346a222ae22d9d0 Mon Sep 17 00:00:00 2001 From: pradeepkumar Date: Thu, 19 Mar 2026 16:22:57 +0530 Subject: [PATCH] fix: Remove notifications from the list when marked as read while viewing the 'unread' tab. --- src/app/(agent)/agent/notifications/page.tsx | 18 ++++++++++++++---- src/app/(user)/user/notifications/page.tsx | 16 ++++++++++++---- 2 files changed, 26 insertions(+), 8 deletions(-) diff --git a/src/app/(agent)/agent/notifications/page.tsx b/src/app/(agent)/agent/notifications/page.tsx index 9cebac0..b8825bc 100644 --- a/src/app/(agent)/agent/notifications/page.tsx +++ b/src/app/(agent)/agent/notifications/page.tsx @@ -64,10 +64,16 @@ export default function AgentNotificationsPage() { const markAsRead = async (id: string) => { try { await notificationsApiService.markAsRead(id); - setNotifications((prev) => - prev.map((n) => (n.id === id ? { ...n, read: true } : n)) - ); + if (filter === 'unread') { + // Remove from list when viewing unread tab + setNotifications((prev) => prev.filter((n) => n.id !== id)); + } else { + setNotifications((prev) => + prev.map((n) => (n.id === id ? { ...n, read: true } : n)) + ); + } setUnreadCount((prev) => Math.max(0, prev - 1)); + setTotalCount((prev) => prev); // total doesn't change, notification still exists } catch (err) { console.error('Failed to mark as read:', err); } @@ -76,7 +82,11 @@ export default function AgentNotificationsPage() { const markAllAsRead = async () => { try { await notificationsApiService.markAllAsRead(); - setNotifications((prev) => prev.map((n) => ({ ...n, read: true }))); + if (filter === 'unread') { + setNotifications([]); + } else { + setNotifications((prev) => prev.map((n) => ({ ...n, read: true }))); + } setUnreadCount(0); } catch (err) { console.error('Failed to mark all as read:', err); diff --git a/src/app/(user)/user/notifications/page.tsx b/src/app/(user)/user/notifications/page.tsx index 225bd17..9a648b7 100644 --- a/src/app/(user)/user/notifications/page.tsx +++ b/src/app/(user)/user/notifications/page.tsx @@ -62,9 +62,13 @@ export default function UserNotificationsPage() { const markAsRead = async (id: string) => { try { await notificationsApiService.markAsRead(id); - setNotifications((prev) => - prev.map((n) => (n.id === id ? { ...n, read: true } : n)) - ); + if (filter === 'unread') { + setNotifications((prev) => prev.filter((n) => n.id !== id)); + } else { + setNotifications((prev) => + prev.map((n) => (n.id === id ? { ...n, read: true } : n)) + ); + } setUnreadCount((prev) => Math.max(0, prev - 1)); } catch (err) { console.error('Failed to mark as read:', err); @@ -74,7 +78,11 @@ export default function UserNotificationsPage() { const markAllAsRead = async () => { try { await notificationsApiService.markAllAsRead(); - setNotifications((prev) => prev.map((n) => ({ ...n, read: true }))); + if (filter === 'unread') { + setNotifications([]); + } else { + setNotifications((prev) => prev.map((n) => ({ ...n, read: true }))); + } setUnreadCount(0); } catch (err) { console.error('Failed to mark all as read:', err);