import clsx from 'clsx'; import { Menu, MenuButton, MenuList, MenuLink as ReachMenuLink, } from '@reach/menu-button'; import { UISrefProps, useSref } from '@uirouter/react'; import Moment from 'moment'; import { useEffect, useState } from 'react'; import { useStore } from 'zustand'; import { AutomationTestingProps } from '@/types'; import { useUser } from '@/portainer/hooks/useUser'; import { ToastNotification } from '@/react/portainer/notifications/types'; import { Icon } from '@@/Icon'; import { Link } from '@@/Link'; import { Button } from '@@/buttons'; import { notificationsStore } from '../../portainer/notifications/notifications-store'; import headerStyles from './HeaderTitle.module.css'; import notificationStyles from './NotificationsMenu.module.css'; export function NotificationsMenu() { const notificationsStoreState = useStore(notificationsStore); const { removeNotification } = notificationsStoreState; const { clearUserNotifications } = notificationsStoreState; const { user } = useUser(); const userNotifications: ToastNotification[] = useStore( notificationsStore, (state) => state.userNotifications[user.Id] ); const [badge, setBadge] = useState(false); useEffect(() => { if (userNotifications?.length > 0) { setBadge(true); } else { setBadge(false); } }, [userNotifications]); return (
); function onDelete(notificationId: string) { removeNotification(user.Id, notificationId); } function onClear() { clearUserNotifications(user.Id); } } interface MenuLinkProps extends AutomationTestingProps, UISrefProps { notification: ToastNotification; onDelete: () => void; } function MenuLink({ to, params, options, notification, onDelete, }: MenuLinkProps) { const anchorProps = useSref(to, params, options); return ({notification.title}
{notification.details}
{formatTime(notification.timeStamp)}