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 { useStore } from 'zustand'; import { AlertCircle, Bell, CheckCircle, Trash2 } from 'lucide-react'; import { AutomationTestingProps } from '@/types'; import { useUser } from '@/react/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 reducedNotifications = userNotifications?.slice(0, 50); 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, notification, onDelete }: MenuLinkProps) { const anchorProps = useSref(to, params); return ({notification.title}
{notification.details}
{formatTime(notification.timeStamp)}