@stigg/react-sdk 4.2.1 → 4.2.2

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.
@@ -1,4 +1,4 @@
1
- import Stigg__default, { EntitlementResetPeriod, WidgetType, SubscriptionScheduleType, BillingModel, TiersMode, BillingPeriod, PricingType, Currency, FontWeight as FontWeight$1, Alignment, SubscriptionStatus, MeterType } from '@stigg/js-client-sdk';
1
+ import Stigg__default, { EntitlementResetPeriod, WidgetType, SubscriptionScheduleType, BillingModel, TiersMode, BillingPeriod, PricingType, Currency, SubscriptionStatus, FontWeight as FontWeight$1, Alignment, MeterType } from '@stigg/js-client-sdk';
2
2
  export * from '@stigg/js-client-sdk';
3
3
  import React__default, { createElement, forwardRef, useState, useEffect, useCallback, useRef, useContext, useMemo } from 'react';
4
4
  import _styled from '@emotion/styled/base';
@@ -699,14 +699,14 @@ function getSelectedTier(plan, billingPeriod, currentSubscription, selectedTierB
699
699
  var tieredPrice = currentSubscription.prices.find(function (subscriptionPrice) {
700
700
  var _subscriptionPrice$fe;
701
701
 
702
- return subscriptionPrice.pricingModel == BillingModel.PerUnit && subscriptionPrice.billingPeriod == billingPeriod && subscriptionPrice.tiersMode && ((_subscriptionPrice$fe = subscriptionPrice.feature) == null ? void 0 : _subscriptionPrice$fe.featureId) === featureId;
702
+ return subscriptionPrice.pricingModel == BillingModel.PerUnit && subscriptionPrice.tiersMode && ((_subscriptionPrice$fe = subscriptionPrice.feature) == null ? void 0 : _subscriptionPrice$fe.featureId) === featureId;
703
703
  });
704
704
 
705
705
  if (tieredPrice) {
706
- var customerTier = tieredPrice.tiers.find(function (tier) {
706
+ var customerTier = price.tiers.find(function (tier) {
707
707
  return tier.upTo === tieredPrice.feature.unitQuantity;
708
708
  });
709
- currentTier = customerTier || tieredPrice.tiers[0];
709
+ currentTier = customerTier || price.tiers[0];
710
710
  }
711
711
  }
712
712
 
@@ -2955,7 +2955,7 @@ var useStiggContext = function useStiggContext() {
2955
2955
  return ctx;
2956
2956
  };
2957
2957
 
2958
- function computeBillingPeriods(plans, preferredBillingPeriod) {
2958
+ function computeBillingPeriods(plans, activeSubscriptions, preferredBillingPeriod) {
2959
2959
  var billingPeriods = plans.flatMap(function (x) {
2960
2960
  return x.pricePoints;
2961
2961
  }).map(function (x) {
@@ -2967,7 +2967,17 @@ function computeBillingPeriods(plans, preferredBillingPeriod) {
2967
2967
 
2968
2968
  if (preferredBillingPeriod && availableBillingPeriods.includes(preferredBillingPeriod)) {
2969
2969
  defaultBillingPeriod = preferredBillingPeriod;
2970
- } else {
2970
+ } else if (activeSubscriptions) {
2971
+ var activeSubscription = activeSubscriptions.find(function (x) {
2972
+ return x.status == SubscriptionStatus.Active;
2973
+ });
2974
+
2975
+ if (activeSubscription && activeSubscription.prices.length > 0) {
2976
+ defaultBillingPeriod = activeSubscription == null ? void 0 : activeSubscription.prices[0].billingPeriod;
2977
+ }
2978
+ }
2979
+
2980
+ if (!defaultBillingPeriod) {
2971
2981
  defaultBillingPeriod = (counts[BillingPeriod.Monthly] || 0) > (counts[BillingPeriod.Annually] || 0) ? BillingPeriod.Monthly : BillingPeriod.Annually;
2972
2982
  }
2973
2983
 
@@ -3269,7 +3279,7 @@ function useLoadPaywallData(_ref) {
3269
3279
 
3270
3280
  case 6:
3271
3281
  paywallResult = _context.sent;
3272
- _computeBillingPeriod = computeBillingPeriods(paywallResult.plans, preferredBillingPeriod), _availableBillingPeriods = _computeBillingPeriod.availableBillingPeriods, defaultBillingPeriod = _computeBillingPeriod.defaultBillingPeriod;
3282
+ _computeBillingPeriod = computeBillingPeriods(paywallResult.plans, paywallResult.activeSubscriptions, preferredBillingPeriod), _availableBillingPeriods = _computeBillingPeriod.availableBillingPeriods, defaultBillingPeriod = _computeBillingPeriod.defaultBillingPeriod;
3273
3283
  setPaywall(paywallResult);
3274
3284
  setAvailableBillingPeriods(_availableBillingPeriods);
3275
3285
  setSelectedBillingPeriod(defaultBillingPeriod);