import { noCase } from 'change-case'; import { useState } from 'react'; // @mui import { Box, List, Badge, Button, Avatar, Tooltip, Divider, Typography, ListItemText, ListSubheader, ListItemAvatar, ListItemButton, } from '@mui/material'; // utils import { fToNow } from '@/utils/formatTime'; // _mock_ import { _notifications } from '@/_mock'; // components import Iconify from '@/components/Iconify'; import Scrollbar from '@/components/Scrollbar'; import MenuPopover from '@/components/MenuPopover'; import { IconButtonAnimate } from '@/components/animate'; // ---------------------------------------------------------------------- export default function NotificationsPopover() { const [notifications, setNotifications] = useState(_notifications); const totalUnRead = notifications.filter((item) => item.isUnRead === true).length; const [open, setOpen] = useState(null); const handleOpen = (event: React.MouseEvent) => { setOpen(event.currentTarget); }; const handleClose = () => { setOpen(null); }; const handleMarkAllAsRead = () => { setNotifications( notifications.map((notification) => ({ ...notification, isUnRead: false, })) ); }; return ( <> Notifications You have {totalUnRead} unread messages {totalUnRead > 0 && ( )} New } > {notifications.slice(0, 2).map((notification) => ( ))} Before that } > {notifications.slice(2, 5).map((notification) => ( ))} ); } // ---------------------------------------------------------------------- type NotificationItemProps = { id: string; title: string; description: string; avatar: string | null; type: string; createdAt: Date; isUnRead: boolean; }; function NotificationItem({ notification }: { notification: NotificationItemProps }) { const { avatar, title } = renderContent(notification); return ( {avatar} {fToNow(notification.createdAt)} } /> ); } // ---------------------------------------------------------------------- function renderContent(notification: NotificationItemProps) { const title = ( {notification.title}   {noCase(notification.description)} ); if (notification.type === 'order_placed') { return { avatar: ( {notification.title} ), title, }; } if (notification.type === 'order_shipped') { return { avatar: ( {notification.title} ), title, }; } if (notification.type === 'mail') { return { avatar: ( {notification.title} ), title, }; } if (notification.type === 'chat_message') { return { avatar: ( {notification.title} ), title, }; } return { avatar: notification.avatar ? {notification.title} : null, title, }; }