bs-unified-ui 1.0.915 → 1.0.920

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.
@@ -83,7 +83,7 @@ declare class NotificationService {
83
83
  }>;
84
84
  markAsRead(notificationId: string): Promise<void>;
85
85
  markAllAsRead(bsOrgId?: string): Promise<void>;
86
- getAudioRepeat(bsOrgId: string): Promise<any>;
86
+ getAudioRepeat(bsOrgId: string, warehousesConfig?: string[]): Promise<any>;
87
87
  getIndicators(bsOrgId: string, categories?: Record<string, string[]>): Promise<any>;
88
88
  updateIndicators(indicators: Partial<{
89
89
  order: boolean;
@@ -1,5 +1,6 @@
1
1
  /**
2
2
  * Custom hook to track current pathname changes in SPA
3
+ * Uses singleton PathTracker to prevent duplicate history API patches
3
4
  * Listens to:
4
5
  * - popstate (browser back/forward)
5
6
  * - history.pushState (programmatic navigation)
@@ -79,6 +79,7 @@ export interface UseNotificationsOptions extends NotificationConfig {
79
79
  navigate?: any;
80
80
  soundConfig?: SoundConfig;
81
81
  triggerEvents?: TriggerEvents;
82
+ warehousesConfig?: string[];
82
83
  }
83
84
  declare const useNotifications: (options?: UseNotificationsOptions) => UseNotificationsResult;
84
85
  export default useNotifications;
@@ -53,6 +53,7 @@ export interface UseNotificationsOptions extends NotificationConfig {
53
53
  navigate?: any;
54
54
  soundConfig?: SoundConfig;
55
55
  triggerEvents?: TriggerEvents;
56
+ warehousesConfig?: string[];
56
57
  }
57
58
  declare const useNotificationsV2: (options?: UseNotificationsOptions) => UseNotificationsV2Result;
58
59
  export default useNotificationsV2;
package/index.js CHANGED
@@ -41890,7 +41890,7 @@ var NotificationService = /** @class */ (function () {
41890
41890
  });
41891
41891
  });
41892
41892
  };
