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

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
@@ -9926,6 +9926,19 @@ function generatePassword() {
9926
9926
  }
9927
9927
  return retVal;
9928
9928
  }
9929
+ const refreshUser = () => {
9930
+ var _window$Pelcro6, _window$Pelcro6$user, _window$Pelcro6$user$;
9931
+ window.Pelcro.user.refresh({
9932
+ auth_token: (_window$Pelcro6 = window.Pelcro) === null || _window$Pelcro6 === void 0 ? void 0 : (_window$Pelcro6$user = _window$Pelcro6.user) === null || _window$Pelcro6$user === void 0 ? void 0 : (_window$Pelcro6$user$ = _window$Pelcro6$user.read()) === null || _window$Pelcro6$user$ === void 0 ? void 0 : _window$Pelcro6$user$.auth_token
9933
+ }, (err, res) => {
9934
+ if (err) {
9935
+ console.error(err);
9936
+ }
9937
+ if (res) {
9938
+ return res.data;
9939
+ }
9940
+ });
9941
+ };
9929
9942
 
9930
9943
  const resources = {
9931
9944
  en: {
@@ -19655,6 +19668,7 @@ const PaymentMethodContainerWithoutStripe = _ref => {
19655
19668
  content: t("messages.sourceCreated")
19656
19669
  }
19657
19670
  });
19671
+ refreshUser();
19658
19672
  onSuccess(res);
19659
19673
  });
19660
19674
  }
@@ -19709,6 +19723,7 @@ const PaymentMethodContainerWithoutStripe = _ref => {
19709
19723
  }
19710
19724
  });
19711
19725
  }
19726
+ refreshUser();
19712
19727
  onSuccess(res);
19713
19728
  });
19714
19729
  }, 2000);
@@ -19770,6 +19785,7 @@ const PaymentMethodContainerWithoutStripe = _ref => {
19770
19785
  content: t("messages.sourceUpdated")
19771
19786
  }
19772
19787
  });
19788
+ refreshUser();
19773
19789
  onSuccess(res);
19774
19790
  });
19775
19791
  }
@@ -20356,6 +20372,7 @@ const PaymentMethodContainerWithoutStripe = _ref => {
20356
20372
  type: LOADING,
20357
20373
  payload: false
20358
20374
  });
20375
+ refreshUser();
20359
20376
  onSuccess(res);
20360
20377
  return;
20361
20378
  }
@@ -20371,6 +20388,7 @@ const PaymentMethodContainerWithoutStripe = _ref => {
20371
20388
  content: t("messages.sourceCreated")
20372
20389
  }
20373
20390
  });
20391
+ refreshUser();
20374
20392
  onSuccess(res);
20375
20393
  return;
20376
20394
  }
@@ -20390,6 +20408,7 @@ const PaymentMethodContainerWithoutStripe = _ref => {
20390
20408
  content: t("messages.sourceUpdated")
20391
20409
  }
20392
20410
  });
20411
+ refreshUser();
20393
20412
  onSuccess(res);
20394
20413
  return;
20395
20414
  }
@@ -20417,6 +20436,7 @@ const PaymentMethodContainerWithoutStripe = _ref => {
20417
20436
  }
20418
20437
  });
20419
20438
  }
20439
+ refreshUser();
20420
20440
  onSuccess(res);
20421
20441
  });
20422
20442
  }, 2000);
