@stigg/react-sdk 4.4.4 → 4.4.6

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.
Files changed (44) hide show
  1. package/dist/components/checkout/CheckoutProvider.d.ts +2 -2
  2. package/dist/components/checkout/components/ChangePlanButton.d.ts +1 -1
  3. package/dist/components/checkout/components/DowngradeToFreeContainer.d.ts +1 -1
  4. package/dist/components/checkout/{textOverrides.d.ts → configurations/textOverrides.d.ts} +1 -1
  5. package/dist/components/checkout/{theme.d.ts → configurations/theme.d.ts} +2 -2
  6. package/dist/components/checkout/configurations/typography.d.ts +2 -0
  7. package/dist/components/checkout/index.d.ts +2 -2
  8. package/dist/components/checkout/promotionCode/AddPromotionCodeButton.d.ts +1 -1
  9. package/dist/components/checkout/promotionCode/PromotionCodeSection.d.ts +1 -1
  10. package/dist/components/checkout/steps/payment/PaymentMethods.d.ts +1 -1
  11. package/dist/components/checkout/steps/plan/BillingPeriodPicker.d.ts +1 -1
  12. package/dist/components/checkout/summary/CheckoutSuccess.d.ts +1 -1
  13. package/dist/components/checkout/summary/components/CheckoutCaptions.d.ts +1 -1
  14. package/dist/components/checkout/summary/components/LineItems.d.ts +1 -1
  15. package/dist/components/common/TiersSelectContainer.d.ts +2 -1
  16. package/dist/components/common/mapExternalTheme.d.ts +2 -1
  17. package/dist/components/paywall/PlanPrice.d.ts +2 -2
  18. package/dist/react-sdk.cjs.development.js +70 -51
  19. package/dist/react-sdk.cjs.development.js.map +1 -1
  20. package/dist/react-sdk.cjs.production.min.js +1 -1
  21. package/dist/react-sdk.cjs.production.min.js.map +1 -1
  22. package/dist/react-sdk.esm.js +70 -51
  23. package/dist/react-sdk.esm.js.map +1 -1
  24. package/package.json +1 -1
  25. package/src/components/checkout/CheckoutProvider.tsx +6 -5
  26. package/src/components/checkout/components/ChangePlanButton.tsx +4 -4
  27. package/src/components/checkout/components/DowngradeToFreeContainer.tsx +1 -1
  28. package/src/components/checkout/{textOverrides.ts → configurations/textOverrides.ts} +2 -2
  29. package/src/components/checkout/{theme.ts → configurations/theme.ts} +2 -2
  30. package/src/components/checkout/configurations/typography.ts +20 -0
  31. package/src/components/checkout/index.ts +2 -2
  32. package/src/components/checkout/planHeader/PlanHeader.tsx +1 -3
  33. package/src/components/checkout/promotionCode/AddPromotionCodeButton.tsx +3 -2
  34. package/src/components/checkout/promotionCode/PromotionCodeSection.tsx +1 -1
  35. package/src/components/checkout/steps/addons/CheckoutAddonsStep.tsx +1 -1
  36. package/src/components/checkout/steps/payment/PaymentMethods.tsx +1 -1
  37. package/src/components/checkout/steps/plan/BillingPeriodPicker.tsx +2 -2
  38. package/src/components/checkout/summary/CheckoutSuccess.tsx +1 -1
  39. package/src/components/checkout/summary/CheckoutSummary.tsx +10 -6
  40. package/src/components/checkout/summary/components/CheckoutCaptions.tsx +2 -2
  41. package/src/components/checkout/summary/components/LineItems.tsx +1 -1
  42. package/src/components/common/TiersSelectContainer.tsx +3 -1
  43. package/src/components/common/mapExternalTheme.ts +14 -10
  44. package/src/components/paywall/PlanPrice.tsx +12 -17
