@stigg/react-sdk 4.4.0-beta.4 → 4.4.0-beta.5

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.
@@ -3,6 +3,9 @@ export declare const usePreviewSubscriptionAction: () => {
3
3
  previewSubscriptionAction: ({ promotionCode }?: {
4
4
  promotionCode?: string | null | undefined;
5
5
  }) => Promise<{
6
+ subscriptionPreview: null;
7
+ errorMessage?: undefined;
8
+ } | {
6
9
  subscriptionPreview: SubscriptionPreview | null;
7
10
  errorMessage: string | null;
8
11
  }>;
@@ -7,8 +7,9 @@ declare type CheckoutChargeListProps = {
7
7
  plan?: Plan;
8
8
  billingPeriod: BillingPeriod;
9
9
  };
10
- export declare function PlanCharge({ charge, setBillableFeature, billableFeature, onValidationChange, }: {
10
+ export declare function PlanCharge({ charge, isValid, setBillableFeature, billableFeature, onValidationChange, }: {
11
11
  charge: Price;
12
+ isValid: boolean;
12
13
  billableFeature?: BillableFeatureInput;
13
14
  setBillableFeature: UsePlanStepModel['setBillableFeature'];
14
15
  onValidationChange: ({ featureId, isValid }: {
@@ -2,5 +2,5 @@
2
2
  /// <reference types="@emotion/styled/macro" />
3
3
  export declare const SubscriptionViewLayout: import("@emotion/styled/macro").StyledComponent<{
4
4
  theme?: import("@emotion/react").Theme | undefined;
5
- as?: "symbol" | "object" | "a" | "abbr" | "address" | "area" | "article" | "aside" | "audio" | "b" | "base" | "bdi" | "bdo" | "big" | "blockquote" | "body" | "br" | "button" | "canvas" | "caption" | "cite" | "code" | "col" | "colgroup" | "data" | "datalist" | "dd" | "del" | "details" | "dfn" | "dialog" | "div" | "dl" | "dt" | "em" | "embed" | "fieldset" | "figcaption" | "figure" | "footer" | "form" | "h1" | "h2" | "h3" | "h4" | "h5" | "h6" | "head" | "header" | "hgroup" | "hr" | "html" | "i" | "iframe" | "img" | "input" | "ins" | "kbd" | "keygen" | "label" | "legend" | "li" | "link" | "main" | "map" | "mark" | "menu" | "menuitem" | "meta" | "meter" | "nav" | "noindex" | "noscript" | "ol" | "optgroup" | "option" | "output" | "p" | "param" | "picture" | "pre" | "progress" | "q" | "rp" | "rt" | "ruby" | "s" | "samp" | "slot" | "script" | "section" | "select" | "small" | "source" | "span" | "strong" | "style" | "sub" | "summary" | "sup" | "table" | "template" | "tbody" | "td" | "textarea" | "tfoot" | "th" | "thead" | "time" | "title" | "tr" | "track" | "u" | "ul" | "var" | "video" | "wbr" | "webview" | "svg" | "animate" | "animateMotion" | "animateTransform" | "circle" | "clipPath" | "defs" | "desc" | "ellipse" | "feBlend" | "feColorMatrix" | "feComponentTransfer" | "feComposite" | "feConvolveMatrix" | "feDiffuseLighting" | "feDisplacementMap" | "feDistantLight" | "feDropShadow" | "feFlood" | "feFuncA" | "feFuncB" | "feFuncG" | "feFuncR" | "feGaussianBlur" | "feImage" | "feMerge" | "feMergeNode" | "feMorphology" | "feOffset" | "fePointLight" | "feSpecularLighting" | "feSpotLight" | "feTile" | "feTurbulence" | "filter" | "foreignObject" | "g" | "image" | "line" | "linearGradient" | "marker" | "mask" | "metadata" | "mpath" | "path" | "pattern" | "polygon" | "polyline" | "radialGradient" | "rect" | "stop" | "switch" | "text" | "textPath" | "tspan" | "use" | "view" | import("react").ComponentClass<any, any> | import("react").FunctionComponent<any> | undefined;
5
+ as?: "symbol" | "object" | "big" | "link" | "small" | "sub" | "sup" | "a" | "abbr" | "address" | "area" | "article" | "aside" | "audio" | "b" | "base" | "bdi" | "bdo" | "blockquote" | "body" | "br" | "button" | "canvas" | "caption" | "cite" | "code" | "col" | "colgroup" | "data" | "datalist" | "dd" | "del" | "details" | "dfn" | "dialog" | "div" | "dl" | "dt" | "em" | "embed" | "fieldset" | "figcaption" | "figure" | "footer" | "form" | "h1" | "h2" | "h3" | "h4" | "h5" | "h6" | "head" | "header" | "hgroup" | "hr" | "html" | "i" | "iframe" | "img" | "input" | "ins" | "kbd" | "keygen" | "label" | "legend" | "li" | "main" | "map" | "mark" | "menu" | "menuitem" | "meta" | "meter" | "nav" | "noindex" | "noscript" | "ol" | "optgroup" | "option" | "output" | "p" | "param" | "picture" | "pre" | "progress" | "q" | "rp" | "rt" | "ruby" | "s" | "samp" | "slot" | "script" | "section" | "select" | "source" | "span" | "strong" | "style" | "summary" | "table" | "template" | "tbody" | "td" | "textarea" | "tfoot" | "th" | "thead" | "time" | "title" | "tr" | "track" | "u" | "ul" | "var" | "video" | "wbr" | "webview" | "svg" | "animate" | "animateMotion" | "animateTransform" | "circle" | "clipPath" | "defs" | "desc" | "ellipse" | "feBlend" | "feColorMatrix" | "feComponentTransfer" | "feComposite" | "feConvolveMatrix" | "feDiffuseLighting" | "feDisplacementMap" | "feDistantLight" | "feDropShadow" | "feFlood" | "feFuncA" | "feFuncB" | "feFuncG" | "feFuncR" | "feGaussianBlur" | "feImage" | "feMerge" | "feMergeNode" | "feMorphology" | "feOffset" | "fePointLight" | "feSpecularLighting" | "feSpotLight" | "feTile" | "feTurbulence" | "filter" | "foreignObject" | "g" | "image" | "line" | "linearGradient" | "marker" | "mask" | "metadata" | "mpath" | "path" | "pattern" | "polygon" | "polyline" | "radialGradient" | "rect" | "stop" | "switch" | "text" | "textPath" | "tspan" | "use" | "view" | import("react").ComponentClass<any, any> | import("react").FunctionComponent<any> | undefined;
6
6
  }, import("react").DetailedHTMLProps<import("react").HTMLAttributes<HTMLDivElement>, HTMLDivElement>, {}>;
@@ -6750,7 +6750,7 @@ var usePreviewSubscriptionAction = function usePreviewSubscriptionAction() {
6750
6750
 
6751
6751
  var previewSubscriptionAction = React.useCallback( /*#__PURE__*/function () {
6752
6752
  var _ref3 = _asyncToGenerator( /*#__PURE__*/runtime_1.mark(function _callee(_temp) {
6753
- var _ref4, promotionCode, estimateAddons, subscriptionPreview, errorMessage, previewSubscriptionProps, _error$message, _ref6, errorMsg;
6753
+ var _ref4, promotionCode, estimateAddons, subscriptionPreview, errorMessage, isValid, previewSubscriptionProps, _error$message, _ref7, errorMsg;
6754
6754
 
6755
6755
  return runtime_1.wrap(function _callee$(_context) {
6756
6756
  while (1) {
@@ -6767,10 +6767,25 @@ var usePreviewSubscriptionAction = function usePreviewSubscriptionAction() {
6767
6767
  });
6768
6768
  subscriptionPreview = null;
6769
6769
  errorMessage = null;
6770
- _context.prev = 4;
6770
+ isValid = !subscription.billableFeatures.some(function (_ref6) {
6771
+ var quantity = _ref6.quantity;
6772
+ return quantity === null;
6773
+ });
6774
+
6775
+ if (isValid) {
6776
+ _context.next = 7;
6777
+ break;
6778
+ }
6779
+
6780
+ return _context.abrupt("return", {
6781
+ subscriptionPreview: subscriptionPreview
6782
+ });
6783
+
6784
+ case 7:
6785
+ _context.prev = 7;
6771
6786
 
6772
6787
  if (!(customer != null && customer.id && plan != null && plan.id)) {
6773
- _context.next = 10;
6788
+ _context.next = 13;
6774
6789
  break;
6775
6790
  }
6776
6791
 
@@ -6787,34 +6802,34 @@ var usePreviewSubscriptionAction = function usePreviewSubscriptionAction() {
6787
6802
  billingAddress: subscription.billingAddress,
6788
6803
  taxPercentage: subscription.taxPercentage
6789
6804
  }));
6790
- _context.next = 9;
6805
+ _context.next = 12;
6791
6806
  return stigg.previewSubscription(previewSubscriptionProps);
6792
6807
 
6793
- case 9:
6808
+ case 12:
6794
6809
  subscriptionPreview = _context.sent;
6795
6810
 
6796
- case 10:
6797
- _context.next = 16;
6811
+ case 13:
6812
+ _context.next = 19;
6798
6813
  break;
6799
6814
 
6800
- case 12:
6801
- _context.prev = 12;
6802
- _context.t0 = _context["catch"](4);
6803
- _ref6 = (_context.t0 == null ? void 0 : (_error$message = _context.t0.message) == null ? void 0 : _error$message.split('Error:')) || [], errorMsg = _ref6[1];
6815
+ case 15:
6816
+ _context.prev = 15;
6817
+ _context.t0 = _context["catch"](7);
6818
+ _ref7 = (_context.t0 == null ? void 0 : (_error$message = _context.t0.message) == null ? void 0 : _error$message.split('Error:')) || [], errorMsg = _ref7[1];
6804
6819
  errorMessage = errorMsg == null ? void 0 : errorMsg.trim();
6805
6820
 
6806
- case 16:
6821
+ case 19:
6807
6822
  return _context.abrupt("return", {
6808
6823
  subscriptionPreview: subscriptionPreview,
6809
6824
  errorMessage: errorMessage
6810
6825
  });
6811
6826
 
6812
- case 17:
6827
+ case 20:
6813
6828
  case "end":
6814
6829
  return _context.stop();
6815
6830
  }
6816
6831
  }
6817
- }, _callee, null, [[4, 12]]);
6832
+ }, _callee, null, [[7, 15]]);
6818
6833
  }));
6819
6834
 
6820
6835
  return function (_x) {
@@ -6839,7 +6854,7 @@ var usePreviewSubscription = function usePreviewSubscription() {
6839
6854
 
6840
6855
  React.useEffect(function () {
6841
6856
  var estimateSubscription = /*#__PURE__*/function () {
6842
- var _ref7 = _asyncToGenerator( /*#__PURE__*/runtime_1.mark(function _callee2() {
6857
+ var _ref8 = _asyncToGenerator( /*#__PURE__*/runtime_1.mark(function _callee2() {
6843
6858
  var _yield$previewSubscri, subscriptionPreview;
6844
6859
 
6845
6860
  return runtime_1.wrap(function _callee2$(_context2) {
@@ -6853,7 +6868,11 @@ var usePreviewSubscription = function usePreviewSubscription() {
6853
6868
  case 3:
6854
6869
  _yield$previewSubscri = _context2.sent;
6855
6870
  subscriptionPreview = _yield$previewSubscri.subscriptionPreview;
6856
- setSubscriptionPreview(subscriptionPreview);
6871
+
6872
+ if (subscriptionPreview) {
6873
+ setSubscriptionPreview(subscriptionPreview);
6874
+ }
6875
+
6857
6876
  setIsFetchingSubscriptionPreview(false);
6858
6877
 
6859
6878
  case 7:
@@ -6865,7 +6884,7 @@ var usePreviewSubscription = function usePreviewSubscription() {
6865
6884
  }));
6866
6885
 
6867
6886
  return function estimateSubscription() {
6868
- return _ref7.apply(this, arguments);
6887
+ return _ref8.apply(this, arguments);
6869
6888
  };
6870
6889
  }();
6871
6890
 
@@ -12539,29 +12558,15 @@ function PlanCharge(_ref) {
12539
12558
  var _charge$feature, _charge$feature2, _charge$feature3;
12540
12559
 
12541
12560
  var charge = _ref.charge,
12561
+ isValid = _ref.isValid,
12542
12562
  setBillableFeature = _ref.setBillableFeature,
12543
12563
  billableFeature = _ref.billableFeature,
12544
12564
  onValidationChange = _ref.onValidationChange;
12545
-
12546
- var _React$useState = React__default.useState(true),
12547
- isValid = _React$useState[0],
12548
- setIsValid = _React$useState[1];
12549
-
12550
12565
  var featureId = (_charge$feature = charge.feature) == null ? void 0 : _charge$feature.featureId;
12551
12566
  var isBaseCharge = !featureId;
12552
12567
  var isPayAsYouGo = charge.pricingModel === Stigg.BillingModel.UsageBased;
12553
12568
  var displayName = isBaseCharge ? 'Base charge' : (_charge$feature2 = charge.feature) == null ? void 0 : _charge$feature2.displayName;
12554
12569
  var hasQuantityRestrictions = !!(charge != null && charge.minUnitQuantity || charge != null && charge.maxUnitQuantity);
12555
- React.useEffect(function () {
12556
- if (!featureId) {
12557
- return;
12558
- }
12559
-
12560
- onValidationChange({
12561
- featureId: featureId,
12562
- isValid: isValid
12563
- });
12564
- }, [featureId, isValid, onValidationChange]);
12565
12570
 
12566
12571
  var handleQuantityChange = function handleQuantityChange(event) {
12567
12572
  var _event$target, _event$target2;
@@ -12570,14 +12575,20 @@ function PlanCharge(_ref) {
12570
12575
  var value = event != null && (_event$target = event.target) != null && _event$target.value ? Number(event == null ? void 0 : (_event$target2 = event.target) == null ? void 0 : _event$target2.value) : charge.minUnitQuantity;
12571
12576
 
12572
12577
  if (!value || value <= 0) {
12573
- setIsValid(false); // Reset the input value to null
12578
+ onValidationChange({
12579
+ featureId: featureId,
12580
+ isValid: false
12581
+ }); // Reset the input value to null
12574
12582
  // @ts-ignore
12575
12583
 
12576
12584
  setBillableFeature(featureId, null);
12577
12585
  return;
12578
12586
  }
12579
12587
 
12580
- setIsValid(true);
12588
+ onValidationChange({
12589
+ featureId: featureId,
12590
+ isValid: true
12591
+ });
12581
12592
  var quantity = getValidPriceQuantity(charge, value);
12582
12593
  setBillableFeature(featureId, quantity);
12583
12594
  };
@@ -12626,7 +12637,7 @@ function PlanCharge(_ref) {
12626
12637
  margin: '4px'
12627
12638
  }
12628
12639
  },
12629
- value: (billableFeature == null ? void 0 : billableFeature.quantity) || charge.minUnitQuantity,
12640
+ value: (billableFeature == null ? void 0 : billableFeature.quantity) || charge.minUnitQuantity || '',
12630
12641
  onChange: handleQuantityChange
12631
12642
  });
12632
12643
  }
@@ -12664,7 +12675,12 @@ function CheckoutChargeList(_ref2) {
12664
12675
  return p.billingPeriod === billingPeriod;
12665
12676
  })) || []);
12666
12677
 
12667
- var _useState = React.useState({}),
12678
+ var _useState = React.useState(planCharges == null ? void 0 : planCharges.reduce(function (acc, curr) {
12679
+ var _curr$feature;
12680
+
12681
+ acc[((_curr$feature = curr.feature) == null ? void 0 : _curr$feature.featureId) || 'base-charge'] = true;
12682
+ return acc;
12683
+ }, {})),
12668
12684
  chargesValidation = _useState[0],
12669
12685
  setChargesValidation = _useState[1];
12670
12686
 
@@ -12675,7 +12691,7 @@ function CheckoutChargeList(_ref2) {
12675
12691
  setIsDisabled(isDisabled);
12676
12692
  }, [chargesValidation, setIsDisabled]);
12677
12693
  return React__default.createElement("div", null, planCharges == null ? void 0 : planCharges.map(function (charge) {
12678
- var _charge$feature5;
12694
+ var _charge$feature5, _charge$feature6;
12679
12695
 
12680
12696
  var billableFeature = billableFeatures.find(function (x) {
12681
12697
  var _charge$feature4;
@@ -12687,6 +12703,7 @@ function CheckoutChargeList(_ref2) {
12687
12703
  charge: charge,
12688
12704
  setBillableFeature: setBillableFeature,
12689
12705
  billableFeature: billableFeature,
12706
+ isValid: chargesValidation[((_charge$feature6 = charge.feature) == null ? void 0 : _charge$feature6.featureId) || 'base-charge'],
12690
12707
  onValidationChange: function onValidationChange(_ref3) {
12691
12708
  var featureId = _ref3.featureId,
12692
12709
  isValid = _ref3.isValid;