Skip to content

Commit 50ae32f

Browse files
[WEB-2555] fix: add "mark all as read" in the notifications header (#5770)
* move mark all as read to header and remove it from dropdown * made recommended changes
1 parent 0451593 commit 50ae32f

File tree

2 files changed

+39
-44
lines changed
  • web/core/components/workspace-notifications/sidebar/header/options

2 files changed

+39
-44
lines changed

web/core/components/workspace-notifications/sidebar/header/options/menu-option/root.tsx

Lines changed: 5 additions & 39 deletions
Original file line numberDiff line numberDiff line change
@@ -2,20 +2,14 @@
22

33
import { FC, ReactNode } from "react";
44
import { observer } from "mobx-react";
5-
import { Check, CheckCheck, CheckCircle, Clock } from "lucide-react";
5+
import { Check, CheckCircle, Clock } from "lucide-react";
66
import { TNotificationFilter } from "@plane/types";
7-
import { ArchiveIcon, PopoverMenu, Spinner } from "@plane/ui";
7+
import { ArchiveIcon, PopoverMenu } from "@plane/ui";
88
// components
99
import { NotificationMenuOptionItem } from "@/components/workspace-notifications";
1010
// constants
11-
import { NOTIFICATIONS_READ } from "@/constants/event-tracker";
12-
import { ENotificationLoader } from "@/constants/notification";
1311
// hooks
14-
import { useEventTracker, useWorkspaceNotifications } from "@/hooks/store";
15-
16-
type TNotificationHeaderMenuOption = {
17-
workspaceSlug: string;
18-
};
12+
import { useWorkspaceNotifications } from "@/hooks/store";
1913

2014
export type TPopoverMenuOptions = {
2115
key: string;
@@ -27,44 +21,16 @@ export type TPopoverMenuOptions = {
2721
onClick?: (() => void) | undefined;
2822
};
2923

30-
export const NotificationHeaderMenuOption: FC<TNotificationHeaderMenuOption> = observer((props) => {
31-
const { workspaceSlug } = props;
24+
export const NotificationHeaderMenuOption = observer(() => {
3225
// hooks
33-
const { captureEvent } = useEventTracker();
34-
const { loader, filters, updateFilters, updateBulkFilters, markAllNotificationsAsRead } = useWorkspaceNotifications();
26+
const { filters, updateFilters, updateBulkFilters } = useWorkspaceNotifications();
3527

3628
const handleFilterChange = (filterType: keyof TNotificationFilter, filterValue: boolean) =>
3729
updateFilters(filterType, filterValue);
3830

3931
const handleBulkFilterChange = (filter: Partial<TNotificationFilter>) => updateBulkFilters(filter);
4032

41-
const handleMarkAllNotificationsAsRead = async () => {
42-
// NOTE: We are using loader to prevent continues request when we are making all the notification to read
43-
if (loader) return;
44-
try {
45-
await markAllNotificationsAsRead(workspaceSlug);
46-
} catch (error) {
47-
console.error(error);
48-
}
49-
};
50-
5133
const popoverMenuOptions: TPopoverMenuOptions[] = [
52-
{
53-
key: "menu-mark-all-read",
54-
type: "menu-item",
55-
label: "Mark all as read",
56-
isActive: true,
57-
prependIcon: <CheckCheck className="h-3 w-3" />,
58-
appendIcon: loader === ENotificationLoader.MARK_ALL_AS_READY ? <Spinner height="14px" width="14px" /> : undefined,
59-
onClick: () => {
60-
captureEvent(NOTIFICATIONS_READ);
61-
handleMarkAllNotificationsAsRead();
62-
},
63-
},
64-
{
65-
key: "menu-divider",
66-
type: "divider",
67-
},
6834
{
6935
key: "menu-unread",
7036
type: "menu-item",

web/core/components/workspace-notifications/sidebar/header/options/root.tsx

Lines changed: 34 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,14 @@
11
import { FC } from "react";
22
import { observer } from "mobx-react";
3-
import { RefreshCw } from "lucide-react";
4-
import { Tooltip } from "@plane/ui";
3+
import { CheckCheck, RefreshCw } from "lucide-react";
4+
import { Spinner, Tooltip } from "@plane/ui";
55
// components
66
import { NotificationFilter, NotificationHeaderMenuOption } from "@/components/workspace-notifications";
77
// constants
8+
import { NOTIFICATIONS_READ } from "@/constants/event-tracker";
89
import { ENotificationLoader, ENotificationQueryParamType } from "@/constants/notification";
910
// hooks
10-
import { useWorkspaceNotifications } from "@/hooks/store";
11+
import { useEventTracker, useWorkspaceNotifications } from "@/hooks/store";
1112
import { usePlatformOS } from "@/hooks/use-platform-os";
1213

1314
type TNotificationSidebarHeaderOptions = {
@@ -18,7 +19,8 @@ export const NotificationSidebarHeaderOptions: FC<TNotificationSidebarHeaderOpti
1819
const { workspaceSlug } = props;
1920
// hooks
2021
const { isMobile } = usePlatformOS();
21-
const { loader, getNotifications } = useWorkspaceNotifications();
22+
const { loader, getNotifications, markAllNotificationsAsRead } = useWorkspaceNotifications();
23+
const { captureEvent } = useEventTracker();
2224

2325
const refreshNotifications = async () => {
2426
if (loader) return;
@@ -29,8 +31,35 @@ export const NotificationSidebarHeaderOptions: FC<TNotificationSidebarHeaderOpti
2931
}
3032
};
3133

34+
const handleMarkAllNotificationsAsRead = async () => {
35+
// NOTE: We are using loader to prevent continues request when we are making all the notification to read
36+
if (loader) return;
37+
try {
38+
await markAllNotificationsAsRead(workspaceSlug);
39+
} catch (error) {
40+
console.error(error);
41+
}
42+
};
43+
3244
return (
3345
<div className="relative flex justify-center items-center gap-2 text-sm">
46+
{/* mark all notifications as read*/}
47+
<Tooltip tooltipContent="Mark all as read" isMobile={isMobile} position="bottom">
48+
<div
49+
className="flex-shrink-0 w-5 h-5 flex justify-center items-center overflow-hidden cursor-pointer transition-all hover:bg-custom-background-80 rounded-sm"
50+
onClick={() => {
51+
captureEvent(NOTIFICATIONS_READ);
52+
handleMarkAllNotificationsAsRead();
53+
}}
54+
>
55+
{loader === ENotificationLoader.MARK_ALL_AS_READY ? (
56+
<Spinner height="14px" width="14px" />
57+
) : (
58+
<CheckCheck className="h-3 w-3" />
59+
)}
60+
</div>
61+
</Tooltip>
62+
3463
{/* refetch current notifications */}
3564
<Tooltip tooltipContent="Refresh" isMobile={isMobile} position="bottom">
3665
<div
@@ -45,7 +74,7 @@ export const NotificationSidebarHeaderOptions: FC<TNotificationSidebarHeaderOpti
4574
<NotificationFilter />
4675

4776
{/* notification menu options */}
48-
<NotificationHeaderMenuOption workspaceSlug={workspaceSlug} />
77+
<NotificationHeaderMenuOption />
4978
</div>
5079
);
5180
});

0 commit comments

Comments
 (0)