@@ -20448,7 +20468,8 @@ const PaymentMethodContainerWithoutStripe = _ref => {
20448
20468
  gift_message: giftRecipient === null || giftRecipient === void 0 ? void 0 : giftRecipient.giftMessage,
20449
20469
  address_id: product.address_required ? selectedAddressId : null
20450
20470
  }, (err, res) => {
20451
- if (res.data.setup_intent) {
20471
+ var _res$data;
20472
+ if (res !== null && res !== void 0 && (_res$data = res.data) !== null && _res$data !== void 0 && _res$data.setup_intent) {
20452
20473
  return confirmStripeIntentSetup(res, "subCreate");
20453
20474
  }
20454
20475
  confirmStripeCardPayment(res, err, true);
@@ -20737,7 +20758,7 @@ const PaymentMethodContainerWithoutStripe = _ref => {
20737
20758
  auth_token: window.Pelcro.user.read().auth_token,
20738
20759
  token: source.id
20739
20760
  }, (err, res) => {
20740
- var _res$data, _res$data$setup_inten, _res$data2, _res$data2$setup_inte;
20761
+ var _res$data2, _res$data2$setup_inte, _res$data3, _res$data3$setup_inte;
20741
20762
  if (err) {
20742
20763
  dispatch({
20743
20764
  type: DISABLE_SUBMIT,
@@ -20756,7 +20777,7 @@ const PaymentMethodContainerWithoutStripe = _ref => {
20756
20777
  }
20757
20778
  });
20758
20779
  }
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") {
20780
+ 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
20781
  confirmStripeIntentSetup(res, "create");
20761
20782
  } else {
20762
20783
  dispatch({
@@ -20770,6 +20791,7 @@ const PaymentMethodContainerWithoutStripe = _ref => {
20770
20791
  content: t("messages.sourceCreated")
20771
20792
  }
20772
20793
  });
20794
+ refreshUser();
20773
20795
  onSuccess(res);
20774
20796
  }
20775
20797
  });
@@ -20792,7 +20814,7 @@ const PaymentMethodContainerWithoutStripe = _ref => {
20792
20814
  exp_year: year,
20793
20815
  is_default: isDefault
20794
20816
  }, (err, res) => {
20795
- var _res$data3, _res$data3$setup_inte, _res$data4, _res$data4$setup_inte;
20817
+ var _res$data4, _res$data4$setup_inte, _res$data5, _res$data5$setup_inte;
20796
20818
  dispatch({
20797
20819
  type: DISABLE_SUBMIT,
20798
20820
  payload: false
@@ -20811,7 +20833,7 @@ const PaymentMethodContainerWithoutStripe = _ref => {
20811
20833
  }
20812
20834
  });
20813
20835
  }
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") {
20836
+ 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
20837
  confirmStripeIntentSetup(res, "update");
20816
20838
  } else {
20817
20839
  dispatch({
@@ -20821,6 +20843,7 @@ const PaymentMethodContainerWithoutStripe = _ref => {
20821
20843
  content: t("messages.sourceUpdated")
20822
20844
  }
20823
20845
  });
20846
+ refreshUser();
20824
20847
  onSuccess(res);
20825
20848
  }
20826
20849
  });
@@ -20853,7 +20876,7 @@ const PaymentMethodContainerWithoutStripe = _ref => {
20853
20876
  auth_token: window.Pelcro.user.read().auth_token,
20854
20877
  token: source.id
20855
20878
  }, (err, res) => {
20856
- var _res$data5, _res$data5$setup_inte, _res$data6, _res$data6$setup_inte;
20879
+ var _res$data6, _res$data6$setup_inte, _res$data7, _res$data7$setup_inte;
20857
20880
  if (err) {
20858
20881
  onFailure(err);
20859
20882
  return dispatch({
@@ -20864,7 +20887,7 @@ const PaymentMethodContainerWithoutStripe = _ref => {
20864
20887
  }
20865
20888
  });
20866
20889
  }
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") {
20890
+ 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
20891
  confirmStripeIntentSetup(res, "replace", paymentMethodId);
20869
20892
  } else {
20870
20893
  setTimeout(() => {
@@ -20890,6 +20913,7 @@ const PaymentMethodContainerWithoutStripe = _ref => {
20890
20913
  }
20891
20914
  });
20892
20915
  }
20916
+ refreshUser();
20893
20917
  onSuccess(res);
20894
20918
  });
20895
20919
  }, 2000);
