bs-unified-ui 1.0.927 → 1.0.930
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/components/Notification/index.d.ts +1 -0
- package/index.js +90 -10
- package/package.json +1 -1
|
@@ -4,3 +4,4 @@ export * from './NotificationContext';
|
|
|
4
4
|
export * from './NotificationService';
|
|
5
5
|
export type { AuthConfig } from './AuthManager';
|
|
6
6
|
export type { UseNotificationsResult, UseNotificationsOptions, } from './useNotifications';
|
|
7
|
+
export type { UseNotificationsV2Result, UseNotificationsOptions as UseNotificationsV2Options, } from './useNotificationsV2';
|
package/index.js
CHANGED
|
@@ -45775,12 +45775,10 @@ var ObservableSet = /** @class */ (function () {
|
|
|
45775
45775
|
return ObservableSet;
|
|
45776
45776
|
}());
|
|
45777
45777
|
|
|
45778
|
-
// Constant empty array to avoid recreating on each render
|
|
45779
|
-
var EMPTY_WAREHOUSES_CONFIG = [];
|
|
45780
45778
|
var useNotificationsV2 = function (options) {
|
|
45781
45779
|
var _a, _b, _c, _d, _e, _f, _g, _h, _j;
|
|
45782
45780
|
if (options === void 0) { options = {}; }
|
|
45783
|
-
var onNotification = options.onNotification, onConnectionChange = options.onConnectionChange, onError = options.onError, _k = options.timezone, timezone = _k === void 0 ? 'America/Vancouver' : _k, navigate = options.navigate, bsOrgId = options.bsOrgId, cfWsId = options.cfWsId, soundConfig = options.soundConfig, triggerEvents = options.triggerEvents, _l = options.warehousesConfig, warehousesConfig = _l === void 0 ?
|
|
45781
|
+
var onNotification = options.onNotification, onConnectionChange = options.onConnectionChange, onError = options.onError, _k = options.timezone, timezone = _k === void 0 ? 'America/Vancouver' : _k, navigate = options.navigate, bsOrgId = options.bsOrgId, cfWsId = options.cfWsId, soundConfig = options.soundConfig, triggerEvents = options.triggerEvents, _l = options.warehousesConfig, warehousesConfig = _l === void 0 ? [] : _l;
|
|
45784
45782
|
var _m = React.useState([]), popoverNotifications = _m[0], setPopoverNotifications = _m[1];
|
|
45785
45783
|
var _o = React.useState(true), popoverLoading = _o[0], setPopoverLoading = _o[1];
|
|
45786
45784
|
var _p = React.useState(false), popoverHasNextPage = _p[0], setPopoverHasNextPage = _p[1];
|
|
@@ -45849,10 +45847,11 @@ var useNotificationsV2 = function (options) {
|
|
|
45849
45847
|
var playAudioForGroupRef = React.useRef(function () { });
|
|
45850
45848
|
var fetchIndicatorsInFlightRef = React.useRef(false);
|
|
45851
45849
|
var fetchAudioRepeatInFlightRef = React.useRef(false);
|
|
45850
|
+
var loadPopoverNotificationsInFlightRef = React.useRef(false);
|
|
45852
45851
|
var onErrorRef = React.useRef(onError);
|
|
45853
45852
|
var onNotificationRef = React.useRef(onNotification);
|
|
45854
45853
|
var onConnectionChangeRef = React.useRef(onConnectionChange);
|
|
45855
|
-
var warehousesConfigRef = React.useRef(
|
|
45854
|
+
var warehousesConfigRef = React.useRef([]);
|
|
45856
45855
|
// Track current pathname for display indicators
|
|
45857
45856
|
var currentPath = useCurrentPath();
|
|
45858
45857
|
// Check which page user is currently on
|
|
@@ -45935,7 +45934,14 @@ var useNotificationsV2 = function (options) {
|
|
|
45935
45934
|
memoizedTriggerEvents === null || memoizedTriggerEvents === void 0 ? void 0 : memoizedTriggerEvents[DELIVERY_EVENTS.NEW_DRIVER],
|
|
45936
45935
|
]);
|
|
45937
45936
|
// Memoize warehousesConfig to prevent recreating when array content is the same
|
|
45938
|
-
var memoizedWarehousesConfig = React.useMemo(function () {
|
|
45937
|
+
var memoizedWarehousesConfig = React.useMemo(function () {
|
|
45938
|
+
var prev = warehousesConfigRef.current;
|
|
45939
|
+
if (prev.length === warehousesConfig.length &&
|
|
45940
|
+
prev.every(function (val, idx) { return val === warehousesConfig[idx]; })) {
|
|
45941
|
+
return prev;
|
|
45942
|
+
}
|
|
45943
|
+
return warehousesConfig;
|
|
45944
|
+
}, [warehousesConfig]);
|
|
45939
45945
|
var markAsRead = React.useCallback(function (notificationId) { return __awaiter(void 0, void 0, void 0, function () {
|
|
45940
45946
|
var err_1, errorMessage;
|
|
45941
45947
|
var _a;
|
|
@@ -46083,9 +46089,14 @@ var useNotificationsV2 = function (options) {
|
|
|
46083
46089
|
case 0:
|
|
46084
46090
|
if (!serviceRef.current)
|
|
46085
46091
|
return [2 /*return*/];
|
|
46092
|
+
// Guard: Skip if already loading to prevent duplicate calls
|
|
46093
|
+
if (loadPopoverNotificationsInFlightRef.current) {
|
|
46094
|
+
return [2 /*return*/];
|
|
46095
|
+
}
|
|
46086
46096
|
_b.label = 1;
|
|
46087
46097
|
case 1:
|
|
46088
46098
|
_b.trys.push([1, 3, 4, 5]);
|
|
46099
|
+
loadPopoverNotificationsInFlightRef.current = true;
|
|
46089
46100
|
return [4 /*yield*/, serviceRef.current.loadNotifications(params)];
|
|
46090
46101
|
case 2:
|
|
46091
46102
|
data_1 = _b.sent();
|
|
@@ -46110,6 +46121,7 @@ var useNotificationsV2 = function (options) {
|
|
|
46110
46121
|
case 4:
|
|
46111
46122
|
if (!(params === null || params === void 0 ? void 0 : params.lastNotificationId))
|
|
46112
46123
|
setPopoverLoading(false);
|
|
46124
|
+
loadPopoverNotificationsInFlightRef.current = false;
|
|
46113
46125
|
return [7 /*endfinally*/];
|
|
46114
46126
|
case 5: return [2 /*return*/];
|
|
46115
46127
|
}
|
|
@@ -46248,6 +46260,8 @@ var useNotificationsV2 = function (options) {
|
|
|
46248
46260
|
});
|
|
46249
46261
|
}
|
|
46250
46262
|
});
|
|
46263
|
+
// Stop audio repeat for old online store event reminders
|
|
46264
|
+
stopAudioRepeatForGroupIfNoReminders('online_store');
|
|
46251
46265
|
reminderGroups = getReminderGroups(allRemindersRef.current);
|
|
46252
46266
|
reminderGroups.forEach(function (group) {
|
|
46253
46267
|
playAudioForGroup(group);
|
|
@@ -46266,7 +46280,6 @@ var useNotificationsV2 = function (options) {
|
|
|
46266
46280
|
});
|
|
46267
46281
|
}); }, [
|
|
46268
46282
|
bsOrgId,
|
|
46269
|
-
memoizedWarehousesConfig,
|
|
46270
46283
|
memoizedTriggerEvents,
|
|
46271
46284
|
playAudioForGroup,
|
|
46272
46285
|
startAudioRepeatForGroup,
|
|
@@ -46905,7 +46918,12 @@ var useNotificationsV2 = function (options) {
|
|
|
46905
46918
|
fetchAudioRepeatTimerRef.current = null;
|
|
46906
46919
|
}, 3000);
|
|
46907
46920
|
}
|
|
46908
|
-
}, [
|
|
46921
|
+
}, [
|
|
46922
|
+
fetchAudioRepeat,
|
|
46923
|
+
memoizedSoundConfig,
|
|
46924
|
+
memoizedReminderEvents,
|
|
46925
|
+
memoizedWarehousesConfig,
|
|
46926
|
+
]);
|
|
46909
46927
|
// Restart interval when repeatingInterval or mute changes per group
|
|
46910
46928
|
React.useEffect(function () {
|
|
46911
46929
|
if (!memoizedSoundConfig)
|
|
@@ -47211,6 +47229,66 @@ var NotificationToast = React.forwardRef(function (props, ref) {
|
|
|
47211
47229
|
});
|
|
47212
47230
|
|
|
47213
47231
|
var NotificationContext = React.createContext(null);
|
|
47232
|
+
/**
|
|
47233
|
+
* Creates a default notification context with safe default values
|
|
47234
|
+
* Used when Provider is not mounted or not yet initialized
|
|
47235
|
+
*/
|
|
47236
|
+
function createDefaultNotificationContext() {
|
|
47237
|
+
var _this = this;
|
|
47238
|
+
return {
|
|
47239
|
+
popoverLoading: false,
|
|
47240
|
+
popoverHasNextPage: false,
|
|
47241
|
+
isUnreadPopover: false,
|
|
47242
|
+
popoverNotifications: [],
|
|
47243
|
+
timezone: 'America/Vancouver',
|
|
47244
|
+
filter: undefined,
|
|
47245
|
+
notifications: [],
|
|
47246
|
+
notificationLoading: false,
|
|
47247
|
+
unreadCount: 0,
|
|
47248
|
+
isConnected: false,
|
|
47249
|
+
loading: false,
|
|
47250
|
+
error: null,
|
|
47251
|
+
isInitialized: false,
|
|
47252
|
+
hasNextPage: false,
|
|
47253
|
+
indicators: {
|
|
47254
|
+
order: false,
|
|
47255
|
+
chat: false,
|
|
47256
|
+
task_update: false,
|
|
47257
|
+
new_driver: false,
|
|
47258
|
+
},
|
|
47259
|
+
allReminders: new ObservableSet(),
|
|
47260
|
+
setIsUnreadPopover: function () { },
|
|
47261
|
+
connect: function () { return __awaiter(_this, void 0, void 0, function () { return __generator(this, function (_a) {
|
|
47262
|
+
return [2 /*return*/];
|
|
47263
|
+
}); }); },
|
|
47264
|
+
disconnect: function () { },
|
|
47265
|
+
loadNotifications: function () { return __awaiter(_this, void 0, void 0, function () { return __generator(this, function (_a) {
|
|
47266
|
+
return [2 /*return*/];
|
|
47267
|
+
}); }); },
|
|
47268
|
+
loadMorePopoverNotifications: function () { return __awaiter(_this, void 0, void 0, function () { return __generator(this, function (_a) {
|
|
47269
|
+
return [2 /*return*/];
|
|
47270
|
+
}); }); },
|
|
47271
|
+
markAsRead: function () { return __awaiter(_this, void 0, void 0, function () { return __generator(this, function (_a) {
|
|
47272
|
+
return [2 /*return*/];
|
|
47273
|
+
}); }); },
|
|
47274
|
+
markAllAsRead: function () { return __awaiter(_this, void 0, void 0, function () { return __generator(this, function (_a) {
|
|
47275
|
+
return [2 /*return*/];
|
|
47276
|
+
}); }); },
|
|
47277
|
+
retry: function () { return __awaiter(_this, void 0, void 0, function () { return __generator(this, function (_a) {
|
|
47278
|
+
return [2 /*return*/];
|
|
47279
|
+
}); }); },
|
|
47280
|
+
refreshAuth: function () { return __awaiter(_this, void 0, void 0, function () { return __generator(this, function (_a) {
|
|
47281
|
+
return [2 /*return*/];
|
|
47282
|
+
}); }); },
|
|
47283
|
+
handleClickNotification: function () { },
|
|
47284
|
+
handleApplyFilter: function () { },
|
|
47285
|
+
redirectToNotificationPage: function () { },
|
|
47286
|
+
setIsActiveNotificationPage: function () { },
|
|
47287
|
+
updateIndicators: function () { return __awaiter(_this, void 0, void 0, function () { return __generator(this, function (_a) {
|
|
47288
|
+
return [2 /*return*/];
|
|
47289
|
+
}); }); },
|
|
47290
|
+
};
|
|
47291
|
+
}
|
|
47214
47292
|
var NotificationProviderBase = function (_a) {
|
|
47215
47293
|
var children = _a.children, config = _a.config, useNotificationsHook = _a.useNotificationsHook;
|
|
47216
47294
|
// Use refs to store callbacks to avoid recreating them
|
|
@@ -47294,13 +47372,15 @@ var NotificationProvider = function (_a) {
|
|
|
47294
47372
|
}, [config]);
|
|
47295
47373
|
// Memoize the hook selection
|
|
47296
47374
|
var useNotificationsHook = React.useMemo(function () { return (isV2 ? useNotificationsV2 : useNotifications); }, [isV2]);
|
|
47297
|
-
return (React.createElement(NotificationProviderBase, { config: restConfig, useNotificationsHook: useNotificationsHook }, children));
|
|
47375
|
+
return (React.createElement(NotificationProviderBase, { key: isV2 ? 'v2' : 'v1', config: restConfig, useNotificationsHook: useNotificationsHook }, children));
|
|
47298
47376
|
};
|
|
47299
47377
|
var useNotificationContext = function () {
|
|
47300
47378
|
var context = React.useContext(NotificationContext);
|
|
47301
47379
|
if (!context) {
|
|
47302
|
-
|
|
47303
|
-
|
|
47380
|
+
// eslint-disable-next-line no-console
|
|
47381
|
+
console.warn('useNotificationContext: No NotificationProvider found. ' +
|
|
47382
|
+
'Returning default values. Wrap your app with <NotificationProvider> at the root level.');
|
|
47383
|
+
return createDefaultNotificationContext();
|
|
47304
47384
|
}
|
|
47305
47385
|
return context;
|
|
47306
47386
|
};
|