41893
- NotificationService.prototype.getAudioRepeat = function (bsOrgId) {
41893
+ NotificationService.prototype.getAudioRepeat = function (bsOrgId, warehousesConfig) {
41894
41894
  return __awaiter(this, void 0, void 0, function () {
41895
41895
  var headers, sessionToken, queryParams, url, response, res, error_8;
41896
41896
  return __generator(this, function (_a) {
@@ -41916,6 +41916,9 @@ var NotificationService = /** @class */ (function () {
41916
41916
  case 3:
41917
41917
  queryParams = new URLSearchParams();
41918
41918
  queryParams.append('bsOrgId', bsOrgId);
41919
+ if (warehousesConfig && warehousesConfig.length > 0) {
41920
+ queryParams.append('warehouses', warehousesConfig.join(','));
41921
+ }
41919
41922
  url = "".concat(this.config.apiBaseUrl, "/notifications/me/get-audio-repeat?").concat(queryParams.toString());
41920
41923
  return [4 /*yield*/, fetch(url, { headers: headers })];
41921
41924
  case 4:
@@ -45585,22 +45588,37 @@ var filterIndicatorsByEnabledEvents = function (receivedIndicators, triggerEvent
45585
45588
  };
45586
45589
 
45587
45590
  /**
45588
- * Custom hook to track current pathname changes in SPA
45589
- * Listens to:
45590
- * - popstate (browser back/forward)
45591
- * - history.pushState (programmatic navigation)
45592
- * - history.replaceState (programmatic navigation)
45591
+ * Global singleton to track pathname changes across all hook instances
45592
+ * This prevents multiple hooks from patching history APIs multiple times
45593
45593
  */
45594
- var useCurrentPath = function () {
45595
- var _a = React.useState(typeof window !== 'undefined' ? window.location.pathname : ''), currentPath = _a[0], setCurrentPath = _a[1];
45596
- React.useEffect(function () {
45597
- var handleLocationChange = function () {
45598
- setCurrentPath(window.location.pathname);
45594
+ var PathTracker = /** @class */ (function () {
45595
+ function PathTracker() {
45596
+ this.listeners = new Set();
45597
+ this.currentPath = '';
45598
+ this.isPatched = false;
45599
+ if (typeof window !== 'undefined') {
45600
+ this.currentPath = window.location.pathname;
45601
+ this.patchHistory();
45602
+ }
45603
+ }
45604
+ PathTracker.getInstance = function () {
45605
+ if (!PathTracker.instance) {
45606
+ PathTracker.instance = new PathTracker();
45607
+ }
45608
+ return PathTracker.instance;
45609
+ };
45610
+ PathTracker.prototype.patchHistory = function () {
45611
+ var _this = this;
45612
+ if (this.isPatched)
45613
+ return;
45614
+ this.isPatched = true;
45615
+ var handleChange = function () {
45616
+ _this.currentPath = window.location.pathname;
45617
+ _this.notifyListeners();
45599
45618
  };
45600
45619
  // Listen to popstate event (browser back/forward)
45601
- window.addEventListener('popstate', handleLocationChange);
45602
- // For SPAs, also listen to custom navigation events if needed
45603
- // This covers most routing libraries that update window.location
45620
+ window.addEventListener('popstate', handleChange);
45621
+ // Patch history.pushState and history.replaceState ONCE
45604
45622
  var originalPushState = window.history.pushState;
45605
45623
  var originalReplaceState = window.history.replaceState;
45606
45624
  window.history.pushState = function pushStateWrapper() {
@@ -45609,7 +45627,7 @@ var useCurrentPath = function () {
45609
45627
  args[_i] = arguments[_i];
45610
45628
  }
45611
45629
  originalPushState.apply(this, args);
45612
- handleLocationChange();
45630
+ handleChange();
45613
45631
  };
45614
45632
  window.history.replaceState = function replaceStateWrapper() {
45615
45633
  var args = [];
@@ -45617,14 +45635,45 @@ var useCurrentPath = function () {
45617
45635
  args[_i] = arguments[_i];
45618
45636
  }
45619
45637
  originalReplaceState.apply(this, args);
45620
- handleLocationChange();
45638
+ handleChange();
45621
45639
  };
45640
+ };
45641
+ PathTracker.prototype.subscribe = function (callback) {
45642
+ var _this = this;
45643
+ this.listeners.add(callback);
45622
45644
  return function () {
45623
- window.removeEventListener('popstate', handleLocationChange);
45624
- window.history.pushState = originalPushState;
45625
- window.history.replaceState = originalReplaceState;
45645
+ _this.listeners.delete(callback);
45626
45646
  };
45627
- }, []);
45647
+ };
45648
+ PathTracker.prototype.notifyListeners = function () {
45649
+ var _this = this;
45650
+ this.listeners.forEach(function (callback) {
45651
+ try {
45652
+ callback(_this.currentPath);
45653
+ }
45654
+ catch (e) {
45655
+ // Ignore errors in listeners
45656
+ }
45657
+ });
45658
+ };
45659
+ PathTracker.prototype.getCurrentPath = function () {
45660
+ return this.currentPath;
45661
+ };
45662
+ PathTracker.instance = null;
45663
+ return PathTracker;
45664
+ }());
45665
+ /**
45666
+ * Custom hook to track current pathname changes in SPA
45667
+ * Uses singleton PathTracker to prevent duplicate history API patches
45668
+ * Listens to:
45669
+ * - popstate (browser back/forward)
45670
+ * - history.pushState (programmatic navigation)
45671
+ * - history.replaceState (programmatic navigation)
45672
+ */
45673
+ var useCurrentPath = function () {
45674
+ var tracker = PathTracker.getInstance();
45675
+ var _a = React.useState(tracker.getCurrentPath()), currentPath = _a[0], setCurrentPath = _a[1];
45676
+ React.useEffect(function () { return tracker.subscribe(setCurrentPath); }, [tracker]);
45628
45677
  return currentPath;
45629
45678
  };
45630
45679
 
@@ -45721,19 +45770,21 @@ var ObservableSet = /** @class */ (function () {
45721
45770
  return ObservableSet;
45722
45771
  }());
45723
45772
 
45773
+ // Constant empty array to avoid recreating on each render
45774
+ var EMPTY_WAREHOUSES_CONFIG = [];
45724
45775
  var useNotificationsV2 = function (options) {
45725
45776
  var _a, _b, _c, _d, _e, _f, _g, _h, _j;
45726
45777
  if (options === void 0) { options = {}; }
45727
- 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;
45728
- var _l = React.useState([]), popoverNotifications = _l[0], setPopoverNotifications = _l[1];
45729
- var _m = React.useState(true), popoverLoading = _m[0], setPopoverLoading = _m[1];
45730
- var _o = React.useState(false), popoverHasNextPage = _o[0], setPopoverHasNextPage = _o[1];
45731
- var _p = React.useState(false), isUnreadPopover = _p[0], setIsUnreadPopover = _p[1];
45732
- var _q = React.useState(0), unreadCount = _q[0], setUnreadCount = _q[1];
45733
- var _r = React.useState(false), isActiveNotificationPage = _r[0], setIsActiveNotificationPage = _r[1];
45734
- var _s = React.useState([]), notifications = _s[0], setNotifications = _s[1];
45735
- var _t = React.useState(true), notificationLoading = _t[0], setNotificationLoading = _t[1];
45736
- var _u = React.useState({
45778
+ 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 ? EMPTY_WAREHOUSES_CONFIG : _l;
45779
+ var _m = React.useState([]), popoverNotifications = _m[0], setPopoverNotifications = _m[1];
45780
+ var _o = React.useState(true), popoverLoading = _o[0], setPopoverLoading = _o[1];
45781
+ var _p = React.useState(false), popoverHasNextPage = _p[0], setPopoverHasNextPage = _p[1];
45782
+ var _q = React.useState(false), isUnreadPopover = _q[0], setIsUnreadPopover = _q[1];
45783
+ var _r = React.useState(0), unreadCount = _r[0], setUnreadCount = _r[1];
45784
+ var _s = React.useState(false), isActiveNotificationPage = _s[0], setIsActiveNotificationPage = _s[1];
45785
+ var _t = React.useState([]), notifications = _t[0], setNotifications = _t[1];
45786
+ var _u = React.useState(true), notificationLoading = _u[0], setNotificationLoading = _u[1];
45787
+ var _v = React.useState({
45737
45788
  search: '',
45738
45789
  sortBy: '',
45739
45790
  sortOrder: '',
@@ -45743,19 +45794,19 @@ var useNotificationsV2 = function (options) {
45743
45794
  limit: 20,
45744
45795
  startDate: '',
45745
45796
  endDate: '',
45746
- }), filter = _u[0], setFilter = _u[1];
45797
+ }), filter = _v[0], setFilter = _v[1];
45747
45798
  var filterRef = React.useRef(filter);
45748
- var _v = React.useState(true), hasNextPage = _v[0], setHasNextPage = _v[1];
45749
- var _w = React.useState(true), loading = _w[0], setLoading = _w[1];
45750
- var _x = React.useState(false), isConnected = _x[0], setIsConnected = _x[1];
45751
- var _y = React.useState(null), error = _y[0], setError = _y[1];
45752
- var _z = React.useState(false), isInitialized = _z[0], setIsInitialized = _z[1];
45753
- var _0 = React.useState({
45799
+ var _w = React.useState(true), hasNextPage = _w[0], setHasNextPage = _w[1];
45800
+ var _x = React.useState(true), loading = _x[0], setLoading = _x[1];
45801
+ var _y = React.useState(false), isConnected = _y[0], setIsConnected = _y[1];
45802
+ var _z = React.useState(null), error = _z[0], setError = _z[1];
45803
+ var _0 = React.useState(false), isInitialized = _0[0], setIsInitialized = _0[1];
45804
+ var _1 = React.useState({
45754
45805
  order: false,
45755
45806
  chat: false,
45756
45807
  task_update: false,
45757
45808
  new_driver: false,
45758
- }), indicators = _0[0], setIndicators = _0[1];
45809
+ }), indicators = _1[0], setIndicators = _1[1];
45759
45810
  var serviceRef = React.useRef(null);
45760
45811
  var unsubscribeRef = React.useRef(null);
45761
45812
  var initPromiseRef = React.useRef(null);
@@ -45767,8 +45818,6 @@ var useNotificationsV2 = function (options) {
45767
45818
  // Single ObservableSet to track all items requiring audio reminders with composite key: `${subType}:${id}`
45768
45819
  var allRemindersRef = React.useRef(new ObservableSet());
45769
45820
  var handleNotificationEventRef = React.useRef(function () { });
45770
- // Refs to always have latest functions (prevents duplicate intervals)
45771
- var playAudioForGroupRef = React.useRef(function () { });
45772
45821
  // Ref to always have latest indicators state
45773
45822
  var indicatorsRef = React.useRef(indicators);
45774
45823
  // Track previous reminder events to detect when events are enabled (falsy -> true)
@@ -45789,9 +45838,12 @@ var useNotificationsV2 = function (options) {
45789
45838
  var prevPageIndicatorRef = React.useRef();
45790
45839
  // Timer for debouncing fetchAudioRepeat calls
45791
45840
  var fetchAudioRepeatTimerRef = React.useRef(null);
45792
- // Ref to always have latest updateIndicators function
45793
- var updateIndicatorsRef = React.useRef();
45794
45841
  // Use refs to store latest callbacks to avoid recreating functions unnecessarily
45842
+ var updateIndicatorsRef = React.useRef();
45843
+ var fetchIndicatorsRef = React.useRef();
45844
+ var playAudioForGroupRef = React.useRef(function () { });
45845
+ var fetchIndicatorsInFlightRef = React.useRef(false);
45846
+ var fetchAudioRepeatInFlightRef = React.useRef(false);
45795
45847
  var onErrorRef = React.useRef(onError);
45796
45848
  var onNotificationRef = React.useRef(onNotification);
45797
45849
  var onConnectionChangeRef = React.useRef(onConnectionChange);
@@ -45876,6 +45928,8 @@ var useNotificationsV2 = function (options) {
45876
45928
  memoizedTriggerEvents === null || memoizedTriggerEvents === void 0 ? void 0 : memoizedTriggerEvents[DELIVERY_EVENTS.IMPORT_TASK],
45877
45929
  memoizedTriggerEvents === null || memoizedTriggerEvents === void 0 ? void 0 : memoizedTriggerEvents[DELIVERY_EVENTS.NEW_DRIVER],
45878
45930
  ]);
45931
+ // Memoize warehousesConfig to prevent recreating when array content is the same
45932
+ var memoizedWarehousesConfig = React.useMemo(function () { return warehousesConfig; }, [JSON.stringify(warehousesConfig)]);
45879
45933
  var markAsRead = React.useCallback(function (notificationId) { return __awaiter(void 0, void 0, void 0, function () {
45880
45934
  var err_1, errorMessage;
45881
45935
  var _a;
@@ -46015,16 +46069,6 @@ var useNotificationsV2 = function (options) {
46015
46069
  }
46016
46070
  return true;
46017
46071
  }, []);
46018
- // Update refs whenever callbacks change
46019
- React.useEffect(function () {
46020
- onErrorRef.current = onError;
46021
- }, [onError]);
46022
- React.useEffect(function () {
46023
- onNotificationRef.current = onNotification;
46024
- }, [onNotification]);
46025
- React.useEffect(function () {
46026
- onConnectionChangeRef.current = onConnectionChange;
46027
- }, [onConnectionChange]);
46028
46072
  var loadPopoverNotifications = React.useCallback(function (params) { return __awaiter(void 0, void 0, void 0, function () {
46029
46073
  var data_1, err_3, errorMessage;
46030
46074
  var _a;
@@ -46074,6 +46118,7 @@ var useNotificationsV2 = function (options) {
46074
46118
  var startRetryInterval = React.useCallback(function () {
46075
46119
  if (!bsOrgId)
46076
46120
  return;
46121
+ // Clear any existing interval to prevent duplicates
46077
46122
  clearRetryInterval();
46078
46123
  retryIntervalRef.current = setInterval(function () {
46079
46124
  var createdAtGte = isoMinusDaysInTimeZone(timezone, 7);
@@ -46109,14 +46154,6 @@ var useNotificationsV2 = function (options) {
46109
46154
  audioElement.play().catch(function () { });
46110
46155
  }
46111
46156
  }, [memoizedSoundConfig]);
46112
- // Update ref whenever playAudioForGroup changes
46113
- React.useEffect(function () {
46114
- playAudioForGroupRef.current = playAudioForGroup;
46115
- }, [playAudioForGroup]);
46116
- // Update ref whenever indicators changes
46117
- React.useEffect(function () {
46118
- indicatorsRef.current = indicators;
46119
- }, [indicators]);
46120
46157
  // Start audio repeat for specific group
46121
46158
  var startAudioRepeatForGroup = React.useCallback(function (group) {
46122
46159
  var _a;
@@ -46170,12 +46207,17 @@ var useNotificationsV2 = function (options) {
46170
46207
  case 0:
46171
46208
  if (!serviceRef.current || !bsOrgId)
46172
46209
  return [2 /*return*/];
46210
+ // Guard: Skip if already fetching to prevent duplicate calls
46211
+ if (fetchAudioRepeatInFlightRef.current) {
46212
+ return [2 /*return*/];
46213
+ }
46173
46214
  // Clear old reminders first to avoid stale data
46174
46215
  allRemindersRef.current.clear();
46175
46216
  _a.label = 1;
46176
46217
  case 1:
46177
- _a.trys.push([1, 3, , 4]);
46178
- return [4 /*yield*/, serviceRef.current.getAudioRepeat(bsOrgId)];
46218
+ _a.trys.push([1, 3, 4, 5]);
46219
+ fetchAudioRepeatInFlightRef.current = true;
46220
+ return [4 /*yield*/, serviceRef.current.getAudioRepeat(bsOrgId, memoizedWarehousesConfig)];
46179
46221
  case 2:
46180
46222
  response = _a.sent();
46181
46223
  data = response === null || response === void 0 ? void 0 : response.data;
@@ -46206,15 +46248,19 @@ var useNotificationsV2 = function (options) {
46206
46248
  startAudioRepeatForGroup(group);
46207
46249
  });
46208
46250
  }
46209
- return [3 /*break*/, 4];
46251
+ return [3 /*break*/, 5];
46210
46252
  case 3:
46211
46253
  _a.sent();
46212
- return [3 /*break*/, 4];
46213
- case 4: return [2 /*return*/];
46254
+ return [3 /*break*/, 5];
46255
+ case 4:
46256
+ fetchAudioRepeatInFlightRef.current = false;
46257
+ return [7 /*endfinally*/];
46258
+ case 5: return [2 /*return*/];
46214
46259
  }
46215
46260
  });
46216
46261
  }); }, [
46217
46262
  bsOrgId,
46263
+ memoizedWarehousesConfig,
46218
46264
  memoizedTriggerEvents,
46219
46265
  playAudioForGroup,
46220
46266
  startAudioRepeatForGroup,
@@ -46227,6 +46273,10 @@ var useNotificationsV2 = function (options) {
46227
46273
  case 0:
46228
46274
  if (!serviceRef.current || !bsOrgId)
46229
46275
  return [2 /*return*/];
46276
+ // Guard: Skip if already fetching to prevent duplicate calls
46277
+ if (fetchIndicatorsInFlightRef.current) {
46278
+ return [2 /*return*/];
46279
+ }
46230
46280
  categories = {};
46231
46281
  Object.entries(INDICATOR_MAPPING).forEach(function (_a) {
46232
46282
  var category = _a[0], events = _a[1];
@@ -46239,14 +46289,22 @@ var useNotificationsV2 = function (options) {
46239
46289
  if (Object.keys(categories).length === 0) {
46240
46290
  return [2 /*return*/];
46241
46291
  }
46242
- return [4 /*yield*/, serviceRef.current.getIndicators(bsOrgId, categories)];
46292
+ _a.label = 1;
46243
46293
  case 1:
46294
+ _a.trys.push([1, , 3, 4]);
46295
+ fetchIndicatorsInFlightRef.current = true;
46296
+ return [4 /*yield*/, serviceRef.current.getIndicators(bsOrgId, categories)];
46297
+ case 2:
46244
46298
  response = _a.sent();
46245
46299
  receivedIndicators = response === null || response === void 0 ? void 0 : response.data;
46246
46300
  if (receivedIndicators) {
46247
46301
  setIndicators(receivedIndicators);
46248
46302
  }
46249
- return [2 /*return*/];
46303
+ return [3 /*break*/, 4];
46304
+ case 3:
46305
+ fetchIndicatorsInFlightRef.current = false;
46306
+ return [7 /*endfinally*/];
46307
+ case 4: return [2 /*return*/];
46250
46308
  }
46251
46309
  });
46252
46310
  }); }, [bsOrgId, memoizedTriggerEvents]);
@@ -46285,10 +46343,29 @@ var useNotificationsV2 = function (options) {
46285
46343
  }
46286
46344
  });
46287
46345
  }); }, [bsOrgId, onError, memoizedTriggerEvents]);
46288
- // Update ref whenever updateIndicators changes
46346
+ // Update function refs to avoid stale closures
46347
+ React.useEffect(function () {
46348
+ onErrorRef.current = onError;
46349
+ }, [onError]);
46350
+ React.useEffect(function () {
46351
+ onNotificationRef.current = onNotification;
46352
+ }, [onNotification]);
46353
+ React.useEffect(function () {
46354
+ onConnectionChangeRef.current = onConnectionChange;
46355
+ }, [onConnectionChange]);
46289
46356
  React.useEffect(function () {
46290
46357
  updateIndicatorsRef.current = updateIndicators;
46291
46358
  }, [updateIndicators]);
46359
+ React.useEffect(function () {
46360
+ fetchIndicatorsRef.current = fetchIndicators;
46361
+ }, [fetchIndicators]);
46362
+ React.useEffect(function () {
46363
+ playAudioForGroupRef.current = playAudioForGroup;
46364
+ }, [playAudioForGroup]);
46365
+ // Update state ref
46366
+ React.useEffect(function () {
46367
+ indicatorsRef.current = indicators;
46368
+ }, [indicators]);
46292
46369
  // Queue indicator update to batch multiple updates together
46293
46370
  var queueUpdateIndicators = React.useCallback(function (indicator, value) {
46294
46371
  // Add to pending queue
@@ -46680,10 +46757,11 @@ var useNotificationsV2 = function (options) {
46680
46757
  if (!isInitialized || !bsOrgId)
46681
46758
  return undefined;
46682
46759
  var timeoutId = setTimeout(function () {
46683
- fetchIndicators();
46684
- }, 2000);
46760
+ var _a;
46761
+ (_a = fetchIndicatorsRef.current) === null || _a === void 0 ? void 0 : _a.call(fetchIndicatorsRef);
46762
+ }, 3000);
46685
46763
  return function () { return clearTimeout(timeoutId); };
46686
- }, [isInitialized, bsOrgId, fetchIndicators]);
46764
+ }, [isInitialized, bsOrgId]);
46687
46765
  React.useEffect(function () {
46688
46766
  if (isInitialized && isActiveNotificationPage && bsOrgId) {
46689
46767
  var apiParams = __assign({}, filter);
@@ -46814,7 +46892,7 @@ var useNotificationsV2 = function (options) {
46814
46892
  fetchAudioRepeatTimerRef.current = setTimeout(function () {
46815
46893
  fetchAudioRepeat();
46816
46894
  fetchAudioRepeatTimerRef.current = null;
46817
- }, 2000);
46895
+ }, 3000);
46818
46896
  }
46819
46897
  }, [fetchAudioRepeat, memoizedSoundConfig, memoizedReminderEvents]);
46820
46898
  // Restart interval when repeatingInterval or mute changes per group
@@ -47124,29 +47202,63 @@ var NotificationToast = React.forwardRef(function (props, ref) {
47124
47202
  var NotificationContext = React.createContext(null);
47125
47203
  var NotificationProviderBase = function (_a) {
47126
47204
  var children = _a.children, config = _a.config, useNotificationsHook = _a.useNotificationsHook;
47127
- // Memoize callbacks to prevent recreating on every render
47205
+ // Use refs to store callbacks to avoid recreating them
47206
+ var onNotificationRef = React.useRef(config.onNotification);
47207
+ var onConnectionChangeRef = React.useRef(config.onConnectionChange);
47208
+ var onErrorRef = React.useRef(config.onError);
47209
+ // Update refs when callbacks change
47210
+ onNotificationRef.current = config.onNotification;
47211
+ onConnectionChangeRef.current = config.onConnectionChange;
47212
+ onErrorRef.current = config.onError;
47213
+ // Create stable callbacks that use refs
47128
47214
  var onNotificationCb = React.useCallback(function (notification) {
47129
47215
  var _a;
47130
- (_a = config.onNotification) === null || _a === void 0 ? void 0 : _a.call(config, notification);
47131
- }, [config.onNotification]);
47216
+ (_a = onNotificationRef.current) === null || _a === void 0 ? void 0 : _a.call(onNotificationRef, notification);
47217
+ }, []);
47132
47218
  var onConnectionChangeCb = React.useCallback(function (isConnected) {
47133
47219
  var _a;
47134
- (_a = config.onConnectionChange) === null || _a === void 0 ? void 0 : _a.call(config, isConnected);
47135
- }, [config.onConnectionChange]);
47220
+ (_a = onConnectionChangeRef.current) === null || _a === void 0 ? void 0 : _a.call(onConnectionChangeRef, isConnected);
47221
+ }, []);
47136
47222
  var onErrorCb = React.useCallback(function (error) {
47137
47223
  var _a;
47138
- (_a = config.onError) === null || _a === void 0 ? void 0 : _a.call(config, error);
47139
- }, [config.onError]);
47140
- var notificationState = useNotificationsHook(__assign(__assign({}, config), { onNotification: onNotificationCb, onConnectionChange: onConnectionChangeCb, onError: onErrorCb }));
47141
- return (React.createElement(SnackbarProvider, { maxSnack: (config === null || config === void 0 ? void 0 : config.maxVisibleToasts) || 5, autoHideDuration: (config === null || config === void 0 ? void 0 : config.autoRemoveDelay) || 5000, anchorOrigin: {
47224
+ (_a = onErrorRef.current) === null || _a === void 0 ? void 0 : _a.call(onErrorRef, error);
47225
+ }, []);
47226
+ // Memoize the config object to prevent recreating it
47227
+ var memoizedConfig = React.useMemo(function () { return (__assign(__assign({}, config), { onNotification: onNotificationCb, onConnectionChange: onConnectionChangeCb, onError: onErrorCb })); }, [
47228
+ config.bsOrgId,
47229
+ config.cfWsId,
47230
+ config.timezone,
47231
+ config.navigate,
47232
+ config.soundConfig,
47233
+ config.triggerEvents,
47234
+ config.warehousesConfig,
47235
+ config.maxVisibleToasts,
47236
+ config.autoRemoveDelay,
47237
+ onNotificationCb,
47238
+ onConnectionChangeCb,
47239
+ onErrorCb,
47240
+ ]);
47241
+ var notificationState = useNotificationsHook(memoizedConfig);
47242
+ // Memoize SnackbarProvider props to prevent re-renders
47243
+ var snackbarProps = React.useMemo(function () { return ({
47244
+ maxSnack: (config === null || config === void 0 ? void 0 : config.maxVisibleToasts) || 5,
47245
+ autoHideDuration: (config === null || config === void 0 ? void 0 : config.autoRemoveDelay) || 5000,
47246
+ anchorOrigin: {
47142
47247
  vertical: 'top',
47143
47248
  horizontal: 'right',
47144
- }, dense: true, preventDuplicate: true, disableWindowBlurListener: true, classes: {
47249
+ },
47250
+ dense: true,
47251
+ preventDuplicate: true,
47252
+ disableWindowBlurListener: true,
47253
+ classes: {
47145
47254
  containerRoot: 'snackbarStack',
47146
47255
  containerAnchorOriginTopRight: 'snackbarStack',
47147
- }, Components: {
47256
+ },
47257
+ Components: {
47148
47258
  notification: NotificationToast,
47149
- } },
47259
+ },
47260
+ }); }, [config === null || config === void 0 ? void 0 : config.maxVisibleToasts, config === null || config === void 0 ? void 0 : config.autoRemoveDelay]);
47261
+ return (React.createElement(SnackbarProvider, __assign({}, snackbarProps),
47150
47262
  React.createElement(material.GlobalStyles, { styles: {
47151
47263
  '.snackbarStack': {
47152
47264
  display: 'flex !important',
@@ -47156,12 +47268,22 @@ var NotificationProviderBase = function (_a) {
47156
47268
  } }),
47157
47269
  React.createElement(NotificationContext.Provider, { value: notificationState }, children)));
47158
47270
  };
47271
+ // Default empty config to prevent creating new object on each render
47272
+ var EMPTY_CONFIG = {};
47159
47273
  var NotificationProvider = function (_a) {
47160
- var children = _a.children, _b = _a.config, config = _b === void 0 ? {} : _b;
47161
- var isV2 = config.isV2, restConfig = __rest(config, ["isV2"]);
47162
- if (isV2)
47163
- return (React.createElement(NotificationProviderBase, { config: restConfig, useNotificationsHook: useNotificationsV2 }, children));
47164
- return (React.createElement(NotificationProviderBase, { config: restConfig, useNotificationsHook: useNotifications }, children));
47274
+ var children = _a.children, _b = _a.config, config = _b === void 0 ? EMPTY_CONFIG : _b;
47275
+ // Extract isV2 flag
47276
+ var isV2 = config === null || config === void 0 ? void 0 : config.isV2;
47277
+ // Memoize the config without isV2 to prevent recreating object
47278
+ var restConfig = React.useMemo(function () {
47279
+ if (!config)
47280
+ return {};
47281
+ config.isV2; var rest = __rest(config, ["isV2"]);
47282
+ return rest;
47283
+ }, [config]);
47284
+ // Memoize the hook selection
47285
+ var useNotificationsHook = React.useMemo(function () { return (isV2 ? useNotificationsV2 : useNotifications); }, [isV2]);
47286
+ return (React.createElement(NotificationProviderBase, { config: restConfig, useNotificationsHook: useNotificationsHook }, children));
47165
47287
  };
47166
47288
  var useNotificationContext = function () {
47167
47289
  var context = React.useContext(NotificationContext);
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "bs-unified-ui",
3
- "version": "1.0.915",
3
+ "version": "1.0.920",
4
4
  "license": "MIT",
5
5
  "author": "Advesa",
6
6
  "description": "UI Components for Unified Breadstack UI",