@@ -21029,12 +21053,12 @@ const PaymentMethodContainerWithoutStripe = _ref => {
21029
21053
  coupon_code: state === null || state === void 0 ? void 0 : state.couponCode,
21030
21054
  address_id: selectedAddressId
21031
21055
  }, (error, res) => {
21032
- var _res$data7, _res$data8;
21056
+ var _res$data8, _res$data9;
21033
21057
  if (error) {
21034
21058
  return reject(error);
21035
21059
  }
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;
21060
+ const taxAmount = (_res$data8 = res.data) === null || _res$data8 === void 0 ? void 0 : _res$data8.taxes;
21061
+ const totalAmountWithTax = (_res$data9 = res.data) === null || _res$data9 === void 0 ? void 0 : _res$data9.total;
21038
21062
  resolve({
21039
21063
  totalAmountWithTax,
21040
21064
  taxAmount
@@ -29642,17 +29666,21 @@ const AddressSelectModal = _ref => {
29642
29666
  AddressSelectModal.viewId = "address-select";
29643
29667
 
29644
29668
  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;
29669
+ const defaultPaymentMethod = getDefaultPaymentMethod(paymentMethods);
29647
29670
  const paymentMethodsWithoutDefault = paymentMethods.filter(paymentMethod => paymentMethod.id !== defaultPaymentMethod.id);
29648
29671
  if (defaultPaymentMethod.status !== "chargeable") {
29649
29672
  return paymentMethodsWithoutDefault;
29650
29673
  }
29651
29674
  return [defaultPaymentMethod, ...paymentMethodsWithoutDefault];
29652
29675
  };
29676
+ const getDefaultPaymentMethod = paymentMethods => {
29677
+ const defaultPaymentMethod = paymentMethods.find(paymentMethod => paymentMethod.is_default);
29678
+ return defaultPaymentMethod;
29679
+ };
29653
29680
  const initialState$5 = {
29654
29681
  paymentMethods: [],
29655
29682
  selectedPaymentMethodId: null,
29683
+ skeletonLoader: true,
29656
29684
  isSubmitting: false,
29657
29685
  alert: {
29658
29686
  type: "error",
@@ -29683,12 +29711,11 @@ const PaymentMethodSelectContainer = _ref => {
29683
29711
  });
29684
29712
  return onSuccess(selectedPaymentMethodId);
29685
29713
  };
29686
- const getInitialSelectedMethodId = () => {
29687
- var _window$Pelcro$user$r2;
29714
+ const getInitialSelectedMethodId = paymentMethods => {
29688
29715
  if (selectedPaymentMethodIdFromStore) {
29689
29716
  return selectedPaymentMethodIdFromStore;
29690
29717
  }
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;
29718
+ const defaultMethod = getDefaultPaymentMethod(paymentMethods);
29692
29719
  if (defaultMethod && defaultMethod.status === "chargeable") {
29693
29720
  return String(defaultMethod.id);
29694
29721
  }
@@ -29705,7 +29732,12 @@ const PaymentMethodSelectContainer = _ref => {
29705
29732
  return lib_7({
29706
29733
  ...state,
29707
29734
  paymentMethods: moveDefaultPaymentMethodToStart(action.payload),
29708
- selectedPaymentMethodId: getInitialSelectedMethodId()
29735
+ selectedPaymentMethodId: getInitialSelectedMethodId(action.payload)
29736
+ });
29737
+ case SKELETON_LOADER:
29738
+ return lib_7({
29739
+ ...state,
29740
+ skeletonLoader: action.payload
29709
29741
  });
29710
29742
  case HANDLE_SUBMIT:
29711
29743
  return lib_5({
@@ -29717,10 +29749,23 @@ const PaymentMethodSelectContainer = _ref => {
29717
29749
  }
29718
29750
  }, initialState$5);
29719
29751
  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 : []
29752
+ window.Pelcro.paymentMethods.list({
29753
+ auth_token: window.Pelcro.user.read().auth_token
29754
+ }, (err, res) => {
29755
+ if (err) {
29756
+ return console.error(err);
29757
+ }
29758
+ if (res) {
29759
+ var _res$data;
29760
+ dispatch({
29761
+ type: LOAD_PAYMENT_METHODS,
29762
+ payload: (_res$data = res.data) !== null && _res$data !== void 0 ? _res$data : []
29763
+ });
29764
+ dispatch({
29765
+ type: SKELETON_LOADER,
29766
+ payload: false
29767
+ });
29768
+ }
29724
29769
  });
29725
29770
  }, []);
29726
29771
  return /*#__PURE__*/React__default['default'].createElement("div", {
@@ -29749,7 +29794,8 @@ const PaymentMethodSelectList = () => {
29749
29794
  dispatch,
29750
29795
  state: {
29751
29796
  paymentMethods,
29752
- selectedPaymentMethodId
29797
+ selectedPaymentMethodId,
29798
+ skeletonLoader
29753
29799
  }
29754
29800
  } = React.useContext(store$5);
29755
29801
  const handlePaymentMethodSelect = event => {
@@ -29758,7 +29804,9 @@ const PaymentMethodSelectList = () => {
29758
29804
  payload: event.target.value
29759
29805
  });
29760
29806
  };
29761
- return /*#__PURE__*/React__default['default'].createElement("div", {
29807
+ return /*#__PURE__*/React__default['default'].createElement("div", null, skeletonLoader ? /*#__PURE__*/React__default['default'].createElement("div", {
29808
+ className: "plc-w-full plc-h-20 plc-bg-gray-300 plc-rounded-md plc-animate-pulse"
29809
+ }) : /*#__PURE__*/React__default['default'].createElement("div", {
29762
29810
  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
29811
  }, paymentMethods.map(paymentMethod => {
29764
29812
  var _paymentMethod$proper, _paymentMethod$proper2, _paymentMethod$proper3, _paymentMethod$proper4;
@@ -29781,7 +29829,7 @@ const PaymentMethodSelectList = () => {
29781
29829
  }, "\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
29830
  className: "plc-text-sm plc-text-gray-500"
29783
29831
  }, 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
- }));
29832
+ })));
29785
29833
  };
29786
29834
 
29787
29835
  const PaymentMethodSelectSubmit = _ref => {
@@ -29883,7 +29931,7 @@ const initialState$4 = {
29883
29931
  paymentMethods: [],
29884
29932
  selectedPaymentMethodId: null,
29885
29933
  isSubmitting: false,
29886
- disableSubmit: false,
29934
+ disableSubmit: true,
29887
29935
  isLoading: false,
29888
29936
  skeletonLoader: true,
29889
29937
  showPaymentMethodSelect: false,
@@ -29929,6 +29977,10 @@ const PaymentMethodDeleteContainer = _ref => {
29929
29977
  payload: true
29930
29978
  });
29931
29979
  }
29980
+ dispatch({
29981
+ type: DISABLE_SUBMIT,
29982
+ payload: false
29983
+ });
29932
29984
  }
29933
29985
  });
