π₯π₯π₯ Open-source Jira, Linear, Monday, and ClickUp alternative. Plane is a modern project management platform to manage tasks, sprints, docs, and triage.
TypeScript boardsbug-trackerdjangodockerganttissue-trackerjirajira-alternativekanbanlinearpostgresqlproduct-managementproject-managementproject-planningpythonreactredistypesciptvitework-management
[WEB-2555] fix: add "mark all as read" in the notifications header (#5770)
Ketan Sharma50ae32f3e1b3
diff --git a/web/core/components/workspace-notifications/sidebar/header/options/menu-option/root.tsx b/web/core/components/workspace-notifications/sidebar/header/options/menu-option/root.tsxindex ea0eb130f2..c603510cfc 100644--- a/web/core/components/workspace-notifications/sidebar/header/options/menu-option/root.tsx+++ b/web/core/components/workspace-notifications/sidebar/header/options/menu-option/root.tsx@@ -2,20 +2,14 @@import { FC, ReactNode } from "react";import { observer } from "mobx-react";-import { Check, CheckCheck, CheckCircle, Clock } from "lucide-react";+import { Check, CheckCircle, Clock } from "lucide-react";import { TNotificationFilter } from "@plane/types";-import { ArchiveIcon, PopoverMenu, Spinner } from "@plane/ui";+import { ArchiveIcon, PopoverMenu } from "@plane/ui";// componentsimport { NotificationMenuOptionItem } from "@/components/workspace-notifications";// constants-import { NOTIFICATIONS_READ } from "@/constants/event-tracker";-import { ENotificationLoader } from "@/constants/notification";// hooks-import { useEventTracker, useWorkspaceNotifications } from "@/hooks/store";--type TNotificationHeaderMenuOption = {- workspaceSlug: string;-};+import { useWorkspaceNotifications } from "@/hooks/store";export type TPopoverMenuOptions = {key: string;@@ -27,44 +21,16 @@ export type TPopoverMenuOptions = {onClick?: (() => void) | undefined;};-export const NotificationHeaderMenuOption: FC<TNotificationHeaderMenuOption> = observer((props) => {- const { workspaceSlug } = props;+export const NotificationHeaderMenuOption = observer(() => {// hooks- const { captureEvent } = useEventTracker();- const { loader, filters, updateFilters, updateBulkFilters, markAllNotificationsAsRead } = useWorkspaceNotifications();+ const { filters, updateFilters, updateBulkFilters } = useWorkspaceNotifications();const handleFilterChange = (filterType: keyof TNotificationFilter, filterValue: boolean) =>updateFilters(filterType, filterValue);const handleBulkFilterChange = (filter: Partial<TNotificationFilter>) => updateBulkFilters(filter);- const handleMarkAllNotificationsAsRead = async () => {- // NOTE: We are using loader to prevent continues request when we are making all the notification to read- if (loader) return;- try {- await markAllNotificationsAsRead(workspaceSlug);- } catch (error) {- console.error(error);- }- };-const popoverMenuOptions: TPopoverMenuOptions[] = [- {- key: "menu-mark-all-read",- type: "menu-item",- label: "Mark all as read",- isActive: true,- prependIcon: <CheckCheck className="h-3 w-3" />,- appendIcon: loader === ENotificationLoader.MARK_ALL_AS_READY ? <Spinner height="14px" width="14px" /> : undefined,- onClick: () => {- captureEvent(NOTIFICATIONS_READ);- handleMarkAllNotificationsAsRead();- },- },- {- key: "menu-divider",- type: "divider",- },{key: "menu-unread",type: "menu-item",diff --git a/web/core/components/workspace-notifications/sidebar/header/options/root.tsx b/web/core/components/workspace-notifications/sidebar/header/options/root.tsxindex 2fc8c4bde9..8f2caf152a 100644--- a/web/core/components/workspace-notifications/sidebar/header/options/root.tsx+++ b/web/core/components/workspace-notifications/sidebar/header/options/root.tsx@@ -1,13 +1,14 @@import { FC } from "react";import { observer } from "mobx-react";-import { RefreshCw } from "lucide-react";-import { Tooltip } from "@plane/ui";+import { CheckCheck, RefreshCw } from "lucide-react";+import { Spinner, Tooltip } from "@plane/ui";// componentsimport { NotificationFilter, NotificationHeaderMenuOption } from "@/components/workspace-notifications";// constants+import { NOTIFICATIONS_READ } from "@/constants/event-tracker";import { ENotificationLoader, ENotificationQueryParamType } from "@/constants/notification";// hooks-import { useWorkspaceNotifications } from "@/hooks/store";+import { useEventTracker, useWorkspaceNotifications } from "@/hooks/store";import { usePlatformOS } from "@/hooks/use-platform-os";type TNotificationSidebarHeaderOptions = {@@ -18,7 +19,8 @@ export const NotificationSidebarHeaderOptions: FC<TNotificationSidebarHeaderOpticonst { workspaceSlug } = props;// hooksconst { isMobile } = usePlatformOS();- const { loader, getNotifications } = useWorkspaceNotifications();+ const { loader, getNotifications, markAllNotificationsAsRead } = useWorkspaceNotifications();+ const { captureEvent } = useEventTracker();const refreshNotifications = async () => {if (loader) return;@@ -29,8 +31,35 @@ export const NotificationSidebarHeaderOptions: FC<TNotificationSidebarHeaderOpti}};+ const handleMarkAllNotificationsAsRead = async () => {+ // NOTE: We are using loader to prevent continues request when we are making all the notification to read+ if (loader) return;+ try {+ await markAllNotificationsAsRead(workspaceSlug);+ } catch (error) {+ console.error(error);+ }+ };+return (<div className="relative flex justify-center items-center gap-2 text-sm">+ {/* mark all notifications as read*/}+ <Tooltip tooltipContent="Mark all as read" isMobile={isMobile} position="bottom">+ <div+ 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"+ onClick={() => {+ captureEvent(NOTIFICATIONS_READ);+ handleMarkAllNotificationsAsRead();+ }}+ >+ {loader === ENotificationLoader.MARK_ALL_AS_READY ? (+ <Spinner height="14px" width="14px" />+ ) : (+ <CheckCheck className="h-3 w-3" />+ )}+ </div>+ </Tooltip>+{/* refetch current notifications */}<Tooltip tooltipContent="Refresh" isMobile={isMobile} position="bottom"><div@@ -45,7 +74,7 @@ export const NotificationSidebarHeaderOptions: FC<TNotificationSidebarHeaderOpti<NotificationFilter />{/* notification menu options */}- <NotificationHeaderMenuOption workspaceSlug={workspaceSlug} />+ <NotificationHeaderMenuOption /></div>);});