import React, { Fragment } from "react"; import { observer } from "mobx-react-lite"; import { Bell } from "lucide-react"; import { Popover, Transition } from "@headlessui/react"; // hooks // icons // components import { Tooltip } from "@plane/ui"; import { EmptyState } from "@/components/empty-state"; import { SnoozeNotificationModal, NotificationCard, NotificationHeader } from "@/components/notifications"; import { NotificationsLoader } from "@/components/ui"; // constants import { EmptyStateType } from "@/constants/empty-state"; // helpers import { getNumberCount } from "@/helpers/string.helper"; import { useApplication } from "@/hooks/store"; import useOutsideClickDetector from "@/hooks/use-outside-click-detector"; import { usePlatformOS } from "@/hooks/use-platform-os"; import useUserNotification from "@/hooks/use-user-notifications"; export const NotificationPopover = observer(() => { // states const [isActive, setIsActive] = React.useState(false); // store hooks const { theme: themeStore } = useApplication(); // refs const notificationPopoverRef = React.useRef(null); // hooks const { isMobile } = usePlatformOS(); 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); }); const currentTabEmptyState = snoozed ? EmptyStateType.NOTIFICATION_SNOOZED_EMPTY_STATE : archived ? EmptyStateType.NOTIFICATION_ARCHIVED_EMPTY_STATE : selectedTab === "created" ? EmptyStateType.NOTIFICATION_CREATED_EMPTY_STATE : selectedTab === "watching" ? EmptyStateType.NOTIFICATION_SUBSCRIBED_EMPTY_STATE : EmptyStateType.NOTIFICATION_MY_ISSUE_EMPTY_STATE; 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 && ( )}
) : (
) ) : ( )}
); });