29934
29986
  }, [paymentMethodToDelete]); // eslint-disable-line react-hooks/exhaustive-deps
@@ -29942,15 +29994,15 @@ const PaymentMethodDeleteContainer = _ref => {
29942
29994
  payment_method_id: paymentMethodId,
29943
29995
  is_default: true
29944
29996
  }, (err, res) => {
29945
- dispatch({
29946
- type: DISABLE_SUBMIT,
29947
- payload: false
29948
- });
29949
- dispatch({
29950
- type: LOADING,
29951
- payload: false
29952
- });
29953
29997
  if (err) {
29998
+ dispatch({
29999
+ type: DISABLE_SUBMIT,
30000
+ payload: false
30001
+ });
30002
+ dispatch({
30003
+ type: LOADING,
30004
+ payload: false
30005
+ });
29954
30006
  console.log(err);
29955
30007
  onFailure(err);
29956
30008
  return dispatch({
@@ -30164,7 +30216,7 @@ const PaymentMethodDeleteSubmit = _ref => {
30164
30216
  dispatch,
30165
30217
  state: {
30166
30218
  isLoading,
30167
- isDisabled,
30219
+ disableSubmit,
30168
30220
  showPaymentMethodSelect,
30169
30221
  selectedPaymentMethodId
30170
30222
  }
@@ -30176,7 +30228,7 @@ const PaymentMethodDeleteSubmit = _ref => {
30176
30228
  });
30177
30229
  onClick === null || onClick === void 0 ? void 0 : onClick();
30178
30230
  },
30179
- disabled: showPaymentMethodSelect ? isDisabled || !selectedPaymentMethodId : isDisabled,
30231
+ disabled: showPaymentMethodSelect ? !selectedPaymentMethodId : disableSubmit,
30180
30232
  isLoading: isLoading,
30181
30233
  className: "plc-w-full"
30182
30234
  }, otherProps), name !== null && name !== void 0 ? name : t("delete.buttons.delete"));
