From 50ae32f3e1b37b1d861b3082ba0dcd6e71cea94a Mon Sep 17 00:00:00 2001 From: Ketan Sharma Date: Tue, 8 Oct 2024 17:13:35 +0530 Subject: [PATCH] [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 --- .../header/options/menu-option/root.tsx | 44 +++---------------- .../sidebar/header/options/root.tsx | 39 +++++++++++++--- 2 files changed, 39 insertions(+), 44 deletions(-) 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.tsx index 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"; // components import { 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 = 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) => 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: , - appendIcon: loader === ENotificationLoader.MARK_ALL_AS_READY ? : 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.tsx index 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"; // components import { 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 { if (loader) return; @@ -29,8 +31,35 @@ export const NotificationSidebarHeaderOptions: FC { + // 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 (
+ {/* mark all notifications as read*/} + +
{ + captureEvent(NOTIFICATIONS_READ); + handleMarkAllNotificationsAsRead(); + }} + > + {loader === ENotificationLoader.MARK_ALL_AS_READY ? ( + + ) : ( + + )} +
+
+ {/* refetch current notifications */}
{/* notification menu options */} - +
); });