mirror of
https://github.com/makeplane/plane.git
synced 2026-02-14 10:49:49 -06:00
[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
This commit is contained in:
@@ -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<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",
|
||||
|
||||
@@ -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<TNotificationSidebarHeaderOpti
|
||||
const { workspaceSlug } = props;
|
||||
// hooks
|
||||
const { 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>
|
||||
);
|
||||
});
|
||||
|
||||
Reference in New Issue
Block a user