@stigg/react-sdk 6.3.0 → 6.4.1

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/package.json CHANGED
@@ -1,5 +1,5 @@
1
1
  {
2
- "version": "6.3.0",
2
+ "version": "6.4.1",
3
3
  "license": "MIT",
4
4
  "main": "dist/index.js",
5
5
  "typings": "dist/index.d.ts",
@@ -0,0 +1,18 @@
1
+ import React from 'react';
2
+ import { GetEnumEntitlement } from '@stigg/js-client-sdk';
3
+ import { useEnumEntitlement } from '../hooks';
4
+
5
+ type EnumEntitlementGuardProps = GetEnumEntitlement & {
6
+ noAccessComponent?: React.ReactNode;
7
+ children: React.ReactElement;
8
+ };
9
+
10
+ export function EnumEntitlementGuard({ noAccessComponent, children, ...rest }: EnumEntitlementGuardProps): JSX.Element {
11
+ const { hasAccess } = useEnumEntitlement(rest);
12
+
13
+ if (!hasAccess) {
14
+ return <>{noAccessComponent ?? null}</>;
15
+ }
16
+
17
+ return children;
18
+ }
@@ -90,6 +90,8 @@ export function PlanCompatibleAddons({ addons, paywallLocale }: PlanCompatibleAd
90
90
 
91
91
  const displayedAddons = showAllAddons ? visibleAddons : visibleAddons.slice(0, MAX_ADDONS);
92
92
 
93
+ if (displayedAddons.length === 0) return null;
94
+
93
95
  return (
94
96
  <AddonsBox className="stigg-compatible-addons-container">
95
97
  <Typography className="stigg-compatible-addons-header" color="secondary" variant="body1" bold>
@@ -1,6 +1,7 @@
1
1
  export { useBooleanEntitlement } from './useBooleanEntitlement';
2
2
  export { useNumericEntitlement } from './useNumericEntitlement';
3
3
  export { useMeteredEntitlement } from './useMeteredEntitlement';
4
+ export { useEnumEntitlement } from './useEnumEntitlement';
4
5
  export { useActiveSubscriptions } from './useActiveSubscriptions';
5
6
  export { usePaywall } from './usePaywall';
6
7
  export { useCustomerPortal } from './useCustomerPortal';
@@ -0,0 +1,20 @@
1
+ import { GetEnumEntitlement, ENUM_DEFAULT_FALLBACK_ENTITLEMENT, EnumEntitlement } from '@stigg/js-client-sdk';
2
+ import { useStiggContext } from './useStiggContext';
3
+
4
+ type TypedGetEnumEntitlement<T> = Omit<GetEnumEntitlement, 'featureId'> & {
5
+ featureId: T;
6
+ };
7
+
8
+ export function useEnumEntitlement<T extends string>(params: TypedGetEnumEntitlement<T>): EnumEntitlement {
9
+ const stiggContext = useStiggContext({ optional: true });
10
+ const stigg = stiggContext?.stigg;
11
+
12
+ if (!stigg) {
13
+ return {
14
+ ...ENUM_DEFAULT_FALLBACK_ENTITLEMENT,
15
+ ...params.options?.fallback,
16
+ };
17
+ }
18
+
19
+ return stigg.getEnumEntitlement(params);
20
+ }
package/src/index.ts CHANGED
@@ -56,6 +56,7 @@ export { useWaitForCheckoutCompleted, ProvisionStatus } from './components/hooks
56
56
  export {
57
57
  useBooleanEntitlement,
58
58
  useMeteredEntitlement,
59
+ useEnumEntitlement,
59
60
  useNumericEntitlement,
60
61
  useActiveSubscriptions,
61
62
  useCustomerPortal,
@@ -67,3 +68,4 @@ export { CustomizedTheme as Theme } from './theme/Theme';
67
68
  export { BooleanEntitlementGuard } from './components/BooleanEntitlementGuard';
68
69
  export { NumericEntitlementGuard } from './components/NumericEntitlementGuard';
69
70
  export { MeteredEntitlementGuard } from './components/MeteredEntitlementGuard';
71
+ export { EnumEntitlementGuard } from './components/EnumEntitlementGuard';