@wlloyalty/wll-react-sdk 1.0.113 → 1.2.0

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.
@@ -2,6 +2,10 @@ import { CTALinkTarget, RoundupTileConfig, TileHeight, TileType } from '../../ty
2
2
  export type RoundupTileMockConfig = Partial<RoundupTileConfig> & {
3
3
  active?: boolean;
4
4
  tileHeight?: TileHeight;
5
+ defaultLocale?: string;
6
+ details?: any[];
7
+ locale?: string;
8
+ balance?: number;
5
9
  };
6
10
  export declare const createRoundupTileMock: (config?: RoundupTileMockConfig) => {
7
11
  id: string;
@@ -13,11 +17,14 @@ export declare const createRoundupTileMock: (config?: RoundupTileMockConfig) =>
13
17
  priority: number;
14
18
  configuration: {
15
19
  title: string | null;
16
- amount: number;
17
- amountPrefix: string | null;
18
- amountSuffix: string | null;
19
20
  artworkUrl: string | null;
20
21
  ctaLink: string | null | undefined;
21
22
  ctaLinkTarget: CTALinkTarget | undefined;
23
+ defaultLocale: string;
24
+ details: any[];
25
+ locale: string;
26
+ balance: number | undefined;
27
+ amountPrefix: string | null | undefined;
28
+ amountSuffix: string | null | undefined;
22
29
  };
23
30
  };
@@ -49,7 +49,7 @@ export declare class RoundupTileConfig {
49
49
  amountPrefix?: string | null;
50
50
  amountSuffix?: string | null;
51
51
  artworkUrl?: string | null;
52
- amount?: number;
52
+ balance?: number;
53
53
  ctaLink?: string | null;
54
54
  ctaLinkTarget?: CTALinkTarget;
55
55
  }
@@ -1,3 +1,9 @@
1
+ /**
2
+ * Cleans up a number by removing any whitespace and ensuring it's a valid number
3
+ * @param value The number to clean up
4
+ * @returns A cleaned up number as a number
5
+ */
6
+ export declare const cleanNumber: (value: number) => number;
1
7
  /**
2
8
  * Applies a multiplier to a base value. Handles string multipliers by converting them to numbers.
3
9
  * If the multiplier is invalid (NaN, null, undefined), defaults to 1.
package/dist/web.js CHANGED
@@ -20640,6 +20640,7 @@ var useGroupRefresh = function (_a) {
20640
20640
  }, [id, sdk, enabled, setGroupData]);
20641
20641
  };
20642
20642
 
20643
+ var inFlightRequests = new Map();
20643
20644
  var useInitialGroupFetch = function (_a) {
20644
20645
  var id = _a.id,
20645
20646
  setGroupData = _a.setGroupData;
@@ -20651,32 +20652,42 @@ var useInitialGroupFetch = function (_a) {
20651
20652
  error = _c[0],
20652
20653
  setError = _c[1];
20653
20654
  React.useEffect(function () {
20655
+ if (!id || !(sdk === null || sdk === void 0 ? void 0 : sdk.refreshGroup)) {
20656
+ setError('Unable to fetch group data: invalid configuration');
20657
+ setIsLoading(false);
20658
+ return;
20659
+ }
20654
20660
  var cancelled = false;
20655
- var fetchGroup = function () {
20661
+ var fetch = function () {
20656
20662
  return __awaiter(void 0, void 0, void 0, function () {
20657
- var response;
20663
+ var existing, request, res;
20658
20664
  var _b;
20659
20665
  return __generator(this, function (_c) {
20660
20666
  switch (_c.label) {
20661
20667
  case 0:
20662
- if (!id || !(sdk === null || sdk === void 0 ? void 0 : sdk.refreshGroup)) {
20663
- setError('Unable to fetch group data: invalid configuration');
20664
- setIsLoading(false);
20665
- return [2 /*return*/];
20666
- }
20667
20668
  setIsLoading(true);
20668
20669
  setError(null);
20670
+ existing = inFlightRequests.get(id);
20671
+ request = existing !== null && existing !== void 0 ? existing : sdk.refreshGroup(id);
20672
+ if (!existing) {
20673
+ inFlightRequests.set(id, request);
20674
+ request.finally(function () {
20675
+ if (inFlightRequests.get(id) === request) {
20676
+ inFlightRequests.delete(id);
20677
+ }
20678
+ });
20679
+ }
20669
20680
  _c.label = 1;
20670
20681
  case 1:
20671
20682
  _c.trys.push([1, 3, 4, 5]);
20672
- return [4 /*yield*/, sdk.refreshGroup(id)];
20683
+ return [4 /*yield*/, request];
20673
20684
  case 2:
20674
- response = _c.sent();
20685
+ res = _c.sent();
20675
20686
  if (cancelled) return [2 /*return*/];
