@wlloyalty/wll-react-sdk 1.4.2 → 1.4.4

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
@@ -1,6 +1,6 @@
1
1
  import * as LucideReactIcons from 'lucide-react';
2
2
  import * as react_native from 'react-native';
3
- import { ViewProps, ImageSourcePropType, StyleProp, ViewStyle, TextProps as TextProps$1, TextStyle, ImageProps } from 'react-native';
3
+ import { ViewProps, ImageSourcePropType, StyleProp, ViewStyle, TextProps as TextProps$1, TextStyle, ImageProps, RefreshControl } from 'react-native';
4
4
  import * as React$1 from 'react';
5
5
  import React__default from 'react';
6
6
 
@@ -600,6 +600,8 @@ type TGroup = {
600
600
 
601
601
  type GroupProps = {
602
602
  id: string;
603
+ enablePullToRefresh?: boolean;
604
+ onRefresh?: () => Promise<void>;
603
605
  };
604
606
  /**
605
607
  * A page-level component that represents a Group view in the application.
@@ -613,7 +615,7 @@ type GroupProps = {
613
615
  * @param {string} props.id - The unique identifier of the group to fetch and display
614
616
  * @returns {JSX.Element|null} The rendered group or null if invalid ID
615
617
  */
616
- declare const Group: ({ id }: GroupProps) => JSX.Element | null;
618
+ declare const Group: ({ id, enablePullToRefresh, onRefresh }: GroupProps) => JSX.Element | null;
617
619
 
618
620
  type PointsTileProps = {
619
621
  tile: Tile;
@@ -725,4 +727,24 @@ type WllSdkProviderProps = WithChildren & {
725
727
  declare const WllSdkProvider: ({ children, theme: providedTheme, config, navigationConfig, }: WllSdkProviderProps) => JSX.Element;
726
728
  declare const useWllSdk: () => WllSdkContextType;
727
729
 
728
- export { type APIResponse, type Align, type AllowedCoreApiUrl, type Availability, type Badge, type BadgeDetail, _default$6 as BadgeTile, BadgeTileConfig, BadgeTileType, _default$5 as BannerTile, BannerTileConfig, BaseBanner, type BaseThemeObject, BaseTile, Button, CTALinkTarget, Carousel, CarouselNavButton, Column, _default$4 as ContentTile, ContentTileConfig, CoreApiUrl, type DerivedColors, type DerivedProperties, type DesaturationType, type FlexDirection, FullFlex, Grid, Group, Icon, type ImagePropsNoSource, Indicator, type Justify, Layout, type LayoutProps$1 as LayoutProps, LoadingIndicator, type NavigationConfig, type NavigationType, type PercentageKey, _default$3 as PointsTile, PointsTileConfig, type ProgessType, ProgressBar, ProgressIndicator, ProgressType, ProgressiveImage, Reward, type RewardCategory, _default$2 as RewardCategoryTile, RewardCategoryTileConfig, _default$1 as RewardTile, RewardTileConfig, _default as RoundupTile, RoundupTileConfig, Row, type SDKConfig, Section, SectionHeader, SectionType, type Size, Skeleton, Spacer, type TGroup, type TSection, Text, type ThemeContextType, type ThemeObject, type ThemeProviderProps, TierTileConfig, TierTileType, TierTile as TierTileUpdated, type TierType, type Tile, type TileConfig, TileContainer, TileHeight, type TileSizeInfo, TileType, type Variant, WllSdkProvider, alignMap, justifyMap, useWllSdk };
730
+ /**
731
+ * Hook to invalidate SDK data
732
+ * @returns Methods to trigger SDK data updates
733
+ */
734
+ declare function useInvalidateData(): {
735
+ invalidateGroupData: () => void;
736
+ invalidateSectionData: (sectionId?: string) => void;
737
+ invalidateTileData: (tileId?: string) => void;
738
+ };
739
+
740
+ type UsePullToRefreshProps = {
741
+ onRefresh?: () => Promise<void>;
742
+ refreshing?: boolean;
743
+ };
744
+ declare function usePullToRefresh({ onRefresh, refreshing: externalRefreshing, }?: UsePullToRefreshProps): {
745
+ refreshControl: React__default.CElement<react_native.RefreshControlProps, RefreshControl>;
746
+ refreshing: boolean;
747
+ handleRefresh: () => Promise<void>;
748
+ };
749
+
750
+ export { type APIResponse, type Align, type AllowedCoreApiUrl, type Availability, type Badge, type BadgeDetail, _default$6 as BadgeTile, BadgeTileConfig, BadgeTileType, _default$5 as BannerTile, BannerTileConfig, BaseBanner, type BaseThemeObject, BaseTile, Button, CTALinkTarget, Carousel, CarouselNavButton, Column, _default$4 as ContentTile, ContentTileConfig, CoreApiUrl, type DerivedColors, type DerivedProperties, type DesaturationType, type FlexDirection, FullFlex, Grid, Group, Icon, type ImagePropsNoSource, Indicator, type Justify, Layout, type LayoutProps$1 as LayoutProps, LoadingIndicator, type NavigationConfig, type NavigationType, type PercentageKey, _default$3 as PointsTile, PointsTileConfig, type ProgessType, ProgressBar, ProgressIndicator, ProgressType, ProgressiveImage, Reward, type RewardCategory, _default$2 as RewardCategoryTile, RewardCategoryTileConfig, _default$1 as RewardTile, RewardTileConfig, _default as RoundupTile, RoundupTileConfig, Row, type SDKConfig, Section, SectionHeader, SectionType, type Size, Skeleton, Spacer, type TGroup, type TSection, Text, type ThemeContextType, type ThemeObject, type ThemeProviderProps, TierTileConfig, TierTileType, TierTile as TierTileUpdated, type TierType, type Tile, type TileConfig, TileContainer, TileHeight, type TileSizeInfo, TileType, type Variant, WllSdkProvider, alignMap, justifyMap, useInvalidateData, usePullToRefresh, useWllSdk };
package/dist/native.js CHANGED
@@ -3859,6 +3859,85 @@ var useInitialGroupFetch = function (_a) {
3859
3859
  return { isLoading: isLoading, error: error };
3860
3860
  };
3861
3861
 
3862
+ /**
3863
+ * Hook to invalidate SDK data
3864
+ * @returns Methods to trigger SDK data updates
3865
+ */
3866
+ function useInvalidateData() {
3867
+ var sdk = useWllSdk();
3868
+ return {
3869
+ invalidateGroupData: function () {
3870
+ if (sdk) {
3871
+ sdk.notifyDataChange('GROUP_DATA_CHANGED');
3872
+ }
3873
+ },
3874
+ invalidateSectionData: function (sectionId) {
3875
+ if (sdk) {
3876
+ sdk.notifyDataChange('SECTION_DATA_CHANGED', { sectionId: sectionId });
3877
+ }
3878
+ },
3879
+ invalidateTileData: function (tileId) {
3880
+ if (sdk) {
3881
+ sdk.notifyDataChange('TILE_DATA_CHANGED', { tileId: tileId });
3882
+ }
3883
+ },
3884
+ };
3885
+ }
3886
+
3887
+ function usePullToRefresh(_a) {
3888
+ var _this = this;
3889
+ var _b = _a === void 0 ? {} : _a, onRefresh = _b.onRefresh, externalRefreshing = _b.refreshing;
3890
+ var _c = React.useState(false), internalRefreshing = _c[0], setInternalRefreshing = _c[1];
3891
+ var invalidateGroupData = useInvalidateData().invalidateGroupData;
3892
+ var refreshing = externalRefreshing !== null && externalRefreshing !== void 0 ? externalRefreshing : internalRefreshing;
3893
+ var handleRefresh = React.useCallback(function () { return __awaiter(_this, void 0, void 0, function () {
3894
+ var error_1;
3895
+ return __generator(this, function (_a) {
3896
+ switch (_a.label) {
3897
+ case 0:
3898
+ if (refreshing)
3899
+ return [2 /*return*/];
3900
+ setInternalRefreshing(true);
3901
+ _a.label = 1;
3902
+ case 1:
3903
+ _a.trys.push([1, 6, 7, 8]);
3904
+ if (!onRefresh) return [3 /*break*/, 3];
3905
+ return [4 /*yield*/, onRefresh()];
3906
+ case 2:
3907
+ _a.sent();
3908
+ return [3 /*break*/, 5];
3909
+ case 3:
3910
+ // Default behavior: refresh all group data
3911
+ invalidateGroupData();
3912
+ // Add a small delay to show the refresh animation
3913
+ return [4 /*yield*/, new Promise(function (resolve) { return setTimeout(resolve, 1000); })];
3914
+ case 4:
3915
+ // Add a small delay to show the refresh animation
3916
+ _a.sent();
3917
+ _a.label = 5;
3918
+ case 5: return [3 /*break*/, 8];
3919
+ case 6:
3920
+ error_1 = _a.sent();
3921
+ console.error('Pull to refresh failed:', error_1);
3922
+ return [3 /*break*/, 8];
3923
+ case 7:
3924
+ setInternalRefreshing(false);
3925
+ return [7 /*endfinally*/];
3926
+ case 8: return [2 /*return*/];
3927
+ }
3928
+ });
3929
+ }); }, [refreshing, onRefresh, invalidateGroupData]);
3930
+ var refreshControl = React.createElement(reactNative.RefreshControl, {
3931
+ refreshing: refreshing,
3932
+ onRefresh: handleRefresh,
3933
+ });
3934
+ return {
3935
+ refreshControl: refreshControl,
3936
+ refreshing: refreshing,
3937
+ handleRefresh: handleRefresh,
3938
+ };
3939
+ }
3940
+
3862
3941
  exports.SectionType = void 0;
3863
3942
  (function (SectionType) {
3864
3943
  SectionType["Grid"] = "GRID";
@@ -4466,14 +4545,18 @@ var GroupSections = function () {
4466
4545
  * @returns {JSX.Element|null} The rendered group or null if invalid ID
4467
4546
  */
4468
4547
  var Group = function (_a) {
4469
- var id = _a.id;
4548
+ var id = _a.id, _b = _a.enablePullToRefresh, enablePullToRefresh = _b === void 0 ? true : _b, onRefresh = _a.onRefresh;
4470
4549
  if (!id) {
4471
4550
  console.warn('Group component requires id prop');
4472
4551
  return null;
4473
4552
  }
4474
- var _b = useGroupData(id), groupData = _b.groupData, isLoading = _b.isLoading, error = _b.error;
4553
+ var _c = useGroupData(id), groupData = _c.groupData, isLoading = _c.isLoading, error = _c.error;
4475
4554
  var theme = useWllSdk().theme;
4476
- if (isLoading) {
4555
+ var _d = usePullToRefresh({
4556
+ onRefresh: onRefresh,
4557
+ refreshing: isLoading && !groupData
4558
+ }), refreshControl = _d.refreshControl; _d.refreshing;
4559
+ if (isLoading && !groupData) {
4477
4560
  return (jsxRuntimeExports.jsx(reactNative.View, { style: {
4478
4561
  flex: 1,
4479
4562
  padding: IS_MOBILE ? theme.sizes.lg : undefined,
@@ -4482,7 +4565,14 @@ var Group = function (_a) {
4482
4565
  if (error || !groupData) {
4483
4566
  return jsxRuntimeExports.jsx(GroupEmptyState, { message: error || 'No group data available' });
4484
4567
  }
4485
- return (jsxRuntimeExports.jsx(GroupContext.Provider, { value: { groupData: groupData }, children: jsxRuntimeExports.jsx(reactNative.View, { testID: "group-container", children: jsxRuntimeExports.jsx(GroupSections, {}) }) }));
4568
+ var Container = IS_WEB ? reactNative.View : reactNative.ScrollView;
4569
+ var containerProps = IS_WEB
4570
+ ? {}
4571
+ : {
4572
+ refreshControl: enablePullToRefresh ? refreshControl : undefined,
4573
+ showsVerticalScrollIndicator: true,
4574
+ };
4575
+ return (jsxRuntimeExports.jsx(GroupContext.Provider, { value: { groupData: groupData }, children: jsxRuntimeExports.jsx(reactNative.View, { testID: "group-container", children: jsxRuntimeExports.jsx(Container, __assign({}, containerProps, { children: jsxRuntimeExports.jsx(GroupSections, {}) })) }) }));
4486
4576
  };
4487
4577
 
4488
4578
  /**
@@ -5394,5 +5484,7 @@ exports.TileContainer = TileContainer;
5394
5484
  exports.WllSdkProvider = WllSdkProvider;
5395
5485
  exports.alignMap = alignMap;
5396
5486
  exports.justifyMap = justifyMap;
5487
+ exports.useInvalidateData = useInvalidateData;
5488
+ exports.usePullToRefresh = usePullToRefresh;
5397
5489
  exports.useWllSdk = useWllSdk;
5398
5490
  //# sourceMappingURL=native.js.map