@pelcro/react-pelcro-js 3.26.0-beta.56 → 3.26.0-beta.57

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/index.cjs.js CHANGED
@@ -20448,7 +20448,8 @@ const PaymentMethodContainerWithoutStripe = _ref => {
20448
20448
  gift_message: giftRecipient === null || giftRecipient === void 0 ? void 0 : giftRecipient.giftMessage,
20449
20449
  address_id: product.address_required ? selectedAddressId : null
20450
20450
  }, (err, res) => {
20451
- if (res.data.setup_intent) {
20451
+ var _res$data;
20452
+ if (res !== null && res !== void 0 && (_res$data = res.data) !== null && _res$data !== void 0 && _res$data.setup_intent) {
20452
20453
  return confirmStripeIntentSetup(res, "subCreate");
20453
20454
  }
20454
20455
  confirmStripeCardPayment(res, err, true);
@@ -20737,7 +20738,7 @@ const PaymentMethodContainerWithoutStripe = _ref => {
20737
20738
  auth_token: window.Pelcro.user.read().auth_token,
20738
20739
  token: source.id
20739
20740
  }, (err, res) => {
20740
- var _res$data, _res$data$setup_inten, _res$data2, _res$data2$setup_inte;
20741
+ var _res$data2, _res$data2$setup_inte, _res$data3, _res$data3$setup_inte;
20741
20742
  if (err) {
20742
20743
  dispatch({
20743
20744
  type: DISABLE_SUBMIT,
@@ -20756,7 +20757,7 @@ const PaymentMethodContainerWithoutStripe = _ref => {
20756
20757
  }
20757
20758
  });
20758
20759
  }
20759
- if (((_res$data = res.data) === null || _res$data === void 0 ? void 0 : (_res$data$setup_inten = _res$data.setup_intent) === null || _res$data$setup_inten === void 0 ? void 0 : _res$data$setup_inten.status) === "requires_action" || ((_res$data2 = res.data) === null || _res$data2 === void 0 ? void 0 : (_res$data2$setup_inte = _res$data2.setup_intent) === null || _res$data2$setup_inte === void 0 ? void 0 : _res$data2$setup_inte.status) === "requires_confirmation") {
20760
+ if (((_res$data2 = res.data) === null || _res$data2 === void 0 ? void 0 : (_res$data2$setup_inte = _res$data2.setup_intent) === null || _res$data2$setup_inte === void 0 ? void 0 : _res$data2$setup_inte.status) === "requires_action" || ((_res$data3 = res.data) === null || _res$data3 === void 0 ? void 0 : (_res$data3$setup_inte = _res$data3.setup_intent) === null || _res$data3$setup_inte === void 0 ? void 0 : _res$data3$setup_inte.status) === "requires_confirmation") {
20760
20761
  confirmStripeIntentSetup(res, "create");
20761
20762
  } else {
20762
20763
  dispatch({
@@ -20792,7 +20793,7 @@ const PaymentMethodContainerWithoutStripe = _ref => {
20792
20793
  exp_year: year,
20793
20794
  is_default: isDefault
20794
20795
  }, (err, res) => {
20795
- var _res$data3, _res$data3$setup_inte, _res$data4, _res$data4$setup_inte;
20796
+ var _res$data4, _res$data4$setup_inte, _res$data5, _res$data5$setup_inte;
20796
20797
  dispatch({
20797
20798
  type: DISABLE_SUBMIT,
20798
20799
  payload: false
@@ -20811,7 +20812,7 @@ const PaymentMethodContainerWithoutStripe = _ref => {
20811
20812
  }
20812
20813
  });
20813
20814
  }
20814
- if (((_res$data3 = res.data) === null || _res$data3 === void 0 ? void 0 : (_res$data3$setup_inte = _res$data3.setup_intent) === null || _res$data3$setup_inte === void 0 ? void 0 : _res$data3$setup_inte.status) === "requires_action" || ((_res$data4 = res.data) === null || _res$data4 === void 0 ? void 0 : (_res$data4$setup_inte = _res$data4.setup_intent) === null || _res$data4$setup_inte === void 0 ? void 0 : _res$data4$setup_inte.status) === "requires_confirmation") {
20815
+ if (((_res$data4 = res.data) === null || _res$data4 === void 0 ? void 0 : (_res$data4$setup_inte = _res$data4.setup_intent) === null || _res$data4$setup_inte === void 0 ? void 0 : _res$data4$setup_inte.status) === "requires_action" || ((_res$data5 = res.data) === null || _res$data5 === void 0 ? void 0 : (_res$data5$setup_inte = _res$data5.setup_intent) === null || _res$data5$setup_inte === void 0 ? void 0 : _res$data5$setup_inte.status) === "requires_confirmation") {
20815
20816
  confirmStripeIntentSetup(res, "update");
20816
20817
  } else {
20817
20818
  dispatch({
@@ -20853,7 +20854,7 @@ const PaymentMethodContainerWithoutStripe = _ref => {
20853
20854
  auth_token: window.Pelcro.user.read().auth_token,
20854
20855
  token: source.id
20855
20856
  }, (err, res) => {
20856
- var _res$data5, _res$data5$setup_inte, _res$data6, _res$data6$setup_inte;
20857
+ var _res$data6, _res$data6$setup_inte, _res$data7, _res$data7$setup_inte;
20857
20858
  if (err) {
20858
20859
  onFailure(err);
20859
20860
  return dispatch({
@@ -20864,7 +20865,7 @@ const PaymentMethodContainerWithoutStripe = _ref => {
20864
20865
  }
20865
20866
  });
20866
20867
  }
20867
- if (((_res$data5 = res.data) === null || _res$data5 === void 0 ? void 0 : (_res$data5$setup_inte = _res$data5.setup_intent) === null || _res$data5$setup_inte === void 0 ? void 0 : _res$data5$setup_inte.status) === "requires_action" || ((_res$data6 = res.data) === null || _res$data6 === void 0 ? void 0 : (_res$data6$setup_inte = _res$data6.setup_intent) === null || _res$data6$setup_inte === void 0 ? void 0 : _res$data6$setup_inte.status) === "requires_confirmation") {
20868
+ if (((_res$data6 = res.data) === null || _res$data6 === void 0 ? void 0 : (_res$data6$setup_inte = _res$data6.setup_intent) === null || _res$data6$setup_inte === void 0 ? void 0 : _res$data6$setup_inte.status) === "requires_action" || ((_res$data7 = res.data) === null || _res$data7 === void 0 ? void 0 : (_res$data7$setup_inte = _res$data7.setup_intent) === null || _res$data7$setup_inte === void 0 ? void 0 : _res$data7$setup_inte.status) === "requires_confirmation") {
20868
20869
  confirmStripeIntentSetup(res, "replace", paymentMethodId);
20869
20870
  } else {
20870
20871
  setTimeout(() => {
@@ -21029,12 +21030,12 @@ const PaymentMethodContainerWithoutStripe = _ref => {
21029
21030
  coupon_code: state === null || state === void 0 ? void 0 : state.couponCode,
21030
21031
  address_id: selectedAddressId
21031
21032
  }, (error, res) => {
21032
- var _res$data7, _res$data8;
21033
+ var _res$data8, _res$data9;
21033
21034
  if (error) {
21034
21035
  return reject(error);
21035
21036
  }
21036
- const taxAmount = (_res$data7 = res.data) === null || _res$data7 === void 0 ? void 0 : _res$data7.taxes;
21037
- const totalAmountWithTax = (_res$data8 = res.data) === null || _res$data8 === void 0 ? void 0 : _res$data8.total;
21037
+ const taxAmount = (_res$data8 = res.data) === null || _res$data8 === void 0 ? void 0 : _res$data8.taxes;
21038
+ const totalAmountWithTax = (_res$data9 = res.data) === null || _res$data9 === void 0 ? void 0 : _res$data9.total;
21038
21039
  resolve({
21039
21040
  totalAmountWithTax,
21040
21041
  taxAmount
@@ -29642,17 +29643,21 @@ const AddressSelectModal = _ref => {
29642
29643
  AddressSelectModal.viewId = "address-select";
29643
29644
 
29644
29645
  const moveDefaultPaymentMethodToStart = paymentMethods => {
29645
- var _window$Pelcro$user$r;
29646
- const defaultPaymentMethod = (_window$Pelcro$user$r = window.Pelcro.user.read()) === null || _window$Pelcro$user$r === void 0 ? void 0 : _window$Pelcro$user$r.source;
29646
+ const defaultPaymentMethod = getDefaultPaymentMethod(paymentMethods);
29647
29647
  const paymentMethodsWithoutDefault = paymentMethods.filter(paymentMethod => paymentMethod.id !== defaultPaymentMethod.id);
29648
29648
  if (defaultPaymentMethod.status !== "chargeable") {
29649
29649
  return paymentMethodsWithoutDefault;
29650
29650
  }
29651
29651
  return [defaultPaymentMethod, ...paymentMethodsWithoutDefault];
29652
29652
  };
29653
+ const getDefaultPaymentMethod = paymentMethods => {
29654
+ const defaultPaymentMethod = paymentMethods.find(paymentMethod => paymentMethod.is_default);
29655
+ return defaultPaymentMethod;
29656
+ };
29653
29657
  const initialState$5 = {
29654
29658
  paymentMethods: [],
29655
29659
  selectedPaymentMethodId: null,
29660
+ skeletonLoader: true,
29656
29661
  isSubmitting: false,
29657
29662
  alert: {
29658
29663
  type: "error",
@@ -29683,12 +29688,11 @@ const PaymentMethodSelectContainer = _ref => {
29683
29688
  });
29684
29689
  return onSuccess(selectedPaymentMethodId);
29685
29690
  };
29686
- const getInitialSelectedMethodId = () => {
29687
- var _window$Pelcro$user$r2;
29691
+ const getInitialSelectedMethodId = paymentMethods => {
29688
29692
  if (selectedPaymentMethodIdFromStore) {
29689
29693
  return selectedPaymentMethodIdFromStore;
29690
29694
  }
29691
- const defaultMethod = (_window$Pelcro$user$r2 = window.Pelcro.user.read()) === null || _window$Pelcro$user$r2 === void 0 ? void 0 : _window$Pelcro$user$r2.source;
29695
+ const defaultMethod = getDefaultPaymentMethod(paymentMethods);
29692
29696
  if (defaultMethod && defaultMethod.status === "chargeable") {
29693
29697
  return String(defaultMethod.id);
29694
29698
  }
@@ -29705,7 +29709,12 @@ const PaymentMethodSelectContainer = _ref => {
29705
29709
  return lib_7({
29706
29710
  ...state,
29707
29711
  paymentMethods: moveDefaultPaymentMethodToStart(action.payload),
29708
- selectedPaymentMethodId: getInitialSelectedMethodId()
29712
+ selectedPaymentMethodId: getInitialSelectedMethodId(action.payload)
29713
+ });
29714
+ case SKELETON_LOADER:
29715
+ return lib_7({
29716
+ ...state,
29717
+ skeletonLoader: action.payload
29709
29718
  });
29710
29719
  case HANDLE_SUBMIT:
29711
29720
  return lib_5({
@@ -29717,10 +29726,23 @@ const PaymentMethodSelectContainer = _ref => {
29717
29726
  }
29718
29727
  }, initialState$5);
29719
29728
  React.useEffect(() => {
29720
- var _window$Pelcro$user$r3;
29721
- dispatch({
29722
- type: LOAD_PAYMENT_METHODS,
29723
- payload: (_window$Pelcro$user$r3 = window.Pelcro.user.read().sources) !== null && _window$Pelcro$user$r3 !== void 0 ? _window$Pelcro$user$r3 : []
29729
+ window.Pelcro.paymentMethods.list({
29730
+ auth_token: window.Pelcro.user.read().auth_token
29731
+ }, (err, res) => {
29732
+ if (err) {
29733
+ return console.error(err);
29734
+ }
29735
+ if (res) {
29736
+ var _res$data;
29737
+ dispatch({
29738
+ type: LOAD_PAYMENT_METHODS,
29739
+ payload: (_res$data = res.data) !== null && _res$data !== void 0 ? _res$data : []
29740
+ });
29741
+ dispatch({
29742
+ type: SKELETON_LOADER,
29743
+ payload: false
29744
+ });
29745
+ }
29724
29746
  });
29725
29747
  }, []);
29726
29748
  return /*#__PURE__*/React__default['default'].createElement("div", {
@@ -29749,7 +29771,8 @@ const PaymentMethodSelectList = () => {
29749
29771
  dispatch,
29750
29772
  state: {
29751
29773
  paymentMethods,
29752
- selectedPaymentMethodId
29774
+ selectedPaymentMethodId,
29775
+ skeletonLoader
29753
29776
  }
29754
29777
  } = React.useContext(store$5);
29755
29778
  const handlePaymentMethodSelect = event => {
@@ -29758,7 +29781,9 @@ const PaymentMethodSelectList = () => {
29758
29781
  payload: event.target.value
29759
29782
  });
29760
29783
  };
29761
- return /*#__PURE__*/React__default['default'].createElement("div", {
29784
+ return /*#__PURE__*/React__default['default'].createElement("div", null, skeletonLoader ? /*#__PURE__*/React__default['default'].createElement("div", {
29785
+ className: "plc-w-full plc-h-20 plc-bg-gray-300 plc-rounded-md plc-animate-pulse"
29786
+ }) : /*#__PURE__*/React__default['default'].createElement("div", {
29762
29787
  className: "plc-px-3 plc-py-2 plc-space-y-4 plc-overflow-y-scroll plc-max-h-80 pelcro-payment-method-select-wrapper"
29763
29788
  }, paymentMethods.map(paymentMethod => {
29764
29789
  var _paymentMethod$proper, _paymentMethod$proper2, _paymentMethod$proper3, _paymentMethod$proper4;
@@ -29781,7 +29806,7 @@ const PaymentMethodSelectList = () => {
29781
29806
  }, "\u2022\u2022\u2022\u2022 \u2022\u2022\u2022\u2022 ", (_paymentMethod$proper2 = paymentMethod.properties) === null || _paymentMethod$proper2 === void 0 ? void 0 : _paymentMethod$proper2.last4), /*#__PURE__*/React__default['default'].createElement("p", {
29782
29807
  className: "plc-text-sm plc-text-gray-500"
29783
29808
  }, t("select.expires"), " ", (_paymentMethod$proper3 = paymentMethod.properties) === null || _paymentMethod$proper3 === void 0 ? void 0 : _paymentMethod$proper3.exp_month, "/", (_paymentMethod$proper4 = paymentMethod.properties) === null || _paymentMethod$proper4 === void 0 ? void 0 : _paymentMethod$proper4.exp_year))));
29784
- }));
29809
+ })));
29785
29810
  };
29786
29811
 
29787
29812
  const PaymentMethodSelectSubmit = _ref => {
@@ -29883,7 +29908,7 @@ const initialState$4 = {
29883
29908
  paymentMethods: [],
29884
29909
  selectedPaymentMethodId: null,
29885
29910
  isSubmitting: false,
29886
- disableSubmit: false,
29911
+ disableSubmit: true,
29887
29912
  isLoading: false,
29888
29913
  skeletonLoader: true,
29889
29914
  showPaymentMethodSelect: false,
@@ -29929,6 +29954,10 @@ const PaymentMethodDeleteContainer = _ref => {
29929
29954
  payload: true
29930
29955
  });
29931
29956
  }
29957
+ dispatch({
29958
+ type: DISABLE_SUBMIT,
29959
+ payload: false
29960
+ });
29932
29961
  }
29933
29962
  });
29934
29963
  }, [paymentMethodToDelete]); // eslint-disable-line react-hooks/exhaustive-deps
@@ -29942,15 +29971,15 @@ const PaymentMethodDeleteContainer = _ref => {
29942
29971
  payment_method_id: paymentMethodId,
29943
29972
  is_default: true
29944
29973
  }, (err, res) => {
29945
- dispatch({
29946
- type: DISABLE_SUBMIT,
29947
- payload: false
29948
- });
29949
- dispatch({
29950
- type: LOADING,
29951
- payload: false
29952
- });
29953
29974
  if (err) {
29975
+ dispatch({
29976
+ type: DISABLE_SUBMIT,
29977
+ payload: false
29978
+ });
29979
+ dispatch({
29980
+ type: LOADING,
29981
+ payload: false
29982
+ });
29954
29983
  console.log(err);
29955
29984
  onFailure(err);
29956
29985
  return dispatch({
@@ -30164,7 +30193,7 @@ const PaymentMethodDeleteSubmit = _ref => {
30164
30193
  dispatch,
30165
30194
  state: {
30166
30195
  isLoading,
30167
- isDisabled,
30196
+ disableSubmit,
30168
30197
  showPaymentMethodSelect,
30169
30198
  selectedPaymentMethodId
30170
30199
  }
@@ -30176,7 +30205,7 @@ const PaymentMethodDeleteSubmit = _ref => {
30176
30205
  });
30177
30206
  onClick === null || onClick === void 0 ? void 0 : onClick();
30178
30207
  },
30179
- disabled: showPaymentMethodSelect ? isDisabled || !selectedPaymentMethodId : isDisabled,
30208
+ disabled: showPaymentMethodSelect ? !selectedPaymentMethodId : disableSubmit,
30180
30209
  isLoading: isLoading,
30181
30210
  className: "plc-w-full"
30182
30211
  }, otherProps), name !== null && name !== void 0 ? name : t("delete.buttons.delete"));
package/dist/index.esm.js CHANGED
@@ -20418,7 +20418,8 @@ const PaymentMethodContainerWithoutStripe = _ref => {
20418
20418
  gift_message: giftRecipient === null || giftRecipient === void 0 ? void 0 : giftRecipient.giftMessage,
20419
20419
  address_id: product.address_required ? selectedAddressId : null
20420
20420
  }, (err, res) => {
20421
- if (res.data.setup_intent) {
20421
+ var _res$data;
20422
+ if (res !== null && res !== void 0 && (_res$data = res.data) !== null && _res$data !== void 0 && _res$data.setup_intent) {
20422
20423
  return confirmStripeIntentSetup(res, "subCreate");
20423
20424
  }
20424
20425
  confirmStripeCardPayment(res, err, true);
@@ -20707,7 +20708,7 @@ const PaymentMethodContainerWithoutStripe = _ref => {
20707
20708
  auth_token: window.Pelcro.user.read().auth_token,
20708
20709
  token: source.id
20709
20710
  }, (err, res) => {
20710
- var _res$data, _res$data$setup_inten, _res$data2, _res$data2$setup_inte;
20711
+ var _res$data2, _res$data2$setup_inte, _res$data3, _res$data3$setup_inte;
20711
20712
  if (err) {
20712
20713
  dispatch({
20713
20714
  type: DISABLE_SUBMIT,
@@ -20726,7 +20727,7 @@ const PaymentMethodContainerWithoutStripe = _ref => {
20726
20727
  }
20727
20728
  });
20728
20729
  }
20729
- if (((_res$data = res.data) === null || _res$data === void 0 ? void 0 : (_res$data$setup_inten = _res$data.setup_intent) === null || _res$data$setup_inten === void 0 ? void 0 : _res$data$setup_inten.status) === "requires_action" || ((_res$data2 = res.data) === null || _res$data2 === void 0 ? void 0 : (_res$data2$setup_inte = _res$data2.setup_intent) === null || _res$data2$setup_inte === void 0 ? void 0 : _res$data2$setup_inte.status) === "requires_confirmation") {
20730
+ if (((_res$data2 = res.data) === null || _res$data2 === void 0 ? void 0 : (_res$data2$setup_inte = _res$data2.setup_intent) === null || _res$data2$setup_inte === void 0 ? void 0 : _res$data2$setup_inte.status) === "requires_action" || ((_res$data3 = res.data) === null || _res$data3 === void 0 ? void 0 : (_res$data3$setup_inte = _res$data3.setup_intent) === null || _res$data3$setup_inte === void 0 ? void 0 : _res$data3$setup_inte.status) === "requires_confirmation") {
20730
20731
  confirmStripeIntentSetup(res, "create");
20731
20732
  } else {
20732
20733
  dispatch({
@@ -20762,7 +20763,7 @@ const PaymentMethodContainerWithoutStripe = _ref => {
20762
20763
  exp_year: year,
20763
20764
  is_default: isDefault
20764
20765
  }, (err, res) => {
20765
- var _res$data3, _res$data3$setup_inte, _res$data4, _res$data4$setup_inte;
20766
+ var _res$data4, _res$data4$setup_inte, _res$data5, _res$data5$setup_inte;
20766
20767
  dispatch({
20767
20768
  type: DISABLE_SUBMIT,
20768
20769
  payload: false
@@ -20781,7 +20782,7 @@ const PaymentMethodContainerWithoutStripe = _ref => {
20781
20782
  }
20782
20783
  });
20783
20784
  }
20784
- if (((_res$data3 = res.data) === null || _res$data3 === void 0 ? void 0 : (_res$data3$setup_inte = _res$data3.setup_intent) === null || _res$data3$setup_inte === void 0 ? void 0 : _res$data3$setup_inte.status) === "requires_action" || ((_res$data4 = res.data) === null || _res$data4 === void 0 ? void 0 : (_res$data4$setup_inte = _res$data4.setup_intent) === null || _res$data4$setup_inte === void 0 ? void 0 : _res$data4$setup_inte.status) === "requires_confirmation") {
20785
+ if (((_res$data4 = res.data) === null || _res$data4 === void 0 ? void 0 : (_res$data4$setup_inte = _res$data4.setup_intent) === null || _res$data4$setup_inte === void 0 ? void 0 : _res$data4$setup_inte.status) === "requires_action" || ((_res$data5 = res.data) === null || _res$data5 === void 0 ? void 0 : (_res$data5$setup_inte = _res$data5.setup_intent) === null || _res$data5$setup_inte === void 0 ? void 0 : _res$data5$setup_inte.status) === "requires_confirmation") {
20785
20786
  confirmStripeIntentSetup(res, "update");
20786
20787
  } else {
20787
20788
  dispatch({
@@ -20823,7 +20824,7 @@ const PaymentMethodContainerWithoutStripe = _ref => {
20823
20824
  auth_token: window.Pelcro.user.read().auth_token,
20824
20825
  token: source.id
20825
20826
  }, (err, res) => {
20826
- var _res$data5, _res$data5$setup_inte, _res$data6, _res$data6$setup_inte;
20827
+ var _res$data6, _res$data6$setup_inte, _res$data7, _res$data7$setup_inte;
20827
20828
  if (err) {
20828
20829
  onFailure(err);
20829
20830
  return dispatch({
@@ -20834,7 +20835,7 @@ const PaymentMethodContainerWithoutStripe = _ref => {
20834
20835
  }
20835
20836
  });
20836
20837
  }
20837
- if (((_res$data5 = res.data) === null || _res$data5 === void 0 ? void 0 : (_res$data5$setup_inte = _res$data5.setup_intent) === null || _res$data5$setup_inte === void 0 ? void 0 : _res$data5$setup_inte.status) === "requires_action" || ((_res$data6 = res.data) === null || _res$data6 === void 0 ? void 0 : (_res$data6$setup_inte = _res$data6.setup_intent) === null || _res$data6$setup_inte === void 0 ? void 0 : _res$data6$setup_inte.status) === "requires_confirmation") {
20838
+ if (((_res$data6 = res.data) === null || _res$data6 === void 0 ? void 0 : (_res$data6$setup_inte = _res$data6.setup_intent) === null || _res$data6$setup_inte === void 0 ? void 0 : _res$data6$setup_inte.status) === "requires_action" || ((_res$data7 = res.data) === null || _res$data7 === void 0 ? void 0 : (_res$data7$setup_inte = _res$data7.setup_intent) === null || _res$data7$setup_inte === void 0 ? void 0 : _res$data7$setup_inte.status) === "requires_confirmation") {
20838
20839
  confirmStripeIntentSetup(res, "replace", paymentMethodId);
20839
20840
  } else {
20840
20841
  setTimeout(() => {
@@ -20999,12 +21000,12 @@ const PaymentMethodContainerWithoutStripe = _ref => {
20999
21000
  coupon_code: state === null || state === void 0 ? void 0 : state.couponCode,
21000
21001
  address_id: selectedAddressId
21001
21002
  }, (error, res) => {
21002
- var _res$data7, _res$data8;
21003
+ var _res$data8, _res$data9;
21003
21004
  if (error) {
21004
21005
  return reject(error);
21005
21006
  }
21006
- const taxAmount = (_res$data7 = res.data) === null || _res$data7 === void 0 ? void 0 : _res$data7.taxes;
21007
- const totalAmountWithTax = (_res$data8 = res.data) === null || _res$data8 === void 0 ? void 0 : _res$data8.total;
21007
+ const taxAmount = (_res$data8 = res.data) === null || _res$data8 === void 0 ? void 0 : _res$data8.taxes;
21008
+ const totalAmountWithTax = (_res$data9 = res.data) === null || _res$data9 === void 0 ? void 0 : _res$data9.total;
21008
21009
  resolve({
21009
21010
  totalAmountWithTax,
21010
21011
  taxAmount
@@ -29612,17 +29613,21 @@ const AddressSelectModal = _ref => {
29612
29613
  AddressSelectModal.viewId = "address-select";
29613
29614
 
29614
29615
  const moveDefaultPaymentMethodToStart = paymentMethods => {
29615
- var _window$Pelcro$user$r;
29616
- const defaultPaymentMethod = (_window$Pelcro$user$r = window.Pelcro.user.read()) === null || _window$Pelcro$user$r === void 0 ? void 0 : _window$Pelcro$user$r.source;
29616
+ const defaultPaymentMethod = getDefaultPaymentMethod(paymentMethods);
29617
29617
  const paymentMethodsWithoutDefault = paymentMethods.filter(paymentMethod => paymentMethod.id !== defaultPaymentMethod.id);
29618
29618
  if (defaultPaymentMethod.status !== "chargeable") {
29619
29619
  return paymentMethodsWithoutDefault;
29620
29620
  }
29621
29621
  return [defaultPaymentMethod, ...paymentMethodsWithoutDefault];
29622
29622
  };
29623
+ const getDefaultPaymentMethod = paymentMethods => {
29624
+ const defaultPaymentMethod = paymentMethods.find(paymentMethod => paymentMethod.is_default);
29625
+ return defaultPaymentMethod;
29626
+ };
29623
29627
  const initialState$5 = {
29624
29628
  paymentMethods: [],
29625
29629
  selectedPaymentMethodId: null,
29630
+ skeletonLoader: true,
29626
29631
  isSubmitting: false,
29627
29632
  alert: {
29628
29633
  type: "error",
@@ -29653,12 +29658,11 @@ const PaymentMethodSelectContainer = _ref => {
29653
29658
  });
29654
29659
  return onSuccess(selectedPaymentMethodId);
29655
29660
  };
29656
- const getInitialSelectedMethodId = () => {
29657
- var _window$Pelcro$user$r2;
29661
+ const getInitialSelectedMethodId = paymentMethods => {
29658
29662
  if (selectedPaymentMethodIdFromStore) {
29659
29663
  return selectedPaymentMethodIdFromStore;
29660
29664
  }
29661
- const defaultMethod = (_window$Pelcro$user$r2 = window.Pelcro.user.read()) === null || _window$Pelcro$user$r2 === void 0 ? void 0 : _window$Pelcro$user$r2.source;
29665
+ const defaultMethod = getDefaultPaymentMethod(paymentMethods);
29662
29666
  if (defaultMethod && defaultMethod.status === "chargeable") {
29663
29667
  return String(defaultMethod.id);
29664
29668
  }
@@ -29675,7 +29679,12 @@ const PaymentMethodSelectContainer = _ref => {
29675
29679
  return lib_7({
29676
29680
  ...state,
29677
29681
  paymentMethods: moveDefaultPaymentMethodToStart(action.payload),
29678
- selectedPaymentMethodId: getInitialSelectedMethodId()
29682
+ selectedPaymentMethodId: getInitialSelectedMethodId(action.payload)
29683
+ });
29684
+ case SKELETON_LOADER:
29685
+ return lib_7({
29686
+ ...state,
29687
+ skeletonLoader: action.payload
29679
29688
  });
29680
29689
  case HANDLE_SUBMIT:
29681
29690
  return lib_5({
@@ -29687,10 +29696,23 @@ const PaymentMethodSelectContainer = _ref => {
29687
29696
  }
29688
29697
  }, initialState$5);
29689
29698
  useEffect(() => {
29690
- var _window$Pelcro$user$r3;
29691
- dispatch({
29692
- type: LOAD_PAYMENT_METHODS,
29693
- payload: (_window$Pelcro$user$r3 = window.Pelcro.user.read().sources) !== null && _window$Pelcro$user$r3 !== void 0 ? _window$Pelcro$user$r3 : []
29699
+ window.Pelcro.paymentMethods.list({
29700
+ auth_token: window.Pelcro.user.read().auth_token
29701
+ }, (err, res) => {
29702
+ if (err) {
29703
+ return console.error(err);
29704
+ }
29705
+ if (res) {
29706
+ var _res$data;
29707
+ dispatch({
29708
+ type: LOAD_PAYMENT_METHODS,
29709
+ payload: (_res$data = res.data) !== null && _res$data !== void 0 ? _res$data : []
29710
+ });
29711
+ dispatch({
29712
+ type: SKELETON_LOADER,
29713
+ payload: false
29714
+ });
29715
+ }
29694
29716
  });
29695
29717
  }, []);
29696
29718
  return /*#__PURE__*/React__default.createElement("div", {
@@ -29719,7 +29741,8 @@ const PaymentMethodSelectList = () => {
29719
29741
  dispatch,
29720
29742
  state: {
29721
29743
  paymentMethods,
29722
- selectedPaymentMethodId
29744
+ selectedPaymentMethodId,
29745
+ skeletonLoader
29723
29746
  }
29724
29747
  } = useContext(store$5);
29725
29748
  const handlePaymentMethodSelect = event => {
@@ -29728,7 +29751,9 @@ const PaymentMethodSelectList = () => {
29728
29751
  payload: event.target.value
29729
29752
  });
29730
29753
  };
29731
- return /*#__PURE__*/React__default.createElement("div", {
29754
+ return /*#__PURE__*/React__default.createElement("div", null, skeletonLoader ? /*#__PURE__*/React__default.createElement("div", {
29755
+ className: "plc-w-full plc-h-20 plc-bg-gray-300 plc-rounded-md plc-animate-pulse"
29756
+ }) : /*#__PURE__*/React__default.createElement("div", {
29732
29757
  className: "plc-px-3 plc-py-2 plc-space-y-4 plc-overflow-y-scroll plc-max-h-80 pelcro-payment-method-select-wrapper"
29733
29758
  }, paymentMethods.map(paymentMethod => {
29734
29759
  var _paymentMethod$proper, _paymentMethod$proper2, _paymentMethod$proper3, _paymentMethod$proper4;
@@ -29751,7 +29776,7 @@ const PaymentMethodSelectList = () => {
29751
29776
  }, "\u2022\u2022\u2022\u2022 \u2022\u2022\u2022\u2022 ", (_paymentMethod$proper2 = paymentMethod.properties) === null || _paymentMethod$proper2 === void 0 ? void 0 : _paymentMethod$proper2.last4), /*#__PURE__*/React__default.createElement("p", {
29752
29777
  className: "plc-text-sm plc-text-gray-500"
29753
29778
  }, t("select.expires"), " ", (_paymentMethod$proper3 = paymentMethod.properties) === null || _paymentMethod$proper3 === void 0 ? void 0 : _paymentMethod$proper3.exp_month, "/", (_paymentMethod$proper4 = paymentMethod.properties) === null || _paymentMethod$proper4 === void 0 ? void 0 : _paymentMethod$proper4.exp_year))));
29754
- }));
29779
+ })));
29755
29780
  };
29756
29781
 
29757
29782
  const PaymentMethodSelectSubmit = _ref => {
@@ -29853,7 +29878,7 @@ const initialState$4 = {
29853
29878
  paymentMethods: [],
29854
29879
  selectedPaymentMethodId: null,
29855
29880
  isSubmitting: false,
29856
- disableSubmit: false,
29881
+ disableSubmit: true,
29857
29882
  isLoading: false,
29858
29883
  skeletonLoader: true,
29859
29884
  showPaymentMethodSelect: false,
@@ -29899,6 +29924,10 @@ const PaymentMethodDeleteContainer = _ref => {
29899
29924
  payload: true
29900
29925
  });
29901
29926
  }
29927
+ dispatch({
29928
+ type: DISABLE_SUBMIT,
29929
+ payload: false
29930
+ });
29902
29931
  }
29903
29932
  });
29904
29933
  }, [paymentMethodToDelete]); // eslint-disable-line react-hooks/exhaustive-deps
@@ -29912,15 +29941,15 @@ const PaymentMethodDeleteContainer = _ref => {
29912
29941
  payment_method_id: paymentMethodId,
29913
29942
  is_default: true
29914
29943
  }, (err, res) => {
29915
- dispatch({
29916
- type: DISABLE_SUBMIT,
29917
- payload: false
29918
- });
29919
- dispatch({
29920
- type: LOADING,
29921
- payload: false
29922
- });
29923
29944
  if (err) {
29945
+ dispatch({
29946
+ type: DISABLE_SUBMIT,
29947
+ payload: false
29948
+ });
29949
+ dispatch({
29950
+ type: LOADING,
29951
+ payload: false
29952
+ });
29924
29953
  console.log(err);
29925
29954
  onFailure(err);
29926
29955
  return dispatch({
@@ -30134,7 +30163,7 @@ const PaymentMethodDeleteSubmit = _ref => {
30134
30163
  dispatch,
30135
30164
  state: {
30136
30165
  isLoading,
30137
- isDisabled,
30166
+ disableSubmit,
30138
30167
  showPaymentMethodSelect,
30139
30168
  selectedPaymentMethodId
30140
30169
  }
@@ -30146,7 +30175,7 @@ const PaymentMethodDeleteSubmit = _ref => {
30146
30175
  });
30147
30176
  onClick === null || onClick === void 0 ? void 0 : onClick();
30148
30177
  },
30149
- disabled: showPaymentMethodSelect ? isDisabled || !selectedPaymentMethodId : isDisabled,
30178
+ disabled: showPaymentMethodSelect ? !selectedPaymentMethodId : disableSubmit,
30150
30179
  isLoading: isLoading,
30151
30180
  className: "plc-w-full"
30152
30181
  }, otherProps), name !== null && name !== void 0 ? name : t("delete.buttons.delete"));
package/package.json CHANGED
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "name": "@pelcro/react-pelcro-js",
3
3
  "description": "Pelcro's React UI Elements",
4
- "version": "3.26.0-beta.56",
4
+ "version": "3.26.0-beta.57",
5
5
  "license": "MIT",
6
6
  "private": false,
7
7
  "main": "dist/index.cjs.js",