import React, { Fragment } from "react"; import { Popover, Transition } from "@headlessui/react"; import { Bell } from "lucide-react"; import { observer } from "mobx-react-lite"; // hooks import { useApplication } from "hooks/store"; import useUserNotification from "hooks/use-user-notifications"; import useOutsideClickDetector from "hooks/use-outside-click-detector"; // components import { EmptyState } from "components/common"; import { SnoozeNotificationModal, NotificationCard, NotificationHeader } from "components/notifications"; import { Tooltip } from "@plane/ui"; import { NotificationsLoader } from "components/ui"; // images import emptyNotification from "public/empty-state/notification.svg"; // helpers import { getNumberCount } from "helpers/string.helper"; export const NotificationPopover = observer(() => { // states const [isActive, setIsActive] = React.useState(false); // store hooks const { theme: themeStore } = useApplication(); // refs const notificationPopoverRef = React.useRef(null); const { notifications, archived, readNotification, selectedNotificationForSnooze, selectedTab, setArchived, setReadNotification, setSelectedNotificationForSnooze, setSelectedTab, setSnoozed, snoozed, notificationMutate, markNotificationArchivedStatus, markNotificationReadStatus, markNotificationAsRead, markSnoozeNotification, notificationCount, totalNotificationCount, setSize, isLoadingMore, hasMore, isRefreshing, setFetchNotifications, markAllNotificationsAsRead, } = useUserNotification(); const isSidebarCollapsed = themeStore.sidebarCollapsed; useOutsideClickDetector(notificationPopoverRef, () => { // if snooze modal is open, then don't close the popover if (selectedNotificationForSnooze === null) setIsActive(false); }); return ( <> setSelectedNotificationForSnooze(null)} onSubmit={markSnoozeNotification} notification={notifications?.find((notification) => notification.id === selectedNotificationForSnooze) || null} onSuccess={() => setSelectedNotificationForSnooze(null)} /> <> setIsActive(false)} isRefreshing={isRefreshing} snoozed={snoozed} archived={archived} readNotification={readNotification} selectedTab={selectedTab} setSnoozed={setSnoozed} setArchived={setArchived} setReadNotification={setReadNotification} setSelectedTab={setSelectedTab} markAllNotificationsAsRead={markAllNotificationsAsRead} /> {notifications ? ( notifications.length > 0 ? (
{notifications.map((notification) => ( setIsActive(false)} notification={notification} markNotificationArchivedStatus={markNotificationArchivedStatus} markNotificationReadStatus={markNotificationAsRead} markNotificationReadStatusToggle={markNotificationReadStatus} setSelectedNotificationForSnooze={setSelectedNotificationForSnooze} markSnoozeNotification={markSnoozeNotification} /> ))}
{isLoadingMore && (
Loading...

Loading notifications

)} {hasMore && !isLoadingMore && ( )}
) : (
) ) : ( )}
); });