@stigg/react-sdk 4.12.1 → 4.13.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/dist/components/paywall/Paywall.d.ts +3 -2
- package/dist/components/paywall/PaywallContainer.d.ts +3 -2
- package/dist/components/paywall/PlanOffering.d.ts +3 -2
- package/dist/components/paywall/types.d.ts +3 -0
- package/dist/components/utils/priceTierUtils.d.ts +3 -2
- package/dist/react-sdk.cjs.development.js +28 -20
- package/dist/react-sdk.cjs.development.js.map +1 -1
- package/dist/react-sdk.cjs.production.min.js +1 -1
- package/dist/react-sdk.cjs.production.min.js.map +1 -1
- package/dist/react-sdk.esm.js +28 -20
- package/dist/react-sdk.esm.js.map +1 -1
- package/package.json +1 -1
- package/src/components/paywall/Paywall.tsx +10 -1
- package/src/components/paywall/PaywallContainer.tsx +4 -1
- package/src/components/paywall/PlanOffering.tsx +4 -2
- package/src/components/paywall/types.ts +2 -0
- package/src/components/utils/priceTierUtils.ts +5 -3
package/package.json
CHANGED
|
@@ -4,7 +4,13 @@ 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 {
|
|
7
|
+
import {
|
|
8
|
+
ShouldHidePlanFn,
|
|
9
|
+
OnPlanSelectedCallbackFn,
|
|
10
|
+
PaywallPlan,
|
|
11
|
+
SubscribeIntentionType,
|
|
12
|
+
SelectDefaultTierIndexFn,
|
|
13
|
+
} from './types';
|
|
8
14
|
import { PaywallLocalization } from './paywallTextOverrides';
|
|
9
15
|
import { PoweredByStigg } from '../common/PoweredByStigg';
|
|
10
16
|
import { useStiggContext } from '../..';
|
|
@@ -52,6 +58,7 @@ type PaywallProps = {
|
|
|
52
58
|
paywallLocale: PaywallLocalization;
|
|
53
59
|
locale: string;
|
|
54
60
|
shouldHidePlan?: ShouldHidePlanFn;
|
|
61
|
+
selectDefaultTierIndex?: SelectDefaultTierIndexFn;
|
|
55
62
|
};
|
|
56
63
|
|
|
57
64
|
export const Paywall = ({
|
|
@@ -67,6 +74,7 @@ export const Paywall = ({
|
|
|
67
74
|
paywallLocale,
|
|
68
75
|
locale,
|
|
69
76
|
shouldHidePlan,
|
|
77
|
+
selectDefaultTierIndex,
|
|
70
78
|
}: PaywallProps) => {
|
|
71
79
|
const { stigg } = useStiggContext();
|
|
72
80
|
const discountRate = calculatePaywallDiscountRate(plans);
|
|
@@ -158,6 +166,7 @@ export const Paywall = ({
|
|
|
158
166
|
locale={locale}
|
|
159
167
|
customer={customer}
|
|
160
168
|
isCustomerInCustomPlan={isCustomerInCustomPlan}
|
|
169
|
+
selectDefaultTierIndex={selectDefaultTierIndex}
|
|
161
170
|
/>
|
|
162
171
|
))}
|
|
163
172
|
</PaywallPlansContainer>
|
|
@@ -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 { ShouldHidePlanFn, OnPlanSelectedCallbackFn } from './types';
|
|
5
|
+
import { ShouldHidePlanFn, OnPlanSelectedCallbackFn, SelectDefaultTierIndexFn } from './types';
|
|
6
6
|
import { getResolvedPaywallLocalize, PaywallLocalization } from './paywallTextOverrides';
|
|
7
7
|
import { DeepPartial } from '../../types';
|
|
8
8
|
import { PaywallLoader } from './PaywallLoader';
|
|
@@ -24,6 +24,7 @@ export type PaywallContainerProps = {
|
|
|
24
24
|
textOverrides?: DeepPartial<PaywallLocalization>;
|
|
25
25
|
billingCountryCode?: string;
|
|
26
26
|
shouldHidePlan?: ShouldHidePlanFn;
|
|
27
|
+
selectDefaultTierIndex?: SelectDefaultTierIndexFn;
|
|
27
28
|
};
|
|
28
29
|
|
|
29
30
|
export const PaywallContainer = ({
|
|
@@ -37,6 +38,7 @@ export const PaywallContainer = ({
|
|
|
37
38
|
onBillingPeriodChange,
|
|
38
39
|
billingCountryCode,
|
|
39
40
|
shouldHidePlan,
|
|
41
|
+
selectDefaultTierIndex,
|
|
40
42
|
}: PaywallContainerProps) => {
|
|
41
43
|
const hasCustomerPortalContext = useCheckContextExists(CustomerPortalContext);
|
|
42
44
|
let isCustomerPortalLoading = false;
|
|
@@ -89,6 +91,7 @@ export const PaywallContainer = ({
|
|
|
89
91
|
paywallLocale={paywallLocale}
|
|
90
92
|
locale={locale}
|
|
91
93
|
shouldHidePlan={shouldHidePlan}
|
|
94
|
+
selectDefaultTierIndex={selectDefaultTierIndex}
|
|
92
95
|
/>
|
|
93
96
|
);
|
|
94
97
|
|
|
@@ -12,7 +12,7 @@ import classNames from 'classnames';
|
|
|
12
12
|
import Grid from '@mui/material/Grid';
|
|
13
13
|
import { PlanEntitlements } from './PlanEntitlements';
|
|
14
14
|
import { PlanOfferingButton } from './PlanOfferingButton';
|
|
15
|
-
import { PaywallPlan, SubscribeIntentionType } from './types';
|
|
15
|
+
import { PaywallPlan, SelectDefaultTierIndexFn, SubscribeIntentionType } from './types';
|
|
16
16
|
import { PaywallLocalization } from './paywallTextOverrides';
|
|
17
17
|
import { flexLayoutMapper } from '../../theme/getResolvedTheme';
|
|
18
18
|
import { Typography } from '../common/Typography';
|
|
@@ -92,6 +92,7 @@ type PlanOfferingProps = {
|
|
|
92
92
|
locale: string;
|
|
93
93
|
withStartingAtRow: boolean;
|
|
94
94
|
isCustomerInCustomPlan: boolean;
|
|
95
|
+
selectDefaultTierIndex?: SelectDefaultTierIndexFn;
|
|
95
96
|
};
|
|
96
97
|
|
|
97
98
|
const NextPlanTagContainer = styled.div`
|
|
@@ -143,6 +144,7 @@ export function PlanOffering({
|
|
|
143
144
|
locale,
|
|
144
145
|
withStartingAtRow,
|
|
145
146
|
isCustomerInCustomPlan,
|
|
147
|
+
selectDefaultTierIndex,
|
|
146
148
|
}: PlanOfferingProps) {
|
|
147
149
|
const isNextPlan = plan.isNextPlan && plan.isNextPlan(billingPeriod);
|
|
148
150
|
const planPrices = plan.pricePoints.filter((pricePoint) => pricePoint.billingPeriod === billingPeriod);
|
|
@@ -166,7 +168,7 @@ export function PlanOffering({
|
|
|
166
168
|
}
|
|
167
169
|
|
|
168
170
|
const [selectedTierByFeature, setSelectedTierByFeature] = React.useState<Record<string, PriceTierFragment>>(
|
|
169
|
-
getSelectedTier(plan, billingPeriod, currentSubscription, {}),
|
|
171
|
+
getSelectedTier(plan, billingPeriod, currentSubscription, {}, selectDefaultTierIndex),
|
|
170
172
|
);
|
|
171
173
|
|
|
172
174
|
useEffect(() => {
|
|
@@ -1,5 +1,6 @@
|
|
|
1
1
|
import { BillingModel, TiersMode, BillingPeriod, Price, PriceTierFragment, Subscription } from '@stigg/js-client-sdk';
|
|
2
|
-
import { PaywallPlan } from '../paywall
|
|
2
|
+
import { PaywallPlan } from '../paywall';
|
|
3
|
+
import { SelectDefaultTierIndexFn } from '../paywall/types';
|
|
3
4
|
|
|
4
5
|
export function getPriceFeatureUnit(price: Price) {
|
|
5
6
|
if (!price.feature) {
|
|
@@ -49,6 +50,7 @@ export function getSelectedTier(
|
|
|
49
50
|
billingPeriod: BillingPeriod,
|
|
50
51
|
currentSubscription: Subscription | null,
|
|
51
52
|
selectedTierByFeature: Record<string, PriceTierFragment>,
|
|
53
|
+
selectDefaultTierIndex?: SelectDefaultTierIndexFn,
|
|
52
54
|
): Record<string, PriceTierFragment> {
|
|
53
55
|
const planTierPrices = plan.pricePoints.filter(
|
|
54
56
|
(price) => price.billingPeriod === billingPeriod && price.isTieredPrice,
|
|
@@ -57,8 +59,8 @@ export function getSelectedTier(
|
|
|
57
59
|
if (planTierPrices.length === 1) {
|
|
58
60
|
const [price] = planTierPrices;
|
|
59
61
|
const { featureId } = price.feature!;
|
|
60
|
-
|
|
61
|
-
let currentTier = price.tiers![
|
|
62
|
+
const selectedDefaultTierIndex = selectDefaultTierIndex ? selectDefaultTierIndex({ plan }) : 0;
|
|
63
|
+
let currentTier = price.tiers![selectedDefaultTierIndex];
|
|
62
64
|
|
|
63
65
|
if (selectedTierByFeature[featureId]) {
|
|
64
66
|
currentTier = price.tiers?.find((tier) => tier.upTo === selectedTierByFeature[featureId].upTo) || currentTier;
|