@stigg/react-sdk 5.6.0 → 5.8.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/checkout/summary/components/LineItems.d.ts +0 -5
- package/dist/components/checkout/summary/components/getPriceBreakdownString.d.ts +5 -0
- package/dist/components/utils/onWheelBlur.d.ts +2 -0
- package/dist/components/utils/priceTierUtils.d.ts +1 -0
- package/dist/react-sdk.cjs.development.js +97 -81
- 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 +99 -83
- package/dist/react-sdk.esm.js.map +1 -1
- package/package.json +1 -1
- package/src/components/checkout/steps/addons/CheckoutAddonsStep.tsx +2 -0
- package/src/components/checkout/steps/plan/CheckoutChargeList.tsx +2 -1
- package/src/components/checkout/summary/components/LineItems.tsx +4 -47
- package/src/components/checkout/summary/components/getPriceBreakdownString.ts +45 -0
- package/src/components/common/VolumePerUnitInput.tsx +2 -0
- package/src/components/utils/onWheelBlur.ts +3 -0
- package/src/components/utils/priceTierUtils.ts +4 -0
package/package.json
CHANGED
|
@@ -12,6 +12,7 @@ import { usePlanStepModel } from '../../hooks/usePlanStepModel';
|
|
|
12
12
|
import { AddonListItemContainer, CheckoutAddonsContainer, TrashButton } from './CheckoutAddonsStep.style';
|
|
13
13
|
import { CheckoutLocalization } from '../../configurations/textOverrides';
|
|
14
14
|
import { useCheckoutModel, useProgressBarModel } from '../../hooks';
|
|
15
|
+
import { ON_WHEEL_BLUR } from '../../../utils/onWheelBlur';
|
|
15
16
|
|
|
16
17
|
type UseAddonsStepModel = ReturnType<typeof useAddonsStepModel>;
|
|
17
18
|
|
|
@@ -96,6 +97,7 @@ function AddonListItem({
|
|
|
96
97
|
<InputField
|
|
97
98
|
id={`${addon.id}-input`}
|
|
98
99
|
type="number"
|
|
100
|
+
onWheel={ON_WHEEL_BLUR}
|
|
99
101
|
sx={{ width: 120, marginX: 2 }}
|
|
100
102
|
value={addonState?.quantity ?? ''}
|
|
101
103
|
error={!isValid}
|
|
@@ -14,6 +14,7 @@ import { useCheckoutModel, usePlanStepModel, useProgressBarModel } from '../../h
|
|
|
14
14
|
import { TiersSelectContainer } from '../../../common/TiersSelectContainer';
|
|
15
15
|
import { getValidPriceQuantity } from '../../../utils/priceUtils';
|
|
16
16
|
import { getFeatureDisplayNameText } from '../../../utils/getFeatureName';
|
|
17
|
+
import { ON_WHEEL_BLUR } from '../../../utils/onWheelBlur';
|
|
17
18
|
|
|
18
19
|
export type UsePlanStepModel = ReturnType<typeof usePlanStepModel>;
|
|
19
20
|
|
|
@@ -122,12 +123,12 @@ export function PlanCharge({
|
|
|
122
123
|
sx={{ width: 120 }}
|
|
123
124
|
id={`${featureId}-input`}
|
|
124
125
|
type="number"
|
|
126
|
+
onWheel={ON_WHEEL_BLUR}
|
|
125
127
|
error={!isValid}
|
|
126
128
|
helperText={!isValid ? getValidationText(charge, billableFeature?.quantity) : undefined}
|
|
127
129
|
FormHelperTextProps={{ sx: { margin: '4px' } }}
|
|
128
130
|
value={billableFeature?.quantity ?? ''}
|
|
129
131
|
onChange={handleQuantityChange}
|
|
130
|
-
onWheel={(e: React.WheelEvent<HTMLInputElement>) => (e.target as HTMLElement).blur()}
|
|
131
132
|
/>
|
|
132
133
|
);
|
|
133
134
|
}
|
|
@@ -1,25 +1,19 @@
|
|
|
1
1
|
import React from 'react';
|
|
2
2
|
import styled from '@emotion/styled/macro';
|
|
3
3
|
import Grid from '@mui/material/Grid';
|
|
4
|
-
import {
|
|
5
|
-
BillingModel,
|
|
6
|
-
BillingPeriod,
|
|
7
|
-
Price,
|
|
8
|
-
SubscriptionPreviewInvoice,
|
|
9
|
-
SubscriptionPreviewV2,
|
|
10
|
-
} from '@stigg/js-client-sdk';
|
|
4
|
+
import { BillingModel, Price, SubscriptionPreviewInvoice, SubscriptionPreviewV2 } from '@stigg/js-client-sdk';
|
|
11
5
|
import { Typography } from '../../../common/Typography';
|
|
12
6
|
import { currencyPriceFormatter } from '../../../utils/currencyUtils';
|
|
13
|
-
import { calculateTierPrice } from '../../../utils/priceTierUtils';
|
|
14
7
|
import { WithSkeleton } from './WithSkeleton';
|
|
15
8
|
import { Skeleton } from '../../components/Skeletons.style';
|
|
16
9
|
import { CheckoutLocalization } from '../../configurations/textOverrides';
|
|
17
10
|
import { Icon } from '../../../common/Icon';
|
|
18
11
|
import { InformationTooltip } from '../../../common/InformationTooltip';
|
|
12
|
+
import { getPriceBreakdownString } from './getPriceBreakdownString';
|
|
19
13
|
|
|
20
14
|
export const LineItemContainer = styled.div`
|
|
21
15
|
& + & {
|
|
22
|
-
margin-top:
|
|
16
|
+
margin-top: 16px;
|
|
23
17
|
}
|
|
24
18
|
`;
|
|
25
19
|
|
|
@@ -29,26 +23,6 @@ export const LineItemRow = styled.div`
|
|
|
29
23
|
justify-content: space-between;
|
|
30
24
|
`;
|
|
31
25
|
|
|
32
|
-
export const getPriceString = ({ amount, price, quantity }: { amount: number; price: Price; quantity: number }) => {
|
|
33
|
-
const { billingPeriod } = price;
|
|
34
|
-
let billingPeriodString = null;
|
|
35
|
-
|
|
36
|
-
if (quantity) {
|
|
37
|
-
amount /= quantity;
|
|
38
|
-
}
|
|
39
|
-
|
|
40
|
-
if (billingPeriod === BillingPeriod.Annually) {
|
|
41
|
-
amount /= 12;
|
|
42
|
-
billingPeriodString = '12 months';
|
|
43
|
-
}
|
|
44
|
-
|
|
45
|
-
const addonPriceFormat = currencyPriceFormatter({ amount, currency: price.currency, minimumFractionDigits: 2 });
|
|
46
|
-
|
|
47
|
-
return `${quantity > 1 ? `${quantity} x ${addonPriceFormat} each` : addonPriceFormat}${
|
|
48
|
-
billingPeriodString ? ` x ${billingPeriodString}` : ''
|
|
49
|
-
}`;
|
|
50
|
-
};
|
|
51
|
-
|
|
52
26
|
const PayAsYouGoPriceTooltip = ({ checkoutLocalization }: { checkoutLocalization: CheckoutLocalization }) => {
|
|
53
27
|
const title = <Typography variant="body1">{checkoutLocalization.summary.payAsYouGoTooltipText}</Typography>;
|
|
54
28
|
return (
|
|
@@ -69,16 +43,8 @@ export const BilledPriceLineItem = ({
|
|
|
69
43
|
quantity: number;
|
|
70
44
|
price: Price;
|
|
71
45
|
}) => {
|
|
72
|
-
const { billingPeriod } = price;
|
|
73
46
|
const isPayAsYouGo = price.pricingModel === BillingModel.UsageBased;
|
|
74
47
|
|
|
75
|
-
let amount;
|
|
76
|
-
if (price.isTieredPrice) {
|
|
77
|
-
amount = calculateTierPrice(price, quantity);
|
|
78
|
-
} else {
|
|
79
|
-
amount = price.amount! * quantity;
|
|
80
|
-
}
|
|
81
|
-
|
|
82
48
|
return (
|
|
83
49
|
<LineItemContainer>
|
|
84
50
|
<LineItemRow style={{ alignItems: 'flex-start' }}>
|
|
@@ -86,20 +52,11 @@ export const BilledPriceLineItem = ({
|
|
|
86
52
|
<Typography variant="body1" color="secondary">
|
|
87
53
|
{label}
|
|
88
54
|
</Typography>
|
|
89
|
-
{(quantity > 1 || billingPeriod === BillingPeriod.Annually) && (
|
|
90
|
-
<Typography variant="body1" color="secondary">
|
|
91
|
-
{getPriceString({ amount, price, quantity })}
|
|
92
|
-
</Typography>
|
|
93
|
-
)}
|
|
94
55
|
</Grid>
|
|
95
56
|
<Grid item display="flex" gap={1} alignItems="center">
|
|
96
57
|
{isPayAsYouGo && <PayAsYouGoPriceTooltip checkoutLocalization={checkoutLocalization} />}
|
|
97
58
|
<Typography variant="body1" color="secondary" style={{ wordBreak: 'break-word' }}>
|
|
98
|
-
{
|
|
99
|
-
amount,
|
|
100
|
-
currency: price.currency,
|
|
101
|
-
minimumFractionDigits: 2,
|
|
102
|
-
})}
|
|
59
|
+
{getPriceBreakdownString({ price, quantity })}
|
|
103
60
|
{isPayAsYouGo && ' / unit'}
|
|
104
61
|
</Typography>
|
|
105
62
|
</Grid>
|
|
@@ -0,0 +1,45 @@
|
|
|
1
|
+
import { BillingModel, BillingPeriod, Price, TiersMode } from '@stigg/js-client-sdk';
|
|
2
|
+
import { currencyPriceFormatter } from '../../../utils/currencyUtils';
|
|
3
|
+
import { calculateTierPrice, isBulkTiers } from '../../../utils/priceTierUtils';
|
|
4
|
+
|
|
5
|
+
function formatPricePerUnit({ price, quantity, totalAmount }: { price: Price; quantity: number; totalAmount: number }) {
|
|
6
|
+
const { currency, pricingModel, billingPeriod } = price;
|
|
7
|
+
const isPerUnit = pricingModel === BillingModel.PerUnit;
|
|
8
|
+
const featureUnits = quantity && (isPerUnit || quantity > 1) ? `${new Intl.NumberFormat().format(quantity)} x ` : '';
|
|
9
|
+
const billingPeriodString = billingPeriod === BillingPeriod.Annually ? ' x 12 months' : '';
|
|
10
|
+
|
|
11
|
+
const unitPrice = totalAmount / quantity / (billingPeriod === BillingPeriod.Annually ? 12 : 1);
|
|
12
|
+
const formattedUnitPrice = currencyPriceFormatter({
|
|
13
|
+
amount: unitPrice,
|
|
14
|
+
currency,
|
|
15
|
+
minimumFractionDigits: 2,
|
|
16
|
+
});
|
|
17
|
+
const formattedTotalPrice = currencyPriceFormatter({
|
|
18
|
+
amount: totalAmount,
|
|
19
|
+
currency,
|
|
20
|
+
minimumFractionDigits: 2,
|
|
21
|
+
});
|
|
22
|
+
|
|
23
|
+
return `${featureUnits}${formattedUnitPrice}${billingPeriodString} ${
|
|
24
|
+
billingPeriodString || featureUnits ? ` = ${formattedTotalPrice}` : ''
|
|
25
|
+
}`;
|
|
26
|
+
}
|
|
27
|
+
|
|
28
|
+
export function getPriceBreakdownString({ price, quantity }: { price: Price; quantity: number }) {
|
|
29
|
+
const amount = price.isTieredPrice ? calculateTierPrice(price, quantity) : (price.amount || 0) * quantity;
|
|
30
|
+
|
|
31
|
+
if (isBulkTiers(price.tiers) || price.tiersMode === TiersMode.Graduated) {
|
|
32
|
+
const formattedTotalPrice = currencyPriceFormatter({
|
|
33
|
+
amount,
|
|
34
|
+
currency: price.currency,
|
|
35
|
+
minimumFractionDigits: 2,
|
|
36
|
+
});
|
|
37
|
+
return `${quantity} for ${formattedTotalPrice}`;
|
|
38
|
+
}
|
|
39
|
+
|
|
40
|
+
return formatPricePerUnit({
|
|
41
|
+
price,
|
|
42
|
+
quantity,
|
|
43
|
+
totalAmount: amount,
|
|
44
|
+
});
|
|
45
|
+
}
|
|
@@ -3,6 +3,7 @@ import React from 'react';
|
|
|
3
3
|
import { Typography } from './Typography';
|
|
4
4
|
import { InputField } from '../checkout/components';
|
|
5
5
|
import { TiersSelectContainerProps } from './TiersSelectContainer';
|
|
6
|
+
import { ON_WHEEL_BLUR } from '../utils/onWheelBlur';
|
|
6
7
|
|
|
7
8
|
export function VolumePerUnitInput({
|
|
8
9
|
width,
|
|
@@ -15,6 +16,7 @@ export function VolumePerUnitInput({
|
|
|
15
16
|
return (
|
|
16
17
|
<InputField
|
|
17
18
|
type="number"
|
|
19
|
+
onWheel={ON_WHEEL_BLUR}
|
|
18
20
|
fullWidth
|
|
19
21
|
sx={{ minHeight: '46px', width }}
|
|
20
22
|
InputProps={{
|
|
@@ -123,6 +123,10 @@ export function hasTierWithUnitPrice(tiers: PriceTierFragment[] | null | undefin
|
|
|
123
123
|
return tiers?.some(({ unitPrice, upTo }) => unitPrice && !isNil(upTo));
|
|
124
124
|
}
|
|
125
125
|
|
|
126
|
+
export function isBulkTiers(tiers: PriceTierFragment[] | null | undefined) {
|
|
127
|
+
return tiers?.every(({ unitPrice, upTo }) => !unitPrice || isNil(upTo));
|
|
128
|
+
}
|
|
129
|
+
|
|
126
130
|
export function getTiersPerUnitQuantities(
|
|
127
131
|
plan: PaywallPlan,
|
|
128
132
|
billingPeriod: BillingPeriod,
|