datastake-daf 0.6.668 → 0.6.670
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/dist/context/index.js +173 -4
- package/dist/layouts/index.js +1339 -285
- package/package.json +1 -1
- package/src/@daf/layouts/AppLayout/components/Notifications/NotificationHistory/index.js +74 -6
- package/src/@daf/layouts/AppLayout/components/Notifications/NotificationHistory/style.js +59 -0
- package/src/@daf/layouts/AppLayout/components/Notifications/config.js +12 -0
- package/src/@daf/layouts/AppLayout/components/Notifications/index.js +2 -0
- package/src/@daf/layouts/AppLayout/index.jsx +4 -0
- package/src/context.js +2 -1
package/dist/context/index.js
CHANGED
|
@@ -7,11 +7,13 @@ var jsxRuntime = require('react/jsx-runtime');
|
|
|
7
7
|
var icons = require('@ant-design/icons');
|
|
8
8
|
var antd = require('antd');
|
|
9
9
|
var axios = require('axios');
|
|
10
|
+
var moment = require('moment');
|
|
10
11
|
|
|
11
12
|
function _interopDefaultLegacy (e) { return e && typeof e === 'object' && 'default' in e ? e : { 'default': e }; }
|
|
12
13
|
|
|
13
14
|
var React__default = /*#__PURE__*/_interopDefaultLegacy(React);
|
|
14
15
|
var axios__default = /*#__PURE__*/_interopDefaultLegacy(axios);
|
|
16
|
+
var moment__default = /*#__PURE__*/_interopDefaultLegacy(moment);
|
|
15
17
|
|
|
16
18
|
const _isCollapsed = typeof localStorage.getItem('is_collapsed') === 'string' ? localStorage.getItem('is_collapsed') === 'true' ? true : false : true;
|
|
17
19
|
const _isNestedSidebarCollapsed = typeof localStorage.getItem('is_nested_sidebar_collapsed') === 'string' ? localStorage.getItem('is_nested_sidebar_collapsed') === 'true' : true;
|
|
@@ -1295,7 +1297,7 @@ class NotificationService extends BaseService {
|
|
|
1295
1297
|
}
|
|
1296
1298
|
var NotificationService$1 = createLazyService(NotificationService);
|
|
1297
1299
|
|
|
1298
|
-
function useNotifications({
|
|
1300
|
+
function useNotifications$1({
|
|
1299
1301
|
status = 'unread'
|
|
1300
1302
|
}) {
|
|
1301
1303
|
const [total, setTotal] = React.useState(0);
|
|
@@ -1370,7 +1372,7 @@ function useNotifications({
|
|
|
1370
1372
|
};
|
|
1371
1373
|
}
|
|
1372
1374
|
|
|
1373
|
-
const status = 'all';
|
|
1375
|
+
const status$1 = 'all';
|
|
1374
1376
|
const NotificationsHistoryContext = /*#__PURE__*/React.createContext({
|
|
1375
1377
|
loading: false,
|
|
1376
1378
|
_notifications: [],
|
|
@@ -1387,8 +1389,8 @@ const NotificationsHistoryProvider = ({
|
|
|
1387
1389
|
_notifications,
|
|
1388
1390
|
_fetch,
|
|
1389
1391
|
total
|
|
1390
|
-
} = useNotifications({
|
|
1391
|
-
status
|
|
1392
|
+
} = useNotifications$1({
|
|
1393
|
+
status: status$1
|
|
1392
1394
|
});
|
|
1393
1395
|
const value = {
|
|
1394
1396
|
loading,
|
|
@@ -1406,6 +1408,170 @@ const useNotificationsHistoryContext = () => {
|
|
|
1406
1408
|
return value;
|
|
1407
1409
|
};
|
|
1408
1410
|
|
|
1411
|
+
const useNotifications = ({
|
|
1412
|
+
status = 'unread',
|
|
1413
|
+
user,
|
|
1414
|
+
fetchNotifications,
|
|
1415
|
+
markAsRead,
|
|
1416
|
+
markAllAsRead
|
|
1417
|
+
}) => {
|
|
1418
|
+
const [loading, setLoading] = React.useState(false);
|
|
1419
|
+
const [notifications, setNotifications] = React.useState([]);
|
|
1420
|
+
const [total, setTotal] = React.useState(0);
|
|
1421
|
+
const [page, setPage] = React.useState(0);
|
|
1422
|
+
const [hasMore, setHasMore] = React.useState(true);
|
|
1423
|
+
const isFetching = React.useRef(false);
|
|
1424
|
+
const _notifications = React.useMemo(() => {
|
|
1425
|
+
return notifications.filter(n => !n.read);
|
|
1426
|
+
}, [notifications]);
|
|
1427
|
+
const _fetch = React.useCallback(async () => {
|
|
1428
|
+
if (!fetchNotifications || isFetching.current || !hasMore || loading) {
|
|
1429
|
+
return;
|
|
1430
|
+
}
|
|
1431
|
+
try {
|
|
1432
|
+
isFetching.current = true;
|
|
1433
|
+
setLoading(true);
|
|
1434
|
+
const response = await fetchNotifications({
|
|
1435
|
+
page: page + 1,
|
|
1436
|
+
status,
|
|
1437
|
+
limit: 20
|
|
1438
|
+
});
|
|
1439
|
+
const newNotifications = response.data || [];
|
|
1440
|
+
if (newNotifications.length === 0) {
|
|
1441
|
+
setHasMore(false);
|
|
1442
|
+
} else {
|
|
1443
|
+
setNotifications(prev => [...prev, ...newNotifications]);
|
|
1444
|
+
setPage(p => p + 1);
|
|
1445
|
+
}
|
|
1446
|
+
setTotal(response.total || 0);
|
|
1447
|
+
} catch (err) {
|
|
1448
|
+
console.error('Error fetching notifications:', err);
|
|
1449
|
+
} finally {
|
|
1450
|
+
setLoading(false);
|
|
1451
|
+
isFetching.current = false;
|
|
1452
|
+
}
|
|
1453
|
+
}, [fetchNotifications, page, status, hasMore, loading]);
|
|
1454
|
+
const removeNotification = React.useCallback(async id => {
|
|
1455
|
+
try {
|
|
1456
|
+
if (markAsRead) {
|
|
1457
|
+
await markAsRead(id);
|
|
1458
|
+
}
|
|
1459
|
+
setNotifications(prev => prev.map(n => n.id === id ? {
|
|
1460
|
+
...n,
|
|
1461
|
+
read: true
|
|
1462
|
+
} : n));
|
|
1463
|
+
setTotal(t => Math.max(0, t - 1));
|
|
1464
|
+
} catch (err) {
|
|
1465
|
+
console.error('Error removing notification:', err);
|
|
1466
|
+
}
|
|
1467
|
+
}, [markAsRead]);
|
|
1468
|
+
const clearAll = React.useCallback(async () => {
|
|
1469
|
+
try {
|
|
1470
|
+
if (markAllAsRead) {
|
|
1471
|
+
await markAllAsRead();
|
|
1472
|
+
}
|
|
1473
|
+
setNotifications(prev => prev.map(n => ({
|
|
1474
|
+
...n,
|
|
1475
|
+
read: true
|
|
1476
|
+
})));
|
|
1477
|
+
setTotal(0);
|
|
1478
|
+
} catch (err) {
|
|
1479
|
+
console.error('Error clearing notifications:', err);
|
|
1480
|
+
}
|
|
1481
|
+
}, [markAllAsRead]);
|
|
1482
|
+
const addNotification = React.useCallback(notification => {
|
|
1483
|
+
setNotifications(prev => [notification, ...prev]);
|
|
1484
|
+
setTotal(t => t + 1);
|
|
1485
|
+
}, []);
|
|
1486
|
+
|
|
1487
|
+
// Initial fetch
|
|
1488
|
+
React.useEffect(() => {
|
|
1489
|
+
if (user) {
|
|
1490
|
+
_fetch();
|
|
1491
|
+
}
|
|
1492
|
+
}, [user]);
|
|
1493
|
+
return {
|
|
1494
|
+
loading,
|
|
1495
|
+
_notifications,
|
|
1496
|
+
_fetch,
|
|
1497
|
+
total,
|
|
1498
|
+
clearAll,
|
|
1499
|
+
removeNotification,
|
|
1500
|
+
addNotification
|
|
1501
|
+
};
|
|
1502
|
+
};
|
|
1503
|
+
|
|
1504
|
+
/* eslint-disable react/prop-types */
|
|
1505
|
+
const status = 'unread';
|
|
1506
|
+
const NotificationsContext = /*#__PURE__*/React.createContext({
|
|
1507
|
+
loading: false,
|
|
1508
|
+
_notifications: [],
|
|
1509
|
+
_fetch: () => {},
|
|
1510
|
+
total: 0,
|
|
1511
|
+
clearAll: () => {},
|
|
1512
|
+
removeNotification: () => {}
|
|
1513
|
+
});
|
|
1514
|
+
const NotificationsProvider = ({
|
|
1515
|
+
children,
|
|
1516
|
+
user,
|
|
1517
|
+
notificationHandlers = {},
|
|
1518
|
+
NotificationsHistoryProvider,
|
|
1519
|
+
firebaseEnabled = true,
|
|
1520
|
+
useFirebaseHook
|
|
1521
|
+
}) => {
|
|
1522
|
+
const {
|
|
1523
|
+
loading,
|
|
1524
|
+
_notifications,
|
|
1525
|
+
_fetch,
|
|
1526
|
+
total,
|
|
1527
|
+
addNotification,
|
|
1528
|
+
clearAll,
|
|
1529
|
+
removeNotification
|
|
1530
|
+
} = useNotifications({
|
|
1531
|
+
status,
|
|
1532
|
+
user,
|
|
1533
|
+
...notificationHandlers
|
|
1534
|
+
});
|
|
1535
|
+
const value = {
|
|
1536
|
+
loading,
|
|
1537
|
+
_notifications,
|
|
1538
|
+
_fetch,
|
|
1539
|
+
total,
|
|
1540
|
+
clearAll,
|
|
1541
|
+
removeNotification
|
|
1542
|
+
};
|
|
1543
|
+
const onMessage = React.useCallback(notification => {
|
|
1544
|
+
let data = {};
|
|
1545
|
+
try {
|
|
1546
|
+
data = JSON.parse(notification.data?.data);
|
|
1547
|
+
} catch (err) {
|
|
1548
|
+
console.log(err);
|
|
1549
|
+
}
|
|
1550
|
+
addNotification({
|
|
1551
|
+
id: notification.messageId,
|
|
1552
|
+
type: notification.data?.type,
|
|
1553
|
+
title: notification.notification?.title,
|
|
1554
|
+
body: notification.notification?.body,
|
|
1555
|
+
createdAt: moment__default["default"]().toString(),
|
|
1556
|
+
data: data,
|
|
1557
|
+
read: false
|
|
1558
|
+
});
|
|
1559
|
+
}, [addNotification]);
|
|
1560
|
+
|
|
1561
|
+
// Only use Firebase if enabled and hook provided
|
|
1562
|
+
if (firebaseEnabled && useFirebaseHook) {
|
|
1563
|
+
useFirebaseHook(onMessage);
|
|
1564
|
+
}
|
|
1565
|
+
return /*#__PURE__*/jsxRuntime.jsx(NotificationsContext.Provider, {
|
|
1566
|
+
value: value,
|
|
1567
|
+
children: children
|
|
1568
|
+
});
|
|
1569
|
+
};
|
|
1570
|
+
const useNotificationsContext = () => {
|
|
1571
|
+
const value = React.useContext(NotificationsContext);
|
|
1572
|
+
return value;
|
|
1573
|
+
};
|
|
1574
|
+
|
|
1409
1575
|
exports.ApplicationsContext = ApplicationsContext;
|
|
1410
1576
|
exports.ApplicationsProvider = ApplicationsProvider;
|
|
1411
1577
|
exports.DasbhoardCacheProvider = DasbhoardCacheProvider;
|
|
@@ -1417,8 +1583,10 @@ exports.HistoryProvider = HistoryProvider;
|
|
|
1417
1583
|
exports.LinkingContext = LinkingContext;
|
|
1418
1584
|
exports.LinkingProvider = LinkingProvider;
|
|
1419
1585
|
exports.NOTIFICATION_MODE = NOTIFICATION_MODE;
|
|
1586
|
+
exports.NotificationsContext = NotificationsContext;
|
|
1420
1587
|
exports.NotificationsHistoryContext = NotificationsHistoryContext;
|
|
1421
1588
|
exports.NotificationsHistoryProvider = NotificationsHistoryProvider;
|
|
1589
|
+
exports.NotificationsProvider = NotificationsProvider;
|
|
1422
1590
|
exports.ProjectSourcesContext = ProjectSourcesContext;
|
|
1423
1591
|
exports.ProjectSourcesProvider = ProjectSourcesProvider;
|
|
1424
1592
|
exports.ResizeProvider = ResizeProvider;
|
|
@@ -1430,5 +1598,6 @@ exports.useDasbhoardCache = useDasbhoardCache;
|
|
|
1430
1598
|
exports.useForms = useForms;
|
|
1431
1599
|
exports.useGeneralContext = useGeneralContext;
|
|
1432
1600
|
exports.useHistory = useHistory;
|
|
1601
|
+
exports.useNotificationsContext = useNotificationsContext;
|
|
1433
1602
|
exports.useNotificationsHistoryContext = useNotificationsHistoryContext;
|
|
1434
1603
|
exports.useResizeContext = useResizeContext;
|