package/dist/index.esm.js CHANGED
@@ -9896,6 +9896,19 @@ function generatePassword() {
9896
9896
  }
9897
9897
  return retVal;
9898
9898
  }
9899
+ const refreshUser = () => {
9900
+ var _window$Pelcro6, _window$Pelcro6$user, _window$Pelcro6$user$;
9901
+ window.Pelcro.user.refresh({
9902
+ auth_token: (_window$Pelcro6 = window.Pelcro) === null || _window$Pelcro6 === void 0 ? void 0 : (_window$Pelcro6$user = _window$Pelcro6.user) === null || _window$Pelcro6$user === void 0 ? void 0 : (_window$Pelcro6$user$ = _window$Pelcro6$user.read()) === null || _window$Pelcro6$user$ === void 0 ? void 0 : _window$Pelcro6$user$.auth_token
9903
+ }, (err, res) => {
9904
+ if (err) {
9905
+ console.error(err);
9906
+ }
9907
+ if (res) {
9908
+ return res.data;
9909
+ }
9910
+ });
9911
+ };
9899
9912
 
9900
9913
  const resources = {
9901
9914
  en: {
@@ -19625,6 +19638,7 @@ const PaymentMethodContainerWithoutStripe = _ref => {
19625
19638
  content: t("messages.sourceCreated")
19626
19639
  }
19627
19640
  });
19641
+ refreshUser();
19628
19642
  onSuccess(res);
19629
19643
  });
19630
19644
  }
@@ -19679,6 +19693,7 @@ const PaymentMethodContainerWithoutStripe = _ref => {
19679
19693
  }
19680
19694
  });
19681
19695
  }
19696
+ refreshUser();
19682
19697
  onSuccess(res);
19683
19698
  });
19684
19699
  }, 2000);
@@ -19740,6 +19755,7 @@ const PaymentMethodContainerWithoutStripe = _ref => {
19740
19755
  content: t("messages.sourceUpdated")
19741
19756
  }
19742
19757
  });
19758
+ refreshUser();
19743
19759
  onSuccess(res);
19744
19760
  });
19745
19761
  }
@@ -20326,6 +20342,7 @@ const PaymentMethodContainerWithoutStripe = _ref => {
20326
20342
  type: LOADING,
20327
20343
  payload: false
20328
20344
  });
20345
+ refreshUser();
20329
20346
  onSuccess(res);
20330
20347
  return;
20331
20348
  }
@@ -20341,6 +20358,7 @@ const PaymentMethodContainerWithoutStripe = _ref => {
20341
20358
  content: t("messages.sourceCreated")
20342
20359
  }
20343
20360
  });
20361
+ refreshUser();
20344
20362
  onSuccess(res);
20345
20363
  return;
20346
20364
  }
@@ -20360,6 +20378,7 @@ const PaymentMethodContainerWithoutStripe = _ref => {
20360
20378
  content: t("messages.sourceUpdated")
20361
20379
  }
20362
20380
  });
20381
+ refreshUser();
20363
20382
  onSuccess(res);
20364
20383
  return;
20365
20384
  }
@@ -20387,6 +20406,7 @@ const PaymentMethodContainerWithoutStripe = _ref => {
20387
20406
  }
20388
20407
  });
20389
20408
  }
20409
+ refreshUser();
20390
20410
  onSuccess(res);
20391
20411
  });
20392
20412
  }, 2000);
