@stigg/react-sdk 4.8.1 → 4.9.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": "4.8.1",
2
+ "version": "4.9.0",
3
3
  "license": "MIT",
4
4
  "main": "dist/index.js",
5
5
  "typings": "dist/index.d.ts",
@@ -18,6 +18,7 @@
18
18
  "lint-fix": "yarn run lint --fix",
19
19
  "size": "size-limit",
20
20
  "analyze": "size-limit --why",
21
+ "fix:prettier": "prettier \"src/**/*.ts\" --write",
21
22
  "storybook": "export NODE_OPTIONS=--openssl-legacy-provider && start-storybook -p 6006",
22
23
  "build-storybook": "build-storybook",
23
24
  "prepare": "husky install",
@@ -4,7 +4,7 @@ import styled from '@emotion/styled/macro';
4
4
  import { PlanOffering } from './PlanOffering';
5
5
  import { BillingPeriodPicker } from './BillingPeriodPicker';
6
6
  import { calculatePaywallDiscountRate } from '../utils/calculateDiscountRate';
7
- import { OnPlanSelectedCallbackFn, PaywallPlan, SubscribeIntentionType } from './types';
7
+ import { ShouldHidePlanFn, OnPlanSelectedCallbackFn, PaywallPlan, SubscribeIntentionType } from './types';
8
8
  import { PaywallLocalization } from './paywallTextOverrides';
9
9
  import { PoweredByStigg } from '../common/PoweredByStigg';
10
10
  import { useStiggContext } from '../..';
@@ -51,6 +51,7 @@ type PaywallProps = {
51
51
  onPlanSelected: OnPlanSelectedCallbackFn;
52
52
  paywallLocale: PaywallLocalization;
53
53
  locale: string;
54
+ shouldHidePlan?: ShouldHidePlanFn;
54
55
  };
55
56
 
56
57
  export const Paywall = ({
@@ -65,13 +66,14 @@ export const Paywall = ({
65
66
  onPlanSelected,
66
67
  paywallLocale,
67
68
  locale,
69
+ shouldHidePlan,
68
70
  }: PaywallProps) => {
69
71
  const { stigg } = useStiggContext();
70
72
  const discountRate = calculatePaywallDiscountRate(plans);
71
73
  const shouldShowDescriptionSection = plans.some((plan) => !!plan.description);
72
74
  const hasMonthlyPrice = hasPricePointsForPlans(plans, BillingPeriod.Monthly);
73
75
  const hasAnnuallyPrice = hasPricePointsForPlans(plans, BillingPeriod.Annually);
74
- const plansToShow = getPlansToDisplay(plans, selectedBillingPeriod);
76
+ const plansToShow = getPlansToDisplay(plans, selectedBillingPeriod, shouldHidePlan);
75
77
 
76
78
  const handleOnSubscribe = useCallback(
77
79
  (plan: Plan, intentionType: SubscribeIntentionType, billableFeatures: BillableFeature[]) => {
@@ -2,7 +2,7 @@ import React from 'react';
2
2
  import { BillingPeriod } from '@stigg/js-client-sdk';
3
3
  import { Paywall } from './Paywall';
4
4
  import { useLoadPaywallData } from './hooks/useLoadPaywallData';
5
- import { OnPlanSelectedCallbackFn } from './types';
5
+ import { ShouldHidePlanFn, OnPlanSelectedCallbackFn } from './types';
6
6
  import { getResolvedPaywallLocalize, PaywallLocalization } from './paywallTextOverrides';
7
7
  import { DeepPartial } from '../../types';
8
8
  import { PaywallLoader } from './PaywallLoader';
@@ -23,6 +23,7 @@ export type PaywallContainerProps = {
23
23
  onBillingPeriodChange?: (billingPeriod: BillingPeriod) => void;
24
24
  textOverrides?: DeepPartial<PaywallLocalization>;
25
25
  billingCountryCode?: string;
26
+ shouldHidePlan?: ShouldHidePlanFn;
26
27
  };
27
28
 
28
29
  export const PaywallContainer = ({
@@ -35,6 +36,7 @@ export const PaywallContainer = ({
35
36
  preferredBillingPeriod,
36
37
  onBillingPeriodChange,
37
38
  billingCountryCode,
39
+ shouldHidePlan,
38
40
  }: PaywallContainerProps) => {
39
41
  const hasCustomerPortalContext = useCheckContextExists(CustomerPortalContext);
40
42
  let isCustomerPortalLoading = false;
@@ -86,6 +88,7 @@ export const PaywallContainer = ({
86
88
  onPlanSelected={onPlanSelected}
87
89
  paywallLocale={paywallLocale}
88
90
  locale={locale}
91
+ shouldHidePlan={shouldHidePlan}
89
92
  />
90
93
  );
91
94
 
@@ -61,3 +61,5 @@ export type OnPlanSelectedCallbackFn = ({
61
61
  selectedBillingPeriod: BillingPeriod;
62
62
  billableFeatures?: BillableFeature[];
63
63
  }) => void | Promise<void>;
64
+
65
+ export type ShouldHidePlanFn = ({ plan }: { plan: PaywallPlan }) => boolean | Promise<boolean>;
@@ -1,7 +1,13 @@
1
1
  import { BillingPeriod, PricingType } from '@stigg/js-client-sdk';
2
- import { PaywallPlan } from '../types';
2
+ import { ShouldHidePlanFn, PaywallPlan } from '../types';
3
3
  import { hasPricePoints } from './hasPricePoints';
4
4
 
5
- export function getPlansToDisplay(plans: PaywallPlan[], selectedBillingPeriod: BillingPeriod): PaywallPlan[] {
6
- return plans.filter(plan => plan.pricingType !== PricingType.Paid || hasPricePoints(plan, selectedBillingPeriod));
7
- }
5
+ export function getPlansToDisplay(
6
+ plans: PaywallPlan[],
7
+ selectedBillingPeriod: BillingPeriod,
8
+ shouldHidePlan?: ShouldHidePlanFn,
9
+ ): PaywallPlan[] {
10
+ return plans
11
+ .filter((plan) => plan.pricingType !== PricingType.Paid || hasPricePoints(plan, selectedBillingPeriod))
12
+ .filter((plan) => !shouldHidePlan || !shouldHidePlan({ plan }));
13
+ }
@@ -39,6 +39,7 @@ const Template: ComponentStory<any> = (args) => (
39
39
  resourceId={args.resourceId}
40
40
  billingCountryCode={args.billingCountryCode}
41
41
  preferredBillingPeriod={args.preferredBillingPeriod}
42
+ shouldHidePlan={args.shouldHidePlan}
42
43
  />
43
44
  );
44
45