20676
- if ((response === null || response === void 0 ? void 0 : response.status) === 'success' && response.data) {
20677
- setGroupData(response.data);
20687
+ if ((res === null || res === void 0 ? void 0 : res.status) === 'success' && res.data) {
20688
+ setGroupData(res.data);
20678
20689
  } else {
20679
- setError((_b = response === null || response === void 0 ? void 0 : response.error) !== null && _b !== void 0 ? _b : 'Failed to fetch group data');
20690
+ setError((_b = res === null || res === void 0 ? void 0 : res.error) !== null && _b !== void 0 ? _b : 'Failed to fetch group data');
20680
20691
  }
20681
20692
  return [3 /*break*/, 5];
20682
20693
  case 3:
@@ -20692,7 +20703,7 @@ var useInitialGroupFetch = function (_a) {
20692
20703
  });
20693
20704
  });
20694
20705
  };
20695
- fetchGroup();
20706
+ fetch();
20696
20707
  return function () {
20697
20708
  cancelled = true;
20698
20709
  };
@@ -22505,6 +22516,36 @@ TierTile.Full = TierTileFull;
22505
22516
  TierTile.Half = TierTileHalf;
22506
22517
  TierTile.Empty = TierTileEmpty;
22507
22518
 
22519
+ /**
22520
+ * Renders formatted points value for a Roundup Tile.
22521
+ *
22522
+ * @returns JSX.Element or null if points are undefined or zero
22523
+ */
22524
+ var RoundupTileFormattedPoints = function () {
22525
+ var tileContext = useTileContext();
22526
+ if (!isContextValid(tileContext)) return null;
22527
+ var _a = tileContext.configuration,
22528
+ _b = _a.balance,
22529
+ balance = _b === void 0 ? 0 : _b,
22530
+ _c = _a.amountPrefix,
22531
+ amountPrefix = _c === void 0 ? '' : _c,
22532
+ _d = _a.amountSuffix,
22533
+ amountSuffix = _d === void 0 ? '' : _d;
22534
+ if (balance === undefined) return null;
22535
+ var fullPointsText = "".concat(amountPrefix).concat(cleanNumber(balance)).concat(amountSuffix).trim();
22536
+ return /*#__PURE__*/React.createElement(View$2, {
22537
+ testID: "roundup-tile-amount",
22538
+ role: "article",
22539
+ accessibilityLabel: "Amount: ".concat(fullPointsText)
22540
+ }, /*#__PURE__*/React.createElement(Row, {
22541
+ align: "center",
22542
+ justify: "start"
22543
+ }, /*#__PURE__*/React.createElement(Text, {
22544
+ variant: "caption",
22545
+ testID: "roundup-tile-value"
22546
+ }, fullPointsText)));
22547
+ };
22548
+
22508
22549
  /**
22509
22550
  * Custom hook that returns the styles for the RoundupTile component.
22510
22551
  * Applies responsive styling based on the current device.
@@ -22564,44 +22605,6 @@ var useRoundupTileStyles = function (isFullSize) {
22564
22605
  });
22565
22606
  };
22566
22607
 
22567
- /**
22568
- * Renders formatted points value for a Roundup Tile.
22569
- *
22570
- * @returns JSX.Element or null if points are undefined or zero
22571
- */
22572
- var RoundupTileFormattedPoints = function () {
22573
- var styles = useRoundupTileStyles();
22574
- var tileContext = useTileContext();
22575
- if (!isContextValid(tileContext)) return null;
22576
- var _a = tileContext.configuration,
22577
- _b = _a.amountPrefix,
22578
- amountPrefix = _b === void 0 ? '' : _b,
22579
- _c = _a.amountSuffix,
22580
- amountSuffix = _c === void 0 ? '' : _c,
22581
- _d = _a.amount,
22582
- amount = _d === void 0 ? 0 : _d;
22583
- if (amount === undefined) return null;
22584
- var fullPointsText = "".concat(amountPrefix).concat(amount, " ").concat(amountSuffix).trim();
22585
- return /*#__PURE__*/React.createElement(View$2, {
22586
- testID: "roundup-tile-amount",
22587
- role: "article",
22588
- accessibilityLabel: "Amount: ".concat(fullPointsText)
22589
- }, /*#__PURE__*/React.createElement(Row, {
22590
- align: "center",
22591
- justify: "start"
22592
- }, amountPrefix ? (/*#__PURE__*/React.createElement(Text, {
22593
- variant: "caption",
22594
- testID: "roundup-tile-prefix"
22595
- }, amountPrefix)) : null, /*#__PURE__*/React.createElement(Text, {
22596
- variant: "caption",
22597
- testID: "roundup-tile-value"
22598
- }, amount), amountSuffix ? (/*#__PURE__*/React.createElement(Text, {
22599
- variant: "caption",
22600
- style: styles.suffix,
22601
- testID: "roundup-tile-suffix"
22602
- }, amountSuffix)) : null));
22603
- };
22604
-
22605
22608
  /**
22606
22609
  * Renders the media of a Points Tile.
22607
22610
  *