@@ -20418,7 +20438,8 @@ const PaymentMethodContainerWithoutStripe = _ref => {
20418
20438
  gift_message: giftRecipient === null || giftRecipient === void 0 ? void 0 : giftRecipient.giftMessage,
20419
20439
  address_id: product.address_required ? selectedAddressId : null
20420
20440
  }, (err, res) => {
20421
- if (res.data.setup_intent) {
20441
+ var _res$data;
20442
+ if (res !== null && res !== void 0 && (_res$data = res.data) !== null && _res$data !== void 0 && _res$data.setup_intent) {
20422
20443
  return confirmStripeIntentSetup(res, "subCreate");
20423
20444
  }
20424
20445
  confirmStripeCardPayment(res, err, true);
@@ -20707,7 +20728,7 @@ const PaymentMethodContainerWithoutStripe = _ref => {
20707
20728
  auth_token: window.Pelcro.user.read().auth_token,
20708
20729
  token: source.id
20709
20730
  }, (err, res) => {
20710
- var _res$data, _res$data$setup_inten, _res$data2, _res$data2$setup_inte;
20731
+ var _res$data2, _res$data2$setup_inte, _res$data3, _res$data3$setup_inte;
20711
20732
  if (err) {
20712
20733
  dispatch({
20713
20734
  type: DISABLE_SUBMIT,
@@ -20726,7 +20747,7 @@ const PaymentMethodContainerWithoutStripe = _ref => {
20726
20747
  }
20727
20748
  });
20728
20749
  }
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") {
20750
+ 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
20751
  confirmStripeIntentSetup(res, "create");
20731
20752
  } else {
20732
20753
  dispatch({
@@ -20740,6 +20761,7 @@ const PaymentMethodContainerWithoutStripe = _ref => {
20740
20761
  content: t("messages.sourceCreated")
20741
20762
  }
20742
20763
  });
20764
+ refreshUser();
20743
20765
  onSuccess(res);
20744
20766
  }
20745
20767
  });
@@ -20762,7 +20784,7 @@ const PaymentMethodContainerWithoutStripe = _ref => {
20762
20784
  exp_year: year,
20763
20785
  is_default: isDefault
20764
20786
  }, (err, res) => {
20765
- var _res$data3, _res$data3$setup_inte, _res$data4, _res$data4$setup_inte;
20787
+ var _res$data4, _res$data4$setup_inte, _res$data5, _res$data5$setup_inte;
20766
20788
  dispatch({
20767
20789
  type: DISABLE_SUBMIT,
20768
20790
  payload: false
@@ -20781,7 +20803,7 @@ const PaymentMethodContainerWithoutStripe = _ref => {
20781
20803
  }
20782
20804
  });
20783
20805
  }
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") {
20806
+ 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
20807
  confirmStripeIntentSetup(res, "update");
20786
20808
  } else {
20787
20809
  dispatch({
@@ -20791,6 +20813,7 @@ const PaymentMethodContainerWithoutStripe = _ref => {
20791
20813
  content: t("messages.sourceUpdated")
20792
20814
  }
20793
20815
  });
20816
+ refreshUser();
20794
20817
  onSuccess(res);
20795
20818
  }
20796
20819
  });
@@ -20823,7 +20846,7 @@ const PaymentMethodContainerWithoutStripe = _ref => {
20823
20846
  auth_token: window.Pelcro.user.read().auth_token,
20824
20847
  token: source.id
20825
20848
  }, (err, res) => {
20826
- var _res$data5, _res$data5$setup_inte, _res$data6, _res$data6$setup_inte;
20849
+ var _res$data6, _res$data6$setup_inte, _res$data7, _res$data7$setup_inte;
20827
20850
  if (err) {
20828
20851
  onFailure(err);
20829
20852
  return dispatch({
@@ -20834,7 +20857,7 @@ const PaymentMethodContainerWithoutStripe = _ref => {
20834
20857
  }
20835
20858
  });
20836
20859
  }
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") {
20860
+ 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
20861
  confirmStripeIntentSetup(res, "replace", paymentMethodId);
20839
20862
  } else {
20840
20863
  setTimeout(() => {
@@ -20860,6 +20883,7 @@ const PaymentMethodContainerWithoutStripe = _ref => {
20860
20883
  }
20861
20884
  });
20862
20885
  }
20886
+ refreshUser();
20863
20887
  onSuccess(res);
20864
20888
  });
20865
20889
  }, 2000);
