@applica-software-guru/react-admin 1.3.174 → 1.3.175

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@applica-software-guru/react-admin",
3
- "version": "1.3.174",
3
+ "version": "1.3.175",
4
4
  "private": false,
5
5
  "repository": {
6
6
  "type": "git",
@@ -1,9 +1,9 @@
1
1
  import { BellOutlined, CheckCircleOutlined } from '@ant-design/icons';
2
2
  import { useLayoutMediaState, useLayoutNotificationsState } from '../../Provider';
3
3
  import { HeaderToggleButton } from '../Buttons';
4
- import { useGetList, useTranslate } from 'ra-core';
4
+ import { useGetList, useNotify, useRefresh, useTranslate, useUpdateMany } from 'ra-core';
5
5
  import { HeaderNotificationItem, INotification } from './NotificationItem';
6
- import { useEffect, useState } from 'react';
6
+ import { useCallback, useEffect, useState } from 'react';
7
7
  import {
8
8
  Badge,
9
9
  ClickAwayListener,
@@ -21,6 +21,7 @@ import { usePopoverState } from '../../../../hooks';
21
21
  import { IconButton, Transitions } from '../../../@extended';
22
22
  import MainCard from '../../../MainCard';
23
23
  import { Link } from 'react-router-dom';
24
+ import dayjs from 'dayjs';
24
25
 
25
26
  const avatarSx = {
26
27
  width: 36,
@@ -45,6 +46,8 @@ function HeaderNotification() {
45
46
  function HeaderNotificationButton() {
46
47
  const translate = useTranslate(),
47
48
  theme = useTheme(),
49
+ refresh = useRefresh(),
50
+ notify = useNotify(),
48
51
  { downMd } = useLayoutMediaState(),
49
52
  { resource } = useLayoutNotificationsState(),
50
53
  [notifications, setNotifications] = useState<Array<INotification>>([]),
@@ -64,6 +67,27 @@ function HeaderNotificationButton() {
64
67
  }
65
68
  }, [data, isLoading]);
66
69
 
70
+ const unreadNotificationIds = notifications.filter((notification) => !notification.readed).map((notification) => notification.id);
71
+
72
+ const [updateMany] = useUpdateMany(
73
+ resource,
74
+ {
75
+ ids: unreadNotificationIds,
76
+ data: { readed: dayjs().format('YYYY-MM-DD HH:mm:ss') }
77
+ },
78
+ {
79
+ onSuccess: () => {
80
+ refresh();
81
+ notify('resources.notifications.messages.readed.done');
82
+ },
83
+ onError: () => notify('ra.notification.readed_error')
84
+ }
85
+ );
86
+
87
+ const handleUpdateMany = useCallback(() => {
88
+ updateMany();
89
+ }, [updateMany]);
90
+
67
91
  return (
68
92
  <>
69
93
  <HeaderToggleButton value="notifications" selected={open} onChange={handleToggle}>
@@ -90,14 +114,14 @@ function HeaderNotificationButton() {
90
114
  >
91
115
  <ClickAwayListener onClickAway={handleClose}>
92
116
  <MainCard
93
- title="Notification"
117
+ title={translate('ra.notification.title')}
94
118
  elevation={0}
95
119
  border={false}
96
120
  content={false}
97
121
  secondary={
98
122
  <>
99
123
  {read > 0 && (
100
- <Tooltip title="Mark as all read">
124
+ <Tooltip title={translate('ra.notification.mark-as-read')} onClick={handleUpdateMany}>
101
125
  {/*@ts-ignore*/}
102
126
  <IconButton color="success" size="small">
103
127
  <CheckCircleOutlined style={{ fontSize: '1.15rem' }} />
@@ -74,9 +74,25 @@ function HeaderNotificationItem(props: IHeaderNotificationItemProps) {
74
74
  <MessageOutlined />
75
75
  </Avatar>
76
76
  </ListItemAvatar>
77
- <ListItemText primary={notification.title} secondary={notification.content} />
77
+ <ListItemText
78
+ sx={{
79
+ overflow: 'hidden',
80
+ wordBreak: 'break-word',
81
+ width: '90%'
82
+ }}
83
+ primary={notification.title}
84
+ secondary={notification.content}
85
+ />
78
86
  <Box flexGrow={1} flexShrink={1} minWidth={theme.spacing(2)} />
79
- <ListItemText primary={ago} primaryTypographyProps={{ variant: 'caption' }} />
87
+ <ListItemText
88
+ sx={{
89
+ overflow: 'hidden',
90
+ whiteSpace: 'pre-wrap',
91
+ wordBreak: 'break-word'
92
+ }}
93
+ primary={ago}
94
+ primaryTypographyProps={{ variant: 'caption' }}
95
+ />
80
96
  </ListItemButton>
81
97
  </ListItem>
82
98
  );
@@ -6,6 +6,8 @@ import { Typography } from '@mui/material';
6
6
  import dayjs from 'dayjs';
7
7
  import { get } from 'lodash';
8
8
  import relativeTime from 'dayjs/plugin/relativeTime';
9
+ import 'dayjs/locale/en';
10
+ import 'dayjs/locale/it';
9
11
 
10
12
  dayjs.extend(relativeTime);
11
13