From d78df2bf2e6439b575bea0e6da5968212e0b379e Mon Sep 17 00:00:00 2001 From: canove Date: Tue, 29 Sep 2020 06:20:16 -0300 Subject: [PATCH] fix: deleting a ticket with unreadMessages keeps ticket in notifications --- backend/src/controllers/TicketController.ts | 1 + frontend/src/components/NotificationsPopOver/index.js | 4 ++-- 2 files changed, 3 insertions(+), 2 deletions(-) diff --git a/backend/src/controllers/TicketController.ts b/backend/src/controllers/TicketController.ts index f28e463..d4dd50f 100644 --- a/backend/src/controllers/TicketController.ts +++ b/backend/src/controllers/TicketController.ts @@ -101,6 +101,7 @@ export const remove = async ( const io = getIO(); io.to(ticket.status) .to(ticketId) + .to("notification") .emit("ticket", { action: "delete", ticketId: +ticketId diff --git a/frontend/src/components/NotificationsPopOver/index.js b/frontend/src/components/NotificationsPopOver/index.js index ed53dbb..a08e39f 100644 --- a/frontend/src/components/NotificationsPopOver/index.js +++ b/frontend/src/components/NotificationsPopOver/index.js @@ -73,7 +73,7 @@ const NotificationsPopOver = () => { socket.emit("joinNotification"); socket.on("ticket", data => { - if (data.action === "updateUnread") { + if (data.action === "updateUnread" || data.action === "delete") { setNotifications(prevState => { const ticketIndex = prevState.findIndex(t => t.id === data.ticketId); if (ticketIndex !== -1) { @@ -103,7 +103,7 @@ const NotificationsPopOver = () => { (ticketIdRef.current && data.message.ticketId === ticketIdRef.current && document.visibilityState === "visible") || - (data.ticket.userId !== userId && data.ticket.userId) + (data.ticket.userId && data.ticket.userId !== userId) ) return; else {