@@ -20999,12 +21023,12 @@ const PaymentMethodContainerWithoutStripe = _ref => {
20999
21023
  coupon_code: state === null || state === void 0 ? void 0 : state.couponCode,
21000
21024
  address_id: selectedAddressId
21001
21025
  }, (error, res) => {
21002
- var _res$data7, _res$data8;
21026
+ var _res$data8, _res$data9;
21003
21027
  if (error) {
21004
21028
  return reject(error);
21005
21029
  }
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;
21030
+ const taxAmount = (_res$data8 = res.data) === null || _res$data8 === void 0 ? void 0 : _res$data8.taxes;
21031
+ const totalAmountWithTax = (_res$data9 = res.data) === null || _res$data9 === void 0 ? void 0 : _res$data9.total;
21008
21032
  resolve({
21009
21033
  totalAmountWithTax,
21010
21034
  taxAmount
@@ -29612,17 +29636,21 @@ const AddressSelectModal = _ref => {
29612
29636
  AddressSelectModal.viewId = "address-select";
29613
29637
 
29614
29638
  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;
29639
+ const defaultPaymentMethod = getDefaultPaymentMethod(paymentMethods);
29617
29640
  const paymentMethodsWithoutDefault = paymentMethods.filter(paymentMethod => paymentMethod.id !== defaultPaymentMethod.id);
29618
29641
  if (defaultPaymentMethod.status !== "chargeable") {
29619
29642
  return paymentMethodsWithoutDefault;
29620
29643
  }
29621
29644
  return [defaultPaymentMethod, ...paymentMethodsWithoutDefault];
29622
29645
  };
29646
+ const getDefaultPaymentMethod = paymentMethods => {
29647
+ const defaultPaymentMethod = paymentMethods.find(paymentMethod => paymentMethod.is_default);
29648
+ return defaultPaymentMethod;
29649
+ };
29623
29650
  const initialState$5 = {
29624
29651
  paymentMethods: [],
29625
29652
  selectedPaymentMethodId: null,
29653
+ skeletonLoader: true,
29626
29654
  isSubmitting: false,
29627
29655
  alert: {
29628
29656
  type: "error",
@@ -29653,12 +29681,11 @@ const PaymentMethodSelectContainer = _ref => {
29653
29681
  });
29654
29682
  return onSuccess(selectedPaymentMethodId);
29655
29683
  };
29656
- const getInitialSelectedMethodId = () => {
29657
- var _window$Pelcro$user$r2;
29684
+ const getInitialSelectedMethodId = paymentMethods => {
29658
29685
  if (selectedPaymentMethodIdFromStore) {
29659
29686
  return selectedPaymentMethodIdFromStore;
29660
29687
  }
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;
29688
+ const defaultMethod = getDefaultPaymentMethod(paymentMethods);
29662
29689
  if (defaultMethod && defaultMethod.status === "chargeable") {
29663
29690
  return String(defaultMethod.id);
29664
29691
  }
@@ -29675,7 +29702,12 @@ const PaymentMethodSelectContainer = _ref => {
29675
29702
  return lib_7({
29676
29703
  ...state,
29677
29704
  paymentMethods: moveDefaultPaymentMethodToStart(action.payload),
29678
- selectedPaymentMethodId: getInitialSelectedMethodId()
29705
+ selectedPaymentMethodId: getInitialSelectedMethodId(action.payload)
29706
+ });
29707
+ case SKELETON_LOADER:
29708
+ return lib_7({
29709
+ ...state,
29710
+ skeletonLoader: action.payload
29679
29711
  });
29680
29712
  case HANDLE_SUBMIT:
29681
29713
  return lib_5({
@@ -29687,10 +29719,23 @@ const PaymentMethodSelectContainer = _ref => {
29687
29719
  }
29688
29720
  }, initialState$5);
29689
29721
  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 : []
29722
+ window.Pelcro.paymentMethods.list({
29723
+ auth_token: window.Pelcro.user.read().auth_token
29724
+ }, (err, res) => {
29725
+ if (err) {
29726
+ return console.error(err);
29727
+ }
29728
+ if (res) {
29729
+ var _res$data;
29730
+ dispatch({
29731
+ type: LOAD_PAYMENT_METHODS,
29732
+ payload: (_res$data = res.data) !== null && _res$data !== void 0 ? _res$data : []
29733
+ });
29734
+ dispatch({
29735
+ type: SKELETON_LOADER,
29736
+ payload: false
29737
+ });
29738
+ }
29694
29739
  });
29695
29740
  }, []);
29696
29741
  return /*#__PURE__*/React__default.createElement("div", {
@@ -29719,7 +29764,8 @@ const PaymentMethodSelectList = () => {
29719
29764
  dispatch,
29720
29765
  state: {
29721
29766
  paymentMethods,
29722
- selectedPaymentMethodId
29767
+ selectedPaymentMethodId,
29768
+ skeletonLoader
29723
29769
  }
29724
29770
  } = useContext(store$5);
29725
29771
  const handlePaymentMethodSelect = event => {
@@ -29728,7 +29774,9 @@ const PaymentMethodSelectList = () => {
29728
29774
  payload: event.target.value
29729
29775
  });
29730
29776
  };
29731
- return /*#__PURE__*/React__default.createElement("div", {
29777
+ return /*#__PURE__*/React__default.createElement("div", null, skeletonLoader ? /*#__PURE__*/React__default.createElement("div", {
29778
+ className: "plc-w-full plc-h-20 plc-bg-gray-300 plc-rounded-md plc-animate-pulse"
29779
+ }) : /*#__PURE__*/React__default.createElement("div", {
29732
29780
  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
29781
  }, paymentMethods.map(paymentMethod => {
29734
29782
  var _paymentMethod$proper, _paymentMethod$proper2, _paymentMethod$proper3, _paymentMethod$proper4;
@@ -29751,7 +29799,7 @@ const PaymentMethodSelectList = () => {
29751
29799
  }, "\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
29800
  className: "plc-text-sm plc-text-gray-500"
29753
29801
  }, 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
- }));
29802
+ })));
29755
29803
  };
29756
29804
 
29757
29805
  const PaymentMethodSelectSubmit = _ref => {
@@ -29853,7 +29901,7 @@ const initialState$4 = {
29853
29901
  paymentMethods: [],
29854
29902
  selectedPaymentMethodId: null,
29855
29903
  isSubmitting: false,
29856
- disableSubmit: false,
29904
+ disableSubmit: true,
29857
29905
  isLoading: false,
29858
29906
  skeletonLoader: true,
29859
29907
  showPaymentMethodSelect: false,
@@ -29899,6 +29947,10 @@ const PaymentMethodDeleteContainer = _ref => {
29899
29947
  payload: true
29900
29948
  });
29901
29949
  }
29950
+ dispatch({
29951
+ type: DISABLE_SUBMIT,
29952
+ payload: false
29953
+ });
29902
29954
  }
29903
29955
  });