package/package.json CHANGED
@@ -1,5 +1,5 @@
1
1
  {
2
- "version": "4.4.4",
2
+ "version": "4.4.6",
3
3
  "license": "MIT",
4
4
  "main": "dist/index.js",
5
5
  "typings": "dist/index.d.ts",
@@ -3,7 +3,7 @@ import React, { useCallback, useContext, useEffect, useMemo, useState } from 're
3
3
  import { BillableFeature, BillingPeriod, GetCheckoutStateResults } from '@stigg/js-client-sdk';
4
4
  import { CustomizedTheme, SdkThemeProvider, useStiggTheme } from '../../theme/Theme';
5
5
  import { DeepPartial } from '../../types';
6
- import { mapCheckoutConfiguration } from '../common/mapExternalTheme';
6
+ import { mapCheckoutConfiguration, mapTypography } from '../common/mapExternalTheme';
7
7
  import {
8
8
  AddonsStepState,
9
9
  getAddonsStepInitialState,
@@ -16,10 +16,11 @@ import {
16
16
  useLoadCheckout,
17
17
  WidgetState,
18
18
  } from './hooks';
19
- import { CheckoutLocalization, getResolvedCheckoutLocalize } from './textOverrides';
20
- import { CheckoutTheme, getResolvedCheckoutTheme } from './theme';
19
+ import { CheckoutLocalization, getResolvedCheckoutLocalize } from './configurations/textOverrides';
20
+ import { CheckoutTheme, getResolvedCheckoutTheme } from './configurations/theme';
21
21
  import { StiggTheme } from '../../theme/types';
22
22
  import { BillingInformation, MockCheckoutStateCallback } from './types';
23
+ import { defaultCheckoutTypography } from './configurations/typography';
23
24
 
24
25
  export interface CheckoutContextState {
25
26
  checkout?: GetCheckoutStateResults | null;
@@ -98,9 +99,9 @@ export function CheckoutProvider({
98
99
  children: React.ReactNode;
99
100
  } & CheckoutProviderProps) {
100
101
  const { checkout, isLoading } = useLoadCheckout({ resourceId, planId, billingCountryCode, onMockCheckoutState });
101
- const configuration: CustomizedTheme | undefined = checkout?.configuration
102
+ const configuration: CustomizedTheme = checkout?.configuration
102
103
  ? mapCheckoutConfiguration(checkout.configuration)
103
- : undefined;
104
+ : { typography: mapTypography(defaultCheckoutTypography) };
104
105
  const globalTheme: StiggTheme = useStiggTheme(configuration);
105
106
 
106
107
  const initialState = useMemo(() => {
@@ -1,8 +1,8 @@
1
- import { Button } from '@mui/material';
2
- import { Typography } from '../../common/Typography';
3
1
  import React from 'react';
4
- import { CheckoutLocalization } from '../textOverrides';
5
2
  import { ButtonProps } from '@mui/material/Button';
3
+ import { Button } from '@mui/material';
4
+ import { Typography } from '../../common/Typography';
5
+ import { CheckoutLocalization } from '../configurations/textOverrides';
6
6
 
7
7
  export const ChangePlanButton = ({
8
8
  onClick,
@@ -23,7 +23,7 @@ export const ChangePlanButton = ({
23
23
  <Typography
24
24
  className="stigg-checkout-change-plan-button-text"
25
25
  color="primary.main"
26
- variant="body1"
26
+ variant="h3"
27
27
  style={{ lineHeight: '24px' }}>
28
28
  {checkoutLocalization.changePlan}
29
29
  </Typography>
@@ -4,7 +4,7 @@ import { Alert, Box } from '@mui/material';
4
4
  import { CheckoutStatePlan, Subscription } from '@stigg/js-client-sdk';
5
5
  import { StyledArrowRightIcon } from './StyledArrow';
6
6
  import { Typography } from '../../common/Typography';
7
- import { CheckoutLocalization } from '../textOverrides';
7
+ import { CheckoutLocalization } from '../configurations/textOverrides';
8
8
  import { CheckoutContainerProps } from '../CheckoutContainer';
9
9
  import { ChangePlanButton } from './ChangePlanButton';
10
10
 
@@ -8,8 +8,8 @@ import {
8
8
  } from '@stigg/js-client-sdk';
9
9
  import moment from 'moment';
10
10
  import merge from 'lodash/merge';
11
- import { DeepPartial } from '../../types';
12
- import { currencyPriceFormatter } from '../utils/currencyUtils';
11
+ import { DeepPartial } from '../../../types';
12
+ import { currencyPriceFormatter } from '../../utils/currencyUtils';
13
13
 
14
14
  export type CheckoutLocalization = {
15
15
  changePlan: string;
@@ -1,6 +1,6 @@
1
1
  import { CheckoutConfiguration } from '@stigg/js-client-sdk';
2
- import { StiggTheme } from '../../theme/types';
3
- import { DeepPartial } from '../../types';
2
+ import { StiggTheme } from '../../../theme/types';
3
+ import { DeepPartial } from '../../../types';
4
4
 
5
5
  export type CheckoutTheme = {
6
6
  primary: string;
@@ -0,0 +1,20 @@
1
+ import { FontWeight, TypographyConfiguration } from '@stigg/js-client-sdk';
2
+
3
+ export const defaultCheckoutTypography: TypographyConfiguration = {
4
+ h1: {
5
+ fontSize: 24,
6
+ fontWeight: FontWeight.Bold,
7
+ },
8
+ h2: {
9
+ fontSize: 16,
10
+ fontWeight: FontWeight.Normal,
11
+ },
12
+ h3: {
13
+ fontSize: 16,
14
+ fontWeight: FontWeight.Normal,
15
+ },
16
+ body: {
17
+ fontSize: 14,
18
+ fontWeight: FontWeight.Normal,
19
+ },
20
+ };
@@ -1,4 +1,4 @@
1
- export { CheckoutTheme } from './theme';
1
+ export { CheckoutTheme } from './configurations/theme';
2
2
  export {
3
3
  OnCheckoutCompletedParams,
4
4
  OnCheckoutParams,
@@ -6,6 +6,6 @@ export {
6
6
  CheckoutContainerProps,
7
7
  } from './CheckoutContainer';
8
8
  export { CheckoutProviderProps } from './CheckoutProvider';
9
- export { CheckoutLocalization } from './textOverrides';
9
+ export { CheckoutLocalization } from './configurations/textOverrides';
10
10
  export { Checkout, CheckoutProps } from './Checkout';
11
11
  export * from './types';
@@ -23,9 +23,7 @@ export function PlanHeader({ allowChangePlan = false, onChangePlan }: PlanHeader
23
23
  </Typography>
24
24
 
25
25
  <Box sx={{ display: 'flex', justifyContent: 'space-between' }}>
26
- <Typography variant="h3" bold>
27
- {plan?.displayName}
28
- </Typography>
26
+ <Typography variant="h1">{plan?.displayName}</Typography>
29
27
 
30
28
  {allowChangePlan && onChangePlan && (
31
29
  <ChangePlanButton
@@ -4,9 +4,10 @@ import styled from '@emotion/styled/macro';
4
4
  import PlusIcon from '../../../assets/plus-icon.svg';
5
5
  import { Typography } from '../../common/Typography';
6
6
  import { Button } from '../components';
7
- import { CheckoutLocalization } from '../textOverrides';
7
+ import { CheckoutLocalization } from '../configurations/textOverrides';
8
8
 
9
9
  const StyledPlusIcon = styled(PlusIcon, { shouldForwardProp: (prop) => !prop.startsWith('$') })<{ $disabled: boolean }>`
10
+ margin-right: 8px;
10
11
  path {
11
12
  stroke: ${({ theme, $disabled }) => ($disabled ? theme.stigg.palette.text.disabled : theme.stigg.palette.primary)};
12
13
  }
@@ -36,7 +37,7 @@ export const AddPromotionCodeButton = ({ onAddClick, checkoutLocalization, disab
36
37
  className="stigg-checkout-change-plan-button-text"
37
38
  color={disabled ? 'disabled' : 'primary.main'}
38
39
  style={{ lineHeight: '24px' }}
39
- variant="body1">
40
+ variant="h3">
40
41
  {checkoutLocalization.summary.addCouponCodeText}
41
42
  </Typography>
42
43
  </Button>
@@ -3,7 +3,7 @@ import styled from '@emotion/styled/macro';
3
3
  import { usePromotionCodeModel } from '../hooks/useCouponModel';
4
4
  import { AddPromotionCode } from './AddPromotionCode';
5
5
  import { AppliedPromotionCode } from './AppliedPromotionCode';
6
- import { CheckoutLocalization } from '../textOverrides';
6
+ import { CheckoutLocalization } from '../configurations/textOverrides';
7
7
  import { MockCheckoutPreviewCallback } from '../types';
8
8
 
9
9
  const PromotionCodeSectionContainer = styled.div`
@@ -10,7 +10,7 @@ import { Button, InputField } from '../../components';
10
10
  import { useAddonsStepModel } from '../../hooks/useAddonsStepModel';
11
11
  import { usePlanStepModel } from '../../hooks/usePlanStepModel';
12
12
  import { AddonListItemContainer, CheckoutAddonsContainer, TrashButton } from './CheckoutAddonsStep.style';
13
- import { CheckoutLocalization } from '../../textOverrides';
13
+ import { CheckoutLocalization } from '../../configurations/textOverrides';
14
14
  import { useCheckoutModel, useProgressBarModel } from '../../hooks';
15
15
 
16
16
  type UseAddonsStepModel = ReturnType<typeof useAddonsStepModel>;
@@ -12,7 +12,7 @@ import {
12
12
  PaymentMethodTextContainer,
13
13
  } from './PaymentMethods.style';
14
14
  import { StripePaymentForm } from './stripe';
15
- import { CheckoutLocalization } from '../../textOverrides';
15
+ import { CheckoutLocalization } from '../../configurations/textOverrides';
16
16
  import { CheckoutContainerProps } from '../../CheckoutContainer';
17
17
 
18
18
  export type PaymentMethodLayoutProps = {
@@ -9,7 +9,7 @@ import { Typography } from '../../../common/Typography';
9
9
  import { formatBillingPeriod } from '../../formatting';
10
10
  import { usePlanStepModel } from '../../hooks/usePlanStepModel';
11
11
  import { BillingPeriodButton, BillingPeriodOptions, BillingPeriodPickerContainer } from './BillingPeriodPicker.style';
12
- import { CheckoutLocalization } from '../../textOverrides';
12
+ import { CheckoutLocalization } from '../../configurations/textOverrides';
13
13
 
14
14
  const BillingPeriodOption = ({
15
15
  billingPeriod,
@@ -36,7 +36,7 @@ const BillingPeriodOption = ({
36
36
  />
37
37
 
38
38
  <Box>
39
- <Typography variant="body1" color="primary">
39
+ <Typography variant="h3" color="primary">
40
40
  {formatBillingPeriod(billingPeriod)}
41
41
  </Typography>
42
42
  </Box>
@@ -5,7 +5,7 @@ import React from 'react';
5
5
  import Lottie from 'react-lottie';
6
6
  import animationData from '../../../assets/lottie/checkout-success.json';
7
7
  import { Typography } from '../../common/Typography';
8
- import { CheckoutLocalization } from '../textOverrides';
8
+ import { CheckoutLocalization } from '../configurations/textOverrides';
9
9
 
10
10
  export const ANIMATION_DURATION = 5000;
11
11
 
@@ -30,7 +30,7 @@ import {
30
30
  } from './components/LineItems';
31
31
  import { WithSkeleton } from './components/WithSkeleton';
32
32
  import { Icon } from '../../common/Icon';
33
- import { CheckoutLocalization } from '../textOverrides';
33
+ import { CheckoutLocalization } from '../configurations/textOverrides';
34
34
  import { CheckoutSuccess } from './CheckoutSuccess';
35
35
  import { getFeatureDisplayNameText } from '../../utils/getFeatureName';
36
36
 
@@ -176,10 +176,10 @@ export const CheckoutSummary = ({
176
176
  return (
177
177
  <SummaryContainer>
178
178
  <SummaryCard>
179
- <SummaryTitle variant="h6">{checkoutLocalization.summary.title}</SummaryTitle>
179
+ <SummaryTitle variant="h3">{checkoutLocalization.summary.title}</SummaryTitle>
180
180
 
181
181
  <Grid display="flex" flexDirection="row" alignItems="center" marginY={2}>
182
- <Typography variant="body1" color="primary" style={{ paddingRight: '8px' }}>
182
+ <Typography variant="h6" color="primary" style={{ paddingRight: '8px' }}>
183
183
  {checkoutLocalization.summary.planName({ plan: plan! })}
184
184
  </Typography>
185
185
  <StyledDivider className="stigg-checkout-summary-divider" sx={{ flex: 1, margin: '0 !important' }} />
@@ -218,7 +218,7 @@ export const CheckoutSummary = ({
218
218
  {!!subscription.addons?.length && (
219
219
  <>
220
220
  <Grid display="flex" flexDirection="row" alignItems="center" marginY={2}>
221
- <Typography variant="body1" color="primary" style={{ paddingRight: '8px' }}>
221
+ <Typography variant="h6" color="primary" style={{ paddingRight: '8px' }}>
222
222
  {checkoutLocalization.summary.addonsSectionTitle}
223
223
  </Typography>
224
224
  <StyledDivider className="stigg-checkout-summary-divider" sx={{ flex: 1, margin: '0 !important' }} />
@@ -248,7 +248,7 @@ export const CheckoutSummary = ({
248
248
  {!hasDiscounts && <StyledDivider className="stigg-checkout-summary-divider" />}
249
249
  {hasDiscounts && (
250
250
  <Grid display="flex" flexDirection="row" alignItems="center" marginY={2}>
251
- <Typography variant="body1" color="primary" style={{ paddingRight: '8px' }}>
251
+ <Typography variant="h6" color="primary" style={{ paddingRight: '8px' }}>
252
252
  {checkoutLocalization.summary.discountsSectionTitle}
253
253
  </Typography>
254
254
  <StyledDivider className="stigg-checkout-summary-divider" sx={{ flex: 1, margin: '0 !important' }} />
@@ -375,7 +375,11 @@ export const CheckoutSummary = ({
375
375
  void onCheckoutClick(e);
376
376
  }}
377
377
  fullWidth>
378
- <Typography className="stigg-checkout-summary-cta-button-text" color="white" style={{ display: 'flex' }}>
378
+ <Typography
379
+ className="stigg-checkout-summary-cta-button-text"
380
+ variant="h3"
381
+ color="white"
382
+ style={{ display: 'flex' }}>
379
383
  {isCheckoutCompletedSuccessfully ? (
380
384
  <Icon icon="Check" style={{ display: 'contents' }} />
381
385
  ) : isLoading || isFetchingSubscriptionPreview ? (
@@ -4,7 +4,7 @@ import moment from 'moment';
4
4
  import { BillingModel, BillingPeriod, Plan, Subscription, SubscriptionPreviewV2 } from '@stigg/js-client-sdk';
5
5
  import { Typography } from '../../../common/Typography';
6
6
  import { currencyPriceFormatter } from '../../../utils/currencyUtils';
7
- import { CheckoutLocalization } from '../../textOverrides';
7
+ import { CheckoutLocalization } from '../../configurations/textOverrides';
8
8
  import { WithSkeleton } from './WithSkeleton';
9
9
 
10
10
  export type CheckoutCaptionProps = {
@@ -123,7 +123,7 @@ const NextBillingCaption = ({
123
123
  text += `${totalAmountText}for this subscription every ${billingPeriodText} on ${nextBillingDate}, unless you cancel.`;
124
124
 
125
125
  return (
126
- <Typography variant="caption" style={{ marginTop: 14 }}>
126
+ <Typography variant="body1" style={{ marginTop: 14 }}>
127
127
  <WithSkeleton isLoading={isFetchingSubscriptionPreview} width="100%">
128
128
  {text}
129
129
  </WithSkeleton>
@@ -7,7 +7,7 @@ import { currencyPriceFormatter } from '../../../utils/currencyUtils';
7
7
  import { getTierByQuantity } from '../../../utils/priceTierUtils';
8
8
  import { WithSkeleton } from './WithSkeleton';
9
9
  import { Skeleton } from '../../components/Skeletons.style';
10
- import { CheckoutLocalization } from '../../textOverrides';
10
+ import { CheckoutLocalization } from '../../configurations/textOverrides';
11
11
  import { Icon } from '../../../common/Icon';
12
12
  import { InformationTooltip } from '../../../common/InformationTooltip';
13
13
 
@@ -29,11 +29,13 @@ const TierInput = styled(OutlinedInput)`
29
29
  export function TiersSelectContainer({
30
30
  componentId,
31
31
  tiers,
32
+ tierUnits,
32
33
  selectedTier,
33
34
  handleTierChange,
34
35
  }: {
35
36
  componentId: string;
36
37
  tiers?: PriceTierFragment[] | null;
38
+ tierUnits?: string;
37
39
  selectedTier?: PriceTierFragment;
38
40
  handleTierChange: (tier: PriceTierFragment) => void;
39
41
  }) {
@@ -61,7 +63,7 @@ export function TiersSelectContainer({
61
63
  {map(tiers, (tier: PriceTierFragment) => (
62
64
  <MenuItem className="stigg-price-tier-menu-item-text" key={tier.upTo} value={tier.upTo.toString()}>
63
65
  <Typography variant="body1" color="primary" style={{ lineHeight: 'unset' }}>
64
- {tier.upTo}
66
+ {tier.upTo} {tierUnits}
65
67
  </Typography>
66
68
  </MenuItem>
67
69
  ))}
@@ -8,6 +8,7 @@ import {
8
8
  } from '@stigg/js-client-sdk';
9
9
  import { CustomizedTheme } from '../../theme/Theme';
10
10
  import { HorizontalAlignment, FontWeight } from '../../theme/types';
11
+ import { defaultCheckoutTypography } from '../checkout/configurations/typography';
11
12
 
12
13
  function addCssUnits(value?: number | null, unit = 'px') {
13
14
  if (!value) {
@@ -31,24 +32,27 @@ function mapFontWeight(defaultValue: FontWeight, fontWeight?: JSFontWeight | nul
31
32
  }
32
33
  }
33
34
 
34
- function mapTypography(typography?: TypographyConfiguration | null): CustomizedTheme['typography'] {
35
+ export function mapTypography(
36
+ typography?: TypographyConfiguration | null,
37
+ defaultTypography?: TypographyConfiguration | null,
38
+ ): CustomizedTheme['typography'] {
35
39
  return {
36
40
  fontFamilyUrl: typography?.fontFamily || undefined,
37
41
  h1: {
38
- fontSize: addCssUnits(typography?.h1?.fontSize),
39
- fontWeight: mapFontWeight('bold', typography?.h1?.fontWeight),
42
+ fontSize: addCssUnits(typography?.h1?.fontSize || defaultTypography?.h1?.fontSize),
43
+ fontWeight: mapFontWeight('bold', typography?.h1?.fontWeight || defaultTypography?.h1?.fontWeight),
40
44
  },
41
45
  h2: {
42
- fontSize: addCssUnits(typography?.h2?.fontSize),
43
- fontWeight: mapFontWeight('normal', typography?.h2?.fontWeight),
46
+ fontSize: addCssUnits(typography?.h2?.fontSize || defaultTypography?.h2?.fontSize),
47
+ fontWeight: mapFontWeight('normal', defaultTypography?.h2?.fontWeight),
44
48
  },
45
49
  h3: {
46
- fontSize: addCssUnits(typography?.h3?.fontSize),
47
- fontWeight: mapFontWeight('normal', typography?.h3?.fontWeight),
50
+ fontSize: addCssUnits(typography?.h3?.fontSize || defaultTypography?.h3?.fontSize),
51
+ fontWeight: mapFontWeight('normal', typography?.h3?.fontWeight || defaultTypography?.h3?.fontWeight),
48
52
  },
49
53
  body: {
50
- fontSize: addCssUnits(typography?.body?.fontSize),
51
- fontWeight: mapFontWeight('normal', typography?.body?.fontWeight),
54
+ fontSize: addCssUnits(typography?.body?.fontSize || defaultTypography?.body?.fontSize),
55
+ fontWeight: mapFontWeight('normal', typography?.body?.fontWeight || defaultTypography?.body?.fontWeight),
52
56
  },
53
57
  };
54
58
  }
@@ -125,6 +129,6 @@ export function mapCheckoutConfiguration(configuration: CheckoutConfiguration):
125
129
  },
126
130
  backgroundHighlight: palette?.summaryBackgroundColor || undefined,
127
131
  },
128
- typography: mapTypography(typography),
132
+ typography: mapTypography(typography, defaultCheckoutTypography),
129
133
  };
130
134
  }
@@ -1,4 +1,4 @@
1
- import React, { useEffect, useState } from 'react';
1
+ import React from 'react';
2
2
  import styled from '@emotion/styled/macro';
3
3
  import { BillingPeriod, PriceTierFragment } from '@stigg/js-client-sdk';
4
4
  import { PaywallPlan } from './types';
@@ -71,7 +71,7 @@ export const PlanPrice = ({
71
71
  withStartingAtRow: boolean;
72
72
  withTiersRow: boolean;
73
73
  selectedTierByFeature: Record<string, PriceTierFragment>;
74
- setSelectedTierByFeature: (selectedTierByFeature: Record<string, PriceTierFragment>) => void;
74
+ setSelectedTierByFeature: React.Dispatch<React.SetStateAction<Record<string, PriceTierFragment>>>;
75
75
  plan: PaywallPlan;
76
76
  billingPeriod: BillingPeriod;
77
77
  paywallLocale: PaywallLocalization;
@@ -79,7 +79,7 @@ export const PlanPrice = ({
79
79
  hasAnnuallyPrice: boolean;
80
80
  locale: string;
81
81
  }) => {
82
- const { price, unit, tiers } = getPlanPrice(
82
+ const { price, unit, tiers, tierUnits } = getPlanPrice(
83
83
  plan,
84
84
  billingPeriod,
85
85
  paywallLocale,
@@ -87,31 +87,25 @@ export const PlanPrice = ({
87
87
  hasMonthlyPrice,
88
88
  selectedTierByFeature,
89
89
  );
90
- const [selectedTier, setSelectedTier] = useState<PriceTierFragment>();
91
90
 
92
91
  // We currently only support prices with one tier - so we select the first one
93
92
  const tieredPrice = plan.pricePoints.find((planPrice) => {
94
93
  return planPrice.billingPeriod === billingPeriod && planPrice.isTieredPrice;
95
94
  });
96
95
  const featureId = tieredPrice ? tieredPrice.feature!.featureId : undefined;
97
-
98
- useEffect(() => {
99
- setSelectedTier(featureId ? selectedTierByFeature[featureId] : undefined);
100
- }, [featureId, selectedTierByFeature]);
96
+ const selectedTier = featureId ? selectedTierByFeature[featureId] : undefined;
101
97
 
102
98
  const handleTierChange = (tier: PriceTierFragment) => {
103
- const updatedTierByFeature: Record<string, PriceTierFragment> = {};
104
- updatedTierByFeature[featureId!] = tier;
99
+ if (!featureId) {
100
+ return;
101
+ }
105
102
 
106
- setSelectedTierByFeature(updatedTierByFeature);
103
+ setSelectedTierByFeature((prevState) => ({
104
+ ...prevState,
105
+ [featureId]: tier,
106
+ }));
107
107
  };
108
108
 
109
- useEffect(() => {
110
- if (tiers) {
111
- handleTierChange(selectedTierByFeature[featureId!]);
112
- }
113
- }, []);
114
-
115
109
  return (
116
110
  <PlanPriceContainer className="stigg-price-text">
117
111
  <>
@@ -147,6 +141,7 @@ export const PlanPrice = ({
147
141
  <TiersSelectContainer
148
142
  componentId={`${plan.id}_${featureId}_tier`}
149
143
  tiers={tiers}
144
+ tierUnits={tierUnits}
150
145
  selectedTier={selectedTier}
151
146
  handleTierChange={handleTierChange}
152
147
  />