@stigg/react-sdk 4.4.0-beta.1 → 4.4.0-beta.3
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/checkout/CheckoutProvider.d.ts +1 -1
- package/dist/components/checkout/hooks/useProgressBarModel.d.ts +1 -0
- package/dist/components/checkout/index.d.ts +1 -0
- package/dist/components/customerPortal/subscriptionOverview/subscriptionView/SubscriptionView.style.d.ts +1 -1
- package/dist/react-sdk.cjs.development.js +19 -16
- 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 +19 -16
- package/dist/react-sdk.esm.js.map +1 -1
- package/package.json +1 -1
- package/src/components/checkout/Checkout.tsx +1 -2
- package/src/components/checkout/CheckoutContainer.tsx +9 -9
- package/src/components/checkout/CheckoutProvider.tsx +10 -14
- package/src/components/checkout/hooks/usePreviewSubscription.ts +1 -2
- package/src/components/checkout/hooks/useProgressBarModel.ts +3 -0
- package/src/components/checkout/index.ts +1 -0
- package/src/stories/Checkout.stories.tsx +1 -1
package/package.json
CHANGED
|
@@ -22,8 +22,7 @@ export const Checkout = ({
|
|
|
22
22
|
planId={planId}
|
|
23
23
|
preferredBillingPeriod={preferredBillingPeriod}
|
|
24
24
|
billingCountryCode={billingCountryCode}
|
|
25
|
-
billableFeatures={billableFeatures}
|
|
26
|
-
>
|
|
25
|
+
billableFeatures={billableFeatures}>
|
|
27
26
|
<CheckoutContainer {...containerProps} />
|
|
28
27
|
</CheckoutProvider>
|
|
29
28
|
);
|
|
@@ -4,7 +4,7 @@ import { ApplySubscription, CheckoutStatePlan } from '@stigg/js-client-sdk';
|
|
|
4
4
|
import { CheckoutContent, CheckoutLayout, CheckoutPanel } from './CheckoutContainer.style';
|
|
5
5
|
import { CheckoutProgressBar } from './progressBar/CheckoutProgressBar';
|
|
6
6
|
import { CheckoutSummary, CheckoutSummarySkeleton } from './summary';
|
|
7
|
-
import { useProgressBarModel } from './hooks';
|
|
7
|
+
import { CheckoutStep, CheckoutStepKey, useProgressBarModel } from './hooks';
|
|
8
8
|
import { PlanHeader } from './planHeader';
|
|
9
9
|
import { CheckoutAddonsStep } from './steps/addons';
|
|
10
10
|
import { PaymentStep } from './steps/payment';
|
|
@@ -20,13 +20,13 @@ type StepProps = {
|
|
|
20
20
|
content: React.ReactNode;
|
|
21
21
|
};
|
|
22
22
|
|
|
23
|
-
const getStepProps = (
|
|
24
|
-
switch (
|
|
25
|
-
case
|
|
23
|
+
const getStepProps = (currentStep: CheckoutStep): StepProps => {
|
|
24
|
+
switch (currentStep.key) {
|
|
25
|
+
case CheckoutStepKey.PLAN:
|
|
26
26
|
return { allowChangePlan: true, content: <CheckoutPlanStep /> };
|
|
27
|
-
case
|
|
27
|
+
case CheckoutStepKey.ADDONS:
|
|
28
28
|
return { content: <CheckoutAddonsStep /> };
|
|
29
|
-
case
|
|
29
|
+
case CheckoutStepKey.PAYMENT:
|
|
30
30
|
return { content: <PaymentStep /> };
|
|
31
31
|
default:
|
|
32
32
|
return { content: null };
|
|
@@ -48,8 +48,8 @@ export type CheckoutContainerProps = {
|
|
|
48
48
|
export function CheckoutContainer({ onCheckout, onCheckoutCompleted, onChangePlan }: CheckoutContainerProps) {
|
|
49
49
|
const { stripePromise, setupIntentClientSecret } = useStripeIntegration();
|
|
50
50
|
const [{ stiggTheme, widgetState }] = useCheckoutContext();
|
|
51
|
-
const {
|
|
52
|
-
|
|
51
|
+
const { currentStep } = useProgressBarModel();
|
|
52
|
+
|
|
53
53
|
const { isLoadingCheckoutData } = widgetState;
|
|
54
54
|
|
|
55
55
|
// uncomment for fun!
|
|
@@ -57,7 +57,7 @@ export function CheckoutContainer({ onCheckout, onCheckoutCompleted, onChangePla
|
|
|
57
57
|
// return <SurpriseStep />;
|
|
58
58
|
// }
|
|
59
59
|
|
|
60
|
-
const { content, allowChangePlan } = getStepProps(
|
|
60
|
+
const { content, allowChangePlan } = getStepProps(currentStep);
|
|
61
61
|
|
|
62
62
|
const checkoutContent = (
|
|
63
63
|
<>
|
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import { produce } from 'immer';
|
|
2
|
-
import React, { useCallback, useContext, useMemo, useState } from 'react';
|
|
2
|
+
import React, { useCallback, useContext, useEffect, useMemo, useState } from 'react';
|
|
3
3
|
|
|
4
4
|
import { BillableFeature, BillingPeriod, GetCheckoutStateResults } from '@stigg/js-client-sdk';
|
|
5
5
|
|
|
@@ -58,12 +58,16 @@ const CheckoutContextProvider: React.FC<{ children: React.ReactNode; initialStat
|
|
|
58
58
|
}) => {
|
|
59
59
|
const [state, innerSetState] = useState(initialState);
|
|
60
60
|
|
|
61
|
+
useEffect(() => {
|
|
62
|
+
innerSetState(initialState);
|
|
63
|
+
}, [initialState]);
|
|
64
|
+
|
|
61
65
|
const setState = useCallback(
|
|
62
66
|
(updater: (state: CheckoutContextState) => void) => innerSetState((old) => produce(old, (draft) => updater(draft))),
|
|
63
67
|
[innerSetState],
|
|
64
68
|
);
|
|
65
69
|
|
|
66
|
-
const [contextValue, setContextValue] = useMemo(() => [state, setState], [state]);
|
|
70
|
+
const [contextValue, setContextValue] = useMemo(() => [state, setState], [setState, state]);
|
|
67
71
|
|
|
68
72
|
return <CheckoutContext.Provider value={[contextValue, setContextValue]}>{children}</CheckoutContext.Provider>;
|
|
69
73
|
};
|
|
@@ -82,11 +86,11 @@ export function CheckoutProvider({
|
|
|
82
86
|
children,
|
|
83
87
|
textOverrides,
|
|
84
88
|
theme,
|
|
89
|
+
preferredBillingPeriod,
|
|
90
|
+
billableFeatures,
|
|
85
91
|
resourceId,
|
|
86
92
|
planId,
|
|
87
|
-
preferredBillingPeriod,
|
|
88
93
|
billingCountryCode,
|
|
89
|
-
billableFeatures,
|
|
90
94
|
}: {
|
|
91
95
|
children: React.ReactNode;
|
|
92
96
|
} & CheckoutProviderProps) {
|
|
@@ -130,16 +134,8 @@ export function CheckoutProvider({
|
|
|
130
134
|
};
|
|
131
135
|
|
|
132
136
|
return initialState;
|
|
133
|
-
|
|
134
|
-
|
|
135
|
-
textOverrides,
|
|
136
|
-
preferredBillingPeriod,
|
|
137
|
-
billingCountryCode,
|
|
138
|
-
billableFeatures,
|
|
139
|
-
globalTheme,
|
|
140
|
-
checkout,
|
|
141
|
-
isLoading,
|
|
142
|
-
]);
|
|
137
|
+
// eslint-disable-next-line react-hooks/exhaustive-deps
|
|
138
|
+
}, [preferredBillingPeriod, billingCountryCode, checkout, isLoading]);
|
|
143
139
|
|
|
144
140
|
return (
|
|
145
141
|
<SdkThemeProvider key={checkout?.plan.id} componentTheme={configuration}>
|
|
@@ -10,7 +10,7 @@ export const usePreviewSubscriptionAction = () => {
|
|
|
10
10
|
const subscription = useSubscriptionModel();
|
|
11
11
|
const [{ resourceId, planStep }] = useCheckoutContext();
|
|
12
12
|
const { checkoutState } = useCheckoutModel();
|
|
13
|
-
const { plan,
|
|
13
|
+
const { plan, customer } = checkoutState || {};
|
|
14
14
|
|
|
15
15
|
const previewSubscriptionAction = useCallback(
|
|
16
16
|
async ({ promotionCode }: { promotionCode?: string | null } = {}) => {
|
|
@@ -43,7 +43,6 @@ export const usePreviewSubscriptionAction = () => {
|
|
|
43
43
|
return { subscriptionPreview, errorMessage };
|
|
44
44
|
},
|
|
45
45
|
[
|
|
46
|
-
activeSubscription,
|
|
47
46
|
customer,
|
|
48
47
|
plan,
|
|
49
48
|
resourceId,
|
|
@@ -78,7 +78,10 @@ function useGoNext() {
|
|
|
78
78
|
|
|
79
79
|
export function useProgressBarModel() {
|
|
80
80
|
const progressBarState = useProgressBarState();
|
|
81
|
+
const currentStep = progressBarState.steps[progressBarState.activeStep];
|
|
82
|
+
|
|
81
83
|
return {
|
|
84
|
+
currentStep,
|
|
82
85
|
progressBarState,
|
|
83
86
|
isLastStep: progressBarState.activeStep === progressBarState.steps.length - 1,
|
|
84
87
|
isCheckoutComplete: isCheckoutComplete(progressBarState),
|
|
@@ -46,7 +46,7 @@ const Template: ComponentStory<any> = (args) => (
|
|
|
46
46
|
onChangePlan={({ currentPlan }) => {
|
|
47
47
|
console.log('plan changed clicked!', { currentPlan });
|
|
48
48
|
}}
|
|
49
|
-
billingInformation={{ taxPercentage: 27 }}
|
|
49
|
+
// billingInformation={{ taxPercentage: 27 }}
|
|
50
50
|
/>
|
|
51
51
|
</Wrapper>
|
|
52
52
|
);
|