29904
29956
  }, [paymentMethodToDelete]); // eslint-disable-line react-hooks/exhaustive-deps
@@ -29912,15 +29964,15 @@ const PaymentMethodDeleteContainer = _ref => {
29912
29964
  payment_method_id: paymentMethodId,
29913
29965
  is_default: true
29914
29966
  }, (err, res) => {
29915
- dispatch({
29916
- type: DISABLE_SUBMIT,
29917
- payload: false
29918
- });
29919
- dispatch({
29920
- type: LOADING,
29921
- payload: false
29922
- });
29923
29967
  if (err) {
29968
+ dispatch({
29969
+ type: DISABLE_SUBMIT,
29970
+ payload: false
29971
+ });
29972
+ dispatch({
29973
+ type: LOADING,
29974
+ payload: false
29975
+ });
29924
29976
  console.log(err);
29925
29977
  onFailure(err);
29926
29978
  return dispatch({
@@ -30134,7 +30186,7 @@ const PaymentMethodDeleteSubmit = _ref => {
30134
30186
  dispatch,
30135
30187
  state: {
30136
30188
  isLoading,
30137
- isDisabled,
30189
+ disableSubmit,
30138
30190
  showPaymentMethodSelect,
30139
30191
  selectedPaymentMethodId
30140
30192
  }
@@ -30146,7 +30198,7 @@ const PaymentMethodDeleteSubmit = _ref => {
30146
30198
  });
30147
30199
  onClick === null || onClick === void 0 ? void 0 : onClick();
30148
30200
  },
30149
- disabled: showPaymentMethodSelect ? isDisabled || !selectedPaymentMethodId : isDisabled,
30201
+ disabled: showPaymentMethodSelect ? !selectedPaymentMethodId : disableSubmit,
30150
30202
  isLoading: isLoading,
30151
30203
  className: "plc-w-full"
30152
30204
  }, 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.58",
5
5
  "license": "MIT",
6
6
  "private": false,
7
7
  "main": "dist/index.cjs.js",