@stigg/react-sdk 5.5.0 → 5.6.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.
package/package.json CHANGED
@@ -1,5 +1,5 @@
1
1
  {
2
- "version": "5.5.0",
2
+ "version": "5.6.0",
3
3
  "license": "MIT",
4
4
  "main": "dist/index.js",
5
5
  "typings": "dist/index.d.ts",
@@ -5,7 +5,7 @@ import { CustomerPortalContainer } from './CustomerPortalContainer';
5
5
  import { DeepPartial } from '../../types';
6
6
  import { CustomerPortalLocalization } from './customerPortalTextOverrides';
7
7
  import { CustomerPortalTheme } from './customerPortalTheme';
8
- import { OnBuyMoreCallbackFn, OnManageSubscriptionFn } from './types';
8
+ import { FilterEntitlementsFn, OnBuyMoreCallbackFn, OnManageSubscriptionFn } from './types';
9
9
 
10
10
  export type CustomerPortalSection =
11
11
  | 'usage'
@@ -24,6 +24,7 @@ export type CustomerPortalProps = {
24
24
  hiddenSections?: CustomerPortalSection[];
25
25
  textOverrides?: DeepPartial<CustomerPortalLocalization>;
26
26
  theme?: DeepPartial<CustomerPortalTheme>;
27
+ filterEntitlements?: FilterEntitlementsFn;
27
28
  resourceId?: string;
28
29
  productId?: string;
29
30
  };
@@ -19,6 +19,7 @@ export function CustomerPortalContainer({
19
19
  onContactSupport,
20
20
  paywallComponent,
21
21
  hiddenSections,
22
+ filterEntitlements,
22
23
  }: CustomerPortalProps) {
23
24
  const { stigg } = useStiggContext();
24
25
  const { customerPortal, textOverrides, theme, isLoading } = useCustomerPortalContext();
@@ -55,7 +56,13 @@ export function CustomerPortalContainer({
55
56
  hiddenSections={hiddenSections}
56
57
  cancelScheduledUpdatesButtonTitle={textOverrides.cancelScheduledUpdatesButtonTitle}
57
58
  />
58
- {shouldShowUsage && <CustomerUsageData onManageSubscription={onManageClick} onBuyMore={onBuyMore} />}
59
+ {shouldShowUsage && (
60
+ <CustomerUsageData
61
+ onManageSubscription={onManageClick}
62
+ onBuyMore={onBuyMore}
63
+ filterEntitlements={filterEntitlements}
64
+ />
65
+ )}
59
66
  <CustomerPortalPaywall
60
67
  ref={customerPortalSectionRef}
61
68
  paywallComponent={paywallComponent}
@@ -33,7 +33,9 @@ export function ChargeItem({
33
33
  hasCustomSubscription,
34
34
  }: UsageBasedChargeProps) {
35
35
  return (
36
- <div className="stigg-charge-list-item" style={{ display: 'flex', flexDirection: 'column', gap: 12 }}>
36
+ <div
37
+ className={`stigg-charge-list-item stigg-charge-list-item-${entitlement.feature!.refId}`}
38
+ style={{ display: 'flex', flexDirection: 'column', gap: 12 }}>
37
39
  <div style={{ display: 'flex', justifyContent: 'space-between', gap: 12 }}>
38
40
  <div style={{ display: 'flex', gap: 12 }}>
39
41
  <LongText variant="body1" color="primary">
@@ -3,6 +3,8 @@ import { FeatureFragment } from '@stigg/api-client-js/src/generated/sdk';
3
3
 
4
4
  export type OnBuyMoreCallbackFn = (feature: FeatureFragment, entitlement: CustomerPortalEntitlement) => void;
5
5
 
6
+ export type FilterEntitlementsFn = (entitlements: CustomerPortalEntitlement[]) => CustomerPortalEntitlement[];
7
+
6
8
  export enum CustomerPortalIntentionType {
7
9
  MANAGE_SUBSCRIPTION = 'MANAGE_SUBSCRIPTION',
8
10
  UPGRADE_PLAN = 'UPGRADE_PLAN',
@@ -10,7 +10,7 @@ import { SectionContainer } from '../common/SectionContainer';
10
10
  import { SectionHeader } from '../common/SectionHeader';
11
11
  import { SectionTitle } from '../common/SectionTitle';
12
12
  import { StyledButton } from '../common/StyledButton';
13
- import { OnBuyMoreCallbackFn } from '../types';
13
+ import { FilterEntitlementsFn, OnBuyMoreCallbackFn } from '../types';
14
14
  import { OnManageClick } from '../CustomerPortalContainer';
15
15
 
16
16
  const MAX_BOXES = 6;
@@ -18,9 +18,10 @@ const MAX_BOXES = 6;
18
18
  export type CustomerUsageDataProps = {
19
19
  onManageSubscription?: OnManageClick;
20
20
  onBuyMore?: OnBuyMoreCallbackFn;
21
+ filterEntitlements?: FilterEntitlementsFn;
21
22
  };
22
23
 
23
- export function CustomerUsageData({ onManageSubscription, onBuyMore }: CustomerUsageDataProps) {
24
+ export function CustomerUsageData({ onManageSubscription, onBuyMore, filterEntitlements }: CustomerUsageDataProps) {
24
25
  const [showAll, setShowAll] = React.useState(false);
25
26
  const { customerPortal, isLoading, textOverrides, theme } = useCustomerPortalContext();
26
27
  const isLoadingData = isLoading || !customerPortal;
@@ -48,10 +49,12 @@ export function CustomerUsageData({ onManageSubscription, onBuyMore }: CustomerU
48
49
  );
49
50
  const sortedEntitlements = [...priceEntitlements, ...otherEntitlements];
50
51
 
52
+ const filteredEntitlements = filterEntitlements ? filterEntitlements(sortedEntitlements) : sortedEntitlements;
53
+
51
54
  // 4 -> 3 per row, 6 -> 2 per row
52
- const xs = sortedEntitlements.length > 2 ? 4 : 6;
55
+ const xs = filteredEntitlements.length > 2 ? 4 : 6;
53
56
 
54
- const entitlementsToShow = showAll ? sortedEntitlements : sortedEntitlements.slice(0, MAX_BOXES);
57
+ const entitlementsToShow = showAll ? filteredEntitlements : filteredEntitlements.slice(0, MAX_BOXES);
55
58
 
56
59
  const toggleShowAll = () => setShowAll((prevState) => !prevState);
57
60
 
@@ -78,7 +81,11 @@ export function CustomerUsageData({ onManageSubscription, onBuyMore }: CustomerU
78
81
  <>
79
82
  <Grid container spacing={4}>
80
83
  {entitlementsToShow.map((entitlement) => (
81
- <Grid key={entitlement.feature!.refId} item xs={xs}>
84
+ <Grid
85
+ className={`stigg-entitlement-usage-${entitlement.feature!.refId}`}
86
+ key={entitlement.feature!.refId}
87
+ item
88
+ xs={xs}>
82
89
  <FeatureUsage
83
90
  key={entitlement.feature!.refId}
84
91
  subscriptionPrice={subscriptionPriceByFeature[entitlement.feature!.refId]}
@@ -92,7 +99,7 @@ export function CustomerUsageData({ onManageSubscription, onBuyMore }: CustomerU
92
99
  ))}
93
100
  </Grid>
94
101
 
95
- {sortedEntitlements.length > MAX_BOXES && (
102
+ {filteredEntitlements.length > MAX_BOXES && (
96
103
  <Footer>
97
104
  <StyledButton
98
105
  className="stigg-usage-toggle-many-button"