import { HeaderNotificationItem, INotification } from './NotificationItem'; import { IconButton, Transitions } from '@/components/@extended'; import { HeaderToggleButton } from '@/components/Layout/Header/Buttons'; import { useLayoutMediaState, useLayoutNotificationsState } from '@/components/Layout/Provider'; import { MainCard } from '@/components/MainCard'; import { PushNotificationToggleButton } from '@/components/ra-buttons'; import { Empty } from '@/components/ra-lists'; import { usePopoverState } from '@/hooks'; import { PushNotificationConfig } from '@/hooks/usePushNotifications'; import { BellOutlined, CheckCircleOutlined } from '@ant-design/icons'; import { Badge, ClickAwayListener, Divider, List, ListItemButton, ListItemText, Paper, Popper, Tooltip, Typography, useTheme } from '@mui/material'; import dayjs from 'dayjs'; import { useGetList, useNotify, useRefresh, useTranslate, useUpdateMany } from 'ra-core'; import { useCallback, useEffect, useState } from 'react'; import { Link } from 'react-router-dom'; const avatarSx = { width: 36, height: 36, fontSize: '1rem' }; const actionSx = { mt: '6px', ml: 1, top: 'auto', right: 'auto', alignSelf: 'flex-start', transform: 'none' }; type HeaderNotificationProps = { pushNotifications?: PushNotificationConfig; }; function HeaderNotification({ pushNotifications }: HeaderNotificationProps) { const { enable } = useLayoutNotificationsState(); return enable ? : null; } type HeaderNotificationButtonProps = { pushNotifications?: PushNotificationConfig; }; function HeaderNotificationButton({ pushNotifications }: HeaderNotificationButtonProps) { const translate = useTranslate(); const theme = useTheme(); const refresh = useRefresh(); const notify = useNotify(); const { downMd } = useLayoutMediaState(); const { resource } = useLayoutNotificationsState(); const [notifications, setNotifications] = useState>([]); const { data, isLoading } = useGetList(resource, { pagination: { page: 1, perPage: 25 }, sort: { field: 'created', order: 'DESC' }, filter: { readed: false } }); const read = notifications.filter((item) => item.readed === null).length; const { open, anchorEl, handleClose, handleToggle } = usePopoverState(); useEffect(() => { if (!isLoading && data) { setNotifications(data ?? []); } }, [data, isLoading]); const unreadNotificationIds = notifications .filter((notification) => !notification.readed) .map((notification) => notification.id); const [updateMany] = useUpdateMany( resource, { ids: unreadNotificationIds, data: { readed: dayjs().toISOString() } }, { onSuccess: () => { refresh(); notify('resources.notifications.messages.readed.done'); }, onError: () => notify('ra.notification.readed_error') } ); const handleUpdateMany = useCallback(() => { updateMany(); }, [updateMany]); return ( <> {({ TransitionProps }) => ( //@ts-ignore {pushNotifications ? : null} {read > 0 && ( {/*@ts-ignore*/} )} } > {notifications.length === 0 ? ( {translate('ra.notification.empty')} } sx={{ '& .ApplicaEmpty-icon': { fontSize: '60px' }, '& .ApplicaEmpty-toolbar': { display: 'none' } }} /> ) : ( <> {notifications.map((item, index) => ( 0} notification={item} onClick={handleClose} divider={index < notifications.length - 1} /> ))} {/*@ts-ignore*/} {translate('ra.notification.view_all')} } /> )} )} ); } export { HeaderNotification };