datastake-daf 0.6.536 → 0.6.538
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 +143 -0
- package/dist/hooks/index.js +4691 -2
- package/package.json +2 -1
- package/rollup.config.js +1 -0
- package/src/@daf/core/context/Notifications/NotificationsHistory/index.js +28 -0
- package/src/@daf/core/context/Notifications/useNotifications.js +84 -0
- package/src/@daf/hooks/useFirebase.js +53 -0
- package/src/@daf/hooks/useIsDatastake.js +21 -0
- package/src/context.js +3 -2
- package/src/hooks.js +2 -1
package/dist/context/index.js
CHANGED
|
@@ -1214,6 +1214,10 @@ const ApplicationsProvider = ({
|
|
|
1214
1214
|
children: children
|
|
1215
1215
|
});
|
|
1216
1216
|
};
|
|
1217
|
+
const useApplications = () => {
|
|
1218
|
+
const value = React.useContext(ApplicationsContext);
|
|
1219
|
+
return value;
|
|
1220
|
+
};
|
|
1217
1221
|
|
|
1218
1222
|
const ProjectSourcesContext = /*#__PURE__*/React.createContext({
|
|
1219
1223
|
info: [],
|
|
@@ -1290,6 +1294,141 @@ const SelectProvider = ({
|
|
|
1290
1294
|
});
|
|
1291
1295
|
};
|
|
1292
1296
|
|
|
1297
|
+
class NotificationService extends BaseService {
|
|
1298
|
+
get({
|
|
1299
|
+
status = 'unread'
|
|
1300
|
+
}) {
|
|
1301
|
+
return this.apiGet({
|
|
1302
|
+
url: `/notifications`,
|
|
1303
|
+
params: {
|
|
1304
|
+
status
|
|
1305
|
+
}
|
|
1306
|
+
});
|
|
1307
|
+
}
|
|
1308
|
+
readAll() {
|
|
1309
|
+
return this.apiPut({
|
|
1310
|
+
url: `/notifications/read/all`
|
|
1311
|
+
});
|
|
1312
|
+
}
|
|
1313
|
+
readOne(id) {
|
|
1314
|
+
return this.apiPut({
|
|
1315
|
+
url: `/notifications/read/${id}`
|
|
1316
|
+
});
|
|
1317
|
+
}
|
|
1318
|
+
}
|
|
1319
|
+
var NotificationService$1 = createLazyService(NotificationService);
|
|
1320
|
+
|
|
1321
|
+
function useNotifications({
|
|
1322
|
+
status = 'unread'
|
|
1323
|
+
}) {
|
|
1324
|
+
const [total, setTotal] = React.useState(0);
|
|
1325
|
+
const [loading, setLoading] = React.useState(false);
|
|
1326
|
+
const [notifications, setNotifications] = React.useState([]);
|
|
1327
|
+
const addNotification = React.useCallback(notification => {
|
|
1328
|
+
if (notification) {
|
|
1329
|
+
// push
|
|
1330
|
+
setTotal(p => p + 1);
|
|
1331
|
+
setNotifications(p => [...p, notification]);
|
|
1332
|
+
}
|
|
1333
|
+
}, []);
|
|
1334
|
+
const removeNotification = React.useCallback(async id => {
|
|
1335
|
+
try {
|
|
1336
|
+
await NotificationService$1.readOne(id);
|
|
1337
|
+
setTotal(p => p - 1);
|
|
1338
|
+
setNotifications(p => p.filter(n => n.id !== id));
|
|
1339
|
+
} catch (err) {
|
|
1340
|
+
console.log(err);
|
|
1341
|
+
// TO-DO Remove this
|
|
1342
|
+
setTotal(p => p - 1);
|
|
1343
|
+
setNotifications(p => p.filter(n => n.id !== id));
|
|
1344
|
+
}
|
|
1345
|
+
}, []);
|
|
1346
|
+
const clearAll = React.useCallback(async () => {
|
|
1347
|
+
try {
|
|
1348
|
+
await NotificationService$1.readAll();
|
|
1349
|
+
setTotal(0);
|
|
1350
|
+
setNotifications([]);
|
|
1351
|
+
} catch (err) {
|
|
1352
|
+
console.log(err);
|
|
1353
|
+
// TO-DO Remove this
|
|
1354
|
+
setTotal(0);
|
|
1355
|
+
setNotifications([]);
|
|
1356
|
+
}
|
|
1357
|
+
}, []);
|
|
1358
|
+
const _fetch = async () => {
|
|
1359
|
+
if (notifications.length && total >= notifications.length || loading) {
|
|
1360
|
+
return;
|
|
1361
|
+
}
|
|
1362
|
+
setLoading(true);
|
|
1363
|
+
try {
|
|
1364
|
+
const _res = await NotificationService$1.get({
|
|
1365
|
+
status
|
|
1366
|
+
});
|
|
1367
|
+
if (_res.data) {
|
|
1368
|
+
setTotal(() => _res.data.total);
|
|
1369
|
+
setNotifications(p => [...p, ..._res.data.data]);
|
|
1370
|
+
setLoading(false);
|
|
1371
|
+
return;
|
|
1372
|
+
}
|
|
1373
|
+
setLoading(false);
|
|
1374
|
+
} catch {
|
|
1375
|
+
setLoading(false);
|
|
1376
|
+
setTotal(0);
|
|
1377
|
+
setNotifications([]);
|
|
1378
|
+
}
|
|
1379
|
+
};
|
|
1380
|
+
React.useEffect(() => {
|
|
1381
|
+
_fetch();
|
|
1382
|
+
}, []);
|
|
1383
|
+
const _notifications = notifications.sort((a, b) => b.createdAt - a.createdAt);
|
|
1384
|
+
return {
|
|
1385
|
+
total,
|
|
1386
|
+
loading,
|
|
1387
|
+
notifications,
|
|
1388
|
+
_notifications,
|
|
1389
|
+
_fetch,
|
|
1390
|
+
removeNotification,
|
|
1391
|
+
addNotification,
|
|
1392
|
+
clearAll
|
|
1393
|
+
};
|
|
1394
|
+
}
|
|
1395
|
+
|
|
1396
|
+
const status = 'all';
|
|
1397
|
+
const NotificationsHistoryContext = /*#__PURE__*/React.createContext({
|
|
1398
|
+
loading: false,
|
|
1399
|
+
_notifications: [],
|
|
1400
|
+
_fetch: [],
|
|
1401
|
+
total: 0
|
|
1402
|
+
});
|
|
1403
|
+
|
|
1404
|
+
// eslint-disable-next-line react/prop-types
|
|
1405
|
+
const NotificationsHistoryProvider = ({
|
|
1406
|
+
children
|
|
1407
|
+
}) => {
|
|
1408
|
+
const {
|
|
1409
|
+
loading,
|
|
1410
|
+
_notifications,
|
|
1411
|
+
_fetch,
|
|
1412
|
+
total
|
|
1413
|
+
} = useNotifications({
|
|
1414
|
+
status
|
|
1415
|
+
});
|
|
1416
|
+
const value = {
|
|
1417
|
+
loading,
|
|
1418
|
+
_notifications,
|
|
1419
|
+
_fetch,
|
|
1420
|
+
total
|
|
1421
|
+
};
|
|
1422
|
+
return /*#__PURE__*/jsxRuntime.jsx(NotificationsHistoryContext.Provider, {
|
|
1423
|
+
value: value,
|
|
1424
|
+
children: children
|
|
1425
|
+
});
|
|
1426
|
+
};
|
|
1427
|
+
const useNotificationsHistoryContext = () => {
|
|
1428
|
+
const value = React.useContext(NotificationsHistoryContext);
|
|
1429
|
+
return value;
|
|
1430
|
+
};
|
|
1431
|
+
|
|
1293
1432
|
exports.ApplicationsContext = ApplicationsContext;
|
|
1294
1433
|
exports.ApplicationsProvider = ApplicationsProvider;
|
|
1295
1434
|
exports.DasbhoardCacheProvider = DasbhoardCacheProvider;
|
|
@@ -1301,14 +1440,18 @@ exports.HistoryProvider = HistoryProvider;
|
|
|
1301
1440
|
exports.LinkingContext = LinkingContext;
|
|
1302
1441
|
exports.LinkingProvider = LinkingProvider;
|
|
1303
1442
|
exports.NOTIFICATION_MODE = NOTIFICATION_MODE;
|
|
1443
|
+
exports.NotificationsHistoryContext = NotificationsHistoryContext;
|
|
1444
|
+
exports.NotificationsHistoryProvider = NotificationsHistoryProvider;
|
|
1304
1445
|
exports.ProjectSourcesContext = ProjectSourcesContext;
|
|
1305
1446
|
exports.ProjectSourcesProvider = ProjectSourcesProvider;
|
|
1306
1447
|
exports.ResizeProvider = ResizeProvider;
|
|
1307
1448
|
exports.SelectContext = SelectContext;
|
|
1308
1449
|
exports.SelectProvider = SelectProvider;
|
|
1309
1450
|
exports.onBeforeUnload = onBeforeUnload;
|
|
1451
|
+
exports.useApplications = useApplications;
|
|
1310
1452
|
exports.useDasbhoardCache = useDasbhoardCache;
|
|
1311
1453
|
exports.useForms = useForms;
|
|
1312
1454
|
exports.useGeneralContext = useGeneralContext;
|
|
1313
1455
|
exports.useHistory = useHistory;
|
|
1456
|
+
exports.useNotificationsHistoryContext = useNotificationsHistoryContext;
|
|
1314
1457
|
exports.useResizeContext = useResizeContext;
|