@wlloyalty/wll-react-sdk 1.0.100 → 1.0.102

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/index.d.ts CHANGED
@@ -526,8 +526,9 @@ type TSection = {
526
526
 
527
527
  type CarouselProps = {
528
528
  section?: TSection;
529
+ autoRotateInterval?: number;
529
530
  };
530
- declare const Carousel: ({ section }: CarouselProps) => JSX.Element | null;
531
+ declare const Carousel: ({ section, autoRotateInterval, }: CarouselProps) => JSX.Element | null;
531
532
 
532
533
  type CarouselNavButtonProps = {
533
534
  direction: 'left' | 'right';
@@ -677,6 +678,7 @@ type WllSdkContextType = ThemeContextType & {
677
678
  getSectionByID: (id: string) => Promise<APIResponse<TSection>>;
678
679
  getTileByID: (id: string) => Promise<APIResponse<Tile>>;
679
680
  handleNavigation: (link: string, target: CTALinkTarget) => Promise<void>;
681
+ refreshGroup: (id: string) => Promise<APIResponse<TGroup>>;
680
682
  } & Readonly<{
681
683
  readonly config: SDKConfig;
682
684
  }>;
package/dist/native.js CHANGED
@@ -1699,9 +1699,6 @@ var validateTheme = function (theme) {
1699
1699
  var createSafeColor = function (color) {
1700
1700
  try {
1701
1701
  var colorInstance = Color(color);
1702
- console.log('Original color:', color);
1703
- console.log('Color instance toString:', colorInstance.toString());
1704
- console.log('Color instance hex:', colorInstance.hex());
1705
1702
  return colorInstance;
1706
1703
  }
1707
1704
  catch (error) {
@@ -1959,6 +1956,11 @@ var WllSdkProvider = function (_a) {
1959
1956
  var getSectionByID = useGetSectionByID(config);
1960
1957
  var getTileByID = useGetTileByID(config);
1961
1958
  var handleNavigation = useNavigation(navigationConfig);
1959
+ var refreshGroup = React.useCallback(function (id) { return __awaiter(void 0, void 0, void 0, function () {
1960
+ return __generator(this, function (_a) {
1961
+ return [2 /*return*/, getGroupByID(id)];
1962
+ });
1963
+ }); }, [getGroupByID]);
1962
1964
  var contextValue = React.useMemo(function () { return ({
1963
1965
  theme: theme,
1964
1966
  setTheme: setTheme,
@@ -1966,6 +1968,7 @@ var WllSdkProvider = function (_a) {
1966
1968
  getSectionByID: getSectionByID,
1967
1969
  getTileByID: getTileByID,
1968
1970
  handleNavigation: handleNavigation,
1971
+ refreshGroup: refreshGroup,
1969
1972
  config: config,
1970
1973
  }); }, [
1971
1974
  theme,
@@ -1974,6 +1977,7 @@ var WllSdkProvider = function (_a) {
1974
1977
  getSectionByID,
1975
1978
  getTileByID,
1976
1979
  handleNavigation,
1980
+ refreshGroup,
1977
1981
  config,
1978
1982
  ]);
1979
1983
  return (jsxRuntimeExports.jsx(WllSdkContext.Provider, { value: contextValue, children: jsxRuntimeExports.jsx(ResponsiveProvider, { children: children }) }));
@@ -3666,7 +3670,7 @@ var carouselReducer = function (state, action) {
3666
3670
  }
3667
3671
  };
3668
3672
  var Carousel = function (_a) {
3669
- var section = _a.section;
3673
+ var section = _a.section, _b = _a.autoRotateInterval, autoRotateInterval = _b === void 0 ? 5000 : _b;
3670
3674
  if (!section)
3671
3675
  return null;
3672
3676
  var WINDOW_WIDTH = reactNative.useWindowDimensions().width;
@@ -3674,9 +3678,9 @@ var Carousel = function (_a) {
3674
3678
  var styles = useCarouselStyles(BUTTON_SIZE);
3675
3679
  var animatedIndex = React.useRef(new reactNative.Animated.Value(0)).current;
3676
3680
  var theme = useWllSdk().theme;
3677
- var _b = useResponsive(), isDesktop = _b.isDesktop, isTablet = _b.isTablet;
3681
+ var _c = useResponsive(), isDesktop = _c.isDesktop, isTablet = _c.isTablet;
3678
3682
  var scrollViewRef = React.useRef(null);
3679
- var _c = React.useReducer(carouselReducer, __assign(__assign({}, initialState), { containerWidth: WINDOW_WIDTH })), state = _c[0], dispatch = _c[1];
3683
+ var _d = React.useReducer(carouselReducer, __assign(__assign({}, initialState), { containerWidth: WINDOW_WIDTH })), state = _d[0], dispatch = _d[1];
3680
3684
  var currentIndex = state.currentIndex, containerWidth = state.containerWidth;
3681
3685
  var sortedTiles = sortByPriority(section.tiles.filter(function (tile) { return tile.type === exports.TileType.Banner; }));
3682
3686
  var handleScroll = React.useCallback(function (event) {
@@ -3699,12 +3703,34 @@ var Carousel = function (_a) {
3699
3703
  };
3700
3704
  var handleNext = function () {
3701
3705
  var _a;
3706
+ var nextIndex = Math.min(sortedTiles.length - 1, currentIndex + 1);
3702
3707
  dispatch({ type: 'NEXT_SLIDE', maxIndex: sortedTiles.length - 1 });
3703
3708
  (_a = scrollViewRef.current) === null || _a === void 0 ? void 0 : _a.scrollTo({
3704
- x: (currentIndex + 1) * containerWidth,
3709
+ x: nextIndex * containerWidth,
3705
3710
  animated: true,
3706
3711
  });
3707
3712
  };
3713
+ var rotateToNextSlide = React.useCallback(function () {
3714
+ var _a;
3715
+ if (currentIndex >= sortedTiles.length - 1) {
3716
+ dispatch({ type: 'SET_CURRENT_INDEX', payload: 0 });
3717
+ (_a = scrollViewRef.current) === null || _a === void 0 ? void 0 : _a.scrollTo({
3718
+ x: 0,
3719
+ animated: true,
3720
+ });
3721
+ }
3722
+ else {
3723
+ handleNext();
3724
+ }
3725
+ }, [currentIndex, containerWidth, sortedTiles.length]);
3726
+ React.useEffect(function () {
3727
+ if (sortedTiles.length <= 1)
3728
+ return;
3729
+ var rotationTimer = setInterval(function () {
3730
+ rotateToNextSlide();
3731
+ }, autoRotateInterval);
3732
+ return function () { return clearInterval(rotationTimer); };
3733
+ }, [rotateToNextSlide, autoRotateInterval, sortedTiles.length]);
3708
3734
  var displayControls = sortedTiles.length > 1;
3709
3735
  var showPrevButton = displayControls && currentIndex > 0;
3710
3736
  var showNextButton = displayControls && currentIndex < sortedTiles.length - 1;
@@ -4054,47 +4080,61 @@ var useGroupData = function (id) {
4054
4080
  var _a = React.useState(null), groupData = _a[0], setGroupData = _a[1];
4055
4081
  var _b = React.useState(null), error = _b[0], setError = _b[1];
4056
4082
  var _c = React.useState(true), isLoading = _c[0], setIsLoading = _c[1];
4057
- var fetchGroup = React.useCallback(function () { return __awaiter(void 0, void 0, void 0, function () {
4058
- var response, err_1;
4059
- return __generator(this, function (_a) {
4060
- switch (_a.label) {
4061
- case 0:
4062
- if (!id || !sdk || !sdk.getGroupByID) {
4063
- setError('Unable to fetch group data: invalid configuration');
4064
- setIsLoading(false);
4065
- return [2 /*return*/];
4066
- }
4067
- setIsLoading(true);
4068
- setError(null);
4069
- _a.label = 1;
4070
- case 1:
4071
- _a.trys.push([1, 3, 4, 5]);
4072
- return [4 /*yield*/, sdk.getGroupByID(id)];
4073
- case 2:
4074
- response = _a.sent();
4075
- if (response && response.status === 'success' && response.data) {
4076
- setGroupData(response.data);
4077
- }
4078
- else {
4079
- setError((response && response.error) || 'Failed to fetch group data.');
4080
- }
4081
- return [3 /*break*/, 5];
4082
- case 3:
4083
- err_1 = _a.sent();
4084
- setError('Failed to fetch group data. Please try again later.');
4085
- console.error('Error fetching group:', err_1);
4086
- return [3 /*break*/, 5];
4087
- case 4:
4088
- setIsLoading(false);
4089
- return [7 /*endfinally*/];
4090
- case 5: return [2 /*return*/];
4091
- }
4083
+ var fetchGroup = React.useCallback(function () {
4084
+ var args_1 = [];
4085
+ for (var _i = 0; _i < arguments.length; _i++) {
4086
+ args_1[_i] = arguments[_i];
4087
+ }
4088
+ return __awaiter(void 0, __spreadArray([], args_1, true), void 0, function (showLoading) {
4089
+ var response, err_1;
4090
+ if (showLoading === void 0) { showLoading = true; }
4091
+ return __generator(this, function (_a) {
4092
+ switch (_a.label) {
4093
+ case 0:
4094
+ if (!id || !sdk || !sdk.getGroupByID) {
4095
+ setError('Unable to fetch group data: invalid configuration');
4096
+ setIsLoading(false);
4097
+ return [2 /*return*/];
4098
+ }
4099
+ if (showLoading) {
4100
+ setIsLoading(true);
4101
+ }
4102
+ setError(null);
4103
+ _a.label = 1;
4104
+ case 1:
4105
+ _a.trys.push([1, 3, 4, 5]);
4106
+ return [4 /*yield*/, sdk.refreshGroup(id)];
4107
+ case 2:
4108
+ response = _a.sent();
4109
+ if (response && response.status === 'success' && response.data) {
4110
+ setGroupData(response.data);
4111
+ }
4112
+ else {
4113
+ setError((response && response.error) || 'Failed to fetch group data.');
4114
+ }
4115
+ return [3 /*break*/, 5];
4116
+ case 3:
4117
+ err_1 = _a.sent();
4118
+ setError('Failed to fetch group data. Please try again later.');
4119
+ console.error('Error fetching group:', err_1);
4120
+ return [3 /*break*/, 5];
4121
+ case 4:
4122
+ if (showLoading) {
4123
+ setIsLoading(false);
4124
+ }
4125
+ return [7 /*endfinally*/];
4126
+ case 5: return [2 /*return*/];
4127
+ }
4128
+ });
4092
4129
  });
4093
- }); }, [id, sdk]);
4130
+ }, [id, sdk]);
4131
+ var refreshGroup = React.useCallback(function () {
4132
+ return fetchGroup(false);
4133
+ }, [fetchGroup]);
4094
4134
  React.useEffect(function () {
4095
- fetchGroup();
4135
+ fetchGroup(true);
4096
4136
  }, [fetchGroup]);
4097
- return { groupData: groupData, isLoading: isLoading, error: error };
4137
+ return { groupData: groupData, isLoading: isLoading, error: error, refreshGroup: refreshGroup };
4098
4138
  };
4099
4139
  /**
4100
4140
  * Component to display an empty state with a message