import React, { Fragment } from "react"; import Image from "next/image"; import { useRouter } from "next/router"; // hooks import useTheme from "hooks/use-theme"; import { Popover, Transition } from "@headlessui/react"; // hooks import useWorkspaceMembers from "hooks/use-workspace-members"; import useUserNotification from "hooks/use-user-notifications"; // components import { Spinner, Icon } from "components/ui"; import { SnoozeNotificationModal, NotificationCard } from "components/notifications"; // helpers import { getNumberCount } from "helpers/string.helper"; // type import type { NotificationType } from "types"; export const NotificationPopover = () => { const { notifications, archived, readNotification, selectedNotificationForSnooze, selectedTab, setArchived, setReadNotification, setSelectedNotificationForSnooze, setSelectedTab, setSnoozed, snoozed, notificationsMutate, markNotificationArchivedStatus, markNotificationReadStatus, markSnoozeNotification, notificationCount, totalNotificationCount, } = useUserNotification(); const router = useRouter(); const { workspaceSlug } = router.query; const { isOwner, isMember } = useWorkspaceMembers(workspaceSlug?.toString() ?? ""); // theme context const { collapsed: sidebarCollapse } = useTheme(); const notificationTabs: Array<{ label: string; value: NotificationType; unreadCount?: number; }> = [ { label: "My Issues", value: "assigned", unreadCount: notificationCount?.my_issues, }, { label: "Created by me", value: "created", unreadCount: notificationCount?.created_issues, }, { label: "Subscribed", value: "watching", unreadCount: notificationCount?.watching_notifications, }, ]; return ( <> setSelectedNotificationForSnooze(null)} onSubmit={markSnoozeNotification} notification={ notifications?.find( (notification) => notification.id === selectedNotificationForSnooze ) || null } onSuccess={() => { notificationsMutate(); setSelectedNotificationForSnooze(null); }} /> {({ open: isActive, close: closePopover }) => ( <> {sidebarCollapse ? null : Notifications} {totalNotificationCount && totalNotificationCount > 0 ? ( {getNumberCount(totalNotificationCount)} ) : null}

Notifications

{snoozed || archived || readNotification ? (
) : (
)}
{notifications ? ( notifications.filter( (notification) => notification.data.issue_activity.field !== "None" ).length > 0 ? ( notifications.map((notification) => ( )) ) : (
Empty

You{"'"}re updated with all the notifications

You have read all the notifications.

) ) : (
)}
)}
); };