import React, { Fragment } from "react"; import { observer } from "mobx-react-lite"; import { Popover, Transition } from "@headlessui/react"; import { Bell } from "lucide-react"; // hooks import { Tooltip } from "@plane/ui"; import { EmptyState } from "components/common"; import { SnoozeNotificationModal, NotificationCard, NotificationHeader } from "components/notifications"; import { NotificationsLoader } from "components/ui"; import { getNumberCount } from "helpers/string.helper"; import { useApplication } from "hooks/store"; import useOutsideClickDetector from "hooks/use-outside-click-detector"; import useUserNotification from "hooks/use-user-notifications"; // components // images import emptyNotification from "public/empty-state/notification.svg"; // helpers 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 && ( )}
) : (
) ) : ( )}
); });