forked from github/plane
fix: notification read status being toggled when click on link (#1769)
This commit is contained in:
parent
a1ae338c37
commit
5aad6c71da
@ -27,6 +27,7 @@ import { snoozeOptions } from "constants/notification";
|
|||||||
type NotificationCardProps = {
|
type NotificationCardProps = {
|
||||||
notification: IUserNotification;
|
notification: IUserNotification;
|
||||||
markNotificationReadStatus: (notificationId: string) => Promise<void>;
|
markNotificationReadStatus: (notificationId: string) => Promise<void>;
|
||||||
|
markNotificationReadStatusToggle: (notificationId: string) => Promise<void>;
|
||||||
markNotificationArchivedStatus: (notificationId: string) => Promise<void>;
|
markNotificationArchivedStatus: (notificationId: string) => Promise<void>;
|
||||||
setSelectedNotificationForSnooze: (notificationId: string) => void;
|
setSelectedNotificationForSnooze: (notificationId: string) => void;
|
||||||
markSnoozeNotification: (notificationId: string, dateTime?: Date | undefined) => Promise<void>;
|
markSnoozeNotification: (notificationId: string, dateTime?: Date | undefined) => Promise<void>;
|
||||||
@ -36,6 +37,7 @@ export const NotificationCard: React.FC<NotificationCardProps> = (props) => {
|
|||||||
const {
|
const {
|
||||||
notification,
|
notification,
|
||||||
markNotificationReadStatus,
|
markNotificationReadStatus,
|
||||||
|
markNotificationReadStatusToggle,
|
||||||
markNotificationArchivedStatus,
|
markNotificationArchivedStatus,
|
||||||
setSelectedNotificationForSnooze,
|
setSelectedNotificationForSnooze,
|
||||||
markSnoozeNotification,
|
markSnoozeNotification,
|
||||||
@ -159,7 +161,7 @@ export const NotificationCard: React.FC<NotificationCardProps> = (props) => {
|
|||||||
name: notification.read_at ? "Mark as unread" : "Mark as read",
|
name: notification.read_at ? "Mark as unread" : "Mark as read",
|
||||||
icon: "chat_bubble",
|
icon: "chat_bubble",
|
||||||
onClick: () => {
|
onClick: () => {
|
||||||
markNotificationReadStatus(notification.id).then(() => {
|
markNotificationReadStatusToggle(notification.id).then(() => {
|
||||||
setToastAlert({
|
setToastAlert({
|
||||||
title: notification.read_at
|
title: notification.read_at
|
||||||
? "Notification marked as unread"
|
? "Notification marked as unread"
|
||||||
|
@ -38,6 +38,7 @@ export const NotificationPopover = () => {
|
|||||||
notificationMutate,
|
notificationMutate,
|
||||||
markNotificationArchivedStatus,
|
markNotificationArchivedStatus,
|
||||||
markNotificationReadStatus,
|
markNotificationReadStatus,
|
||||||
|
markNotificationAsRead,
|
||||||
markSnoozeNotification,
|
markSnoozeNotification,
|
||||||
notificationCount,
|
notificationCount,
|
||||||
totalNotificationCount,
|
totalNotificationCount,
|
||||||
@ -128,7 +129,8 @@ export const NotificationPopover = () => {
|
|||||||
key={notification.id}
|
key={notification.id}
|
||||||
notification={notification}
|
notification={notification}
|
||||||
markNotificationArchivedStatus={markNotificationArchivedStatus}
|
markNotificationArchivedStatus={markNotificationArchivedStatus}
|
||||||
markNotificationReadStatus={markNotificationReadStatus}
|
markNotificationReadStatus={markNotificationAsRead}
|
||||||
|
markNotificationReadStatusToggle={markNotificationReadStatus}
|
||||||
setSelectedNotificationForSnooze={setSelectedNotificationForSnooze}
|
setSelectedNotificationForSnooze={setSelectedNotificationForSnooze}
|
||||||
markSnoozeNotification={markSnoozeNotification}
|
markSnoozeNotification={markSnoozeNotification}
|
||||||
/>
|
/>
|
||||||
|
@ -185,6 +185,26 @@ const useUserNotification = () => {
|
|||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
|
const markNotificationAsRead = async (notificationId: string) => {
|
||||||
|
if (!workspaceSlug) return;
|
||||||
|
|
||||||
|
const isRead =
|
||||||
|
notifications?.find((notification) => notification.id === notificationId)?.read_at !== null;
|
||||||
|
|
||||||
|
if (isRead) return;
|
||||||
|
|
||||||
|
mutateNotification(notificationId, { read_at: new Date() });
|
||||||
|
handleReadMutation("read");
|
||||||
|
|
||||||
|
await userNotificationServices
|
||||||
|
.markUserNotificationAsRead(workspaceSlug.toString(), notificationId)
|
||||||
|
.catch(() => {
|
||||||
|
throw new Error("Something went wrong");
|
||||||
|
});
|
||||||
|
|
||||||
|
mutateNotificationCount();
|
||||||
|
};
|
||||||
|
|
||||||
const markNotificationArchivedStatus = async (notificationId: string) => {
|
const markNotificationArchivedStatus = async (notificationId: string) => {
|
||||||
if (!workspaceSlug) return;
|
if (!workspaceSlug) return;
|
||||||
const isArchived =
|
const isArchived =
|
||||||
@ -283,6 +303,7 @@ const useUserNotification = () => {
|
|||||||
hasMore,
|
hasMore,
|
||||||
isRefreshing,
|
isRefreshing,
|
||||||
setFetchNotifications,
|
setFetchNotifications,
|
||||||
|
markNotificationAsRead,
|
||||||
};
|
};
|
||||||
};
|
};
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user