@pelcro/react-pelcro-js 3.26.0-beta.43 → 3.26.0-beta.45

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
@@ -3251,7 +3251,8 @@ var validation$3 = {
3251
3251
  confirmPassword: "Confirm password is required.",
3252
3252
  enterFirstName: "First name is required.",
3253
3253
  enterLastName: "Last name is required.",
3254
- enterPhone: "Phone number is required."
3254
+ enterPhone: "Phone number is required.",
3255
+ enterFieldName: "{{fieldName}} is required."
3255
3256
  };
3256
3257
  var buttons$n = {
3257
3258
  account: "My account",
@@ -4204,7 +4205,8 @@ var validation$2 = {
4204
4205
  confirmPassword: "Confirmer le mot de passe requis.",
4205
4206
  enterFirstName: "Le prénom est requis.",
4206
4207
  enterLastName: "Le nom de famille est requis.",
4207
- enterPhone: "Le numéro de téléphone est requis."
4208
+ enterPhone: "Le numéro de téléphone est requis.",
4209
+ enterFieldName: "{{fieldName}} est requis."
4208
4210
  };
4209
4211
  var buttons$h = {
4210
4212
  account: "Accès abonné(e)s",
@@ -5147,7 +5149,8 @@ var validation$1 = {
5147
5149
  enterPassword: "비밀번호는 필수 항목입니다.",
5148
5150
  enterFirstName: "이름은 필수 항목입니다.",
5149
5151
  enterLastName: "성은 필수 항목입니다.",
5150
- enterPhone: "전화번호는 필수 항목입니다."
5152
+ enterPhone: "전화번호는 필수 항목입니다.",
5153
+ enterFieldName: "{{fieldName}} 필수."
5151
5154
  };
5152
5155
  var buttons$b = {
5153
5156
  account: "내 계정",
@@ -6196,7 +6199,8 @@ var validation = {
6196
6199
  confirmPassword: "Confirmar la contraseña es obligatorio.",
6197
6200
  enterFirstName: "El nombre es obligatorio.",
6198
6201
  enterLastName: "El apellido es obligatorio.",
6199
- enterPhone: "El número de teléfono es obligatorio."
6202
+ enterPhone: "El número de teléfono es obligatorio.",
6203
+ enterFieldName: "{{fieldName}} es obligatorio."
6200
6204
  };
6201
6205
  var buttons$5 = {
6202
6206
  account: "Mi cuenta",
@@ -12890,6 +12894,7 @@ const SET_FIRST_NAME_ERROR = "SET_FIRST_NAME_ERROR";
12890
12894
  const SET_LAST_NAME_ERROR = "SET_LAST_NAME_ERROR";
12891
12895
  const SET_PHONE_ERROR = "SET_PHONE_ERROR";
12892
12896
  const SET_TEXT_FIELD = "SET_TEXT_FIELD";
12897
+ const SET_TEXT_FIELD_ERROR = "SET_TEXT_FIELD_ERROR";
12893
12898
  const SET_MONTH = "SET_MONTH";
12894
12899
  const SET_YEAR = "SET_YEAR";
12895
12900
  const SET_TOKEN = "SET_TOKEN";
@@ -13839,6 +13844,11 @@ const RegisterContainer = _ref => {
13839
13844
  phoneError: action.payload,
13840
13845
  phone: null
13841
13846
  });
13847
+ case SET_TEXT_FIELD_ERROR:
13848
+ return lib_7({
13849
+ ...state,
13850
+ ...action.payload
13851
+ });
13842
13852
  case SET_CONFIRM_PASSWORD_ERROR:
13843
13853
  return lib_7({
13844
13854
  ...state,
@@ -14989,26 +14999,69 @@ function TextInput(_ref) {
14989
14999
  fieldName,
14990
15000
  ...otherProps
14991
15001
  } = _ref;
15002
+ const {
15003
+ t
15004
+ } = useTranslation("common");
14992
15005
  const {
14993
15006
  dispatch,
14994
- state
15007
+ state: {
15008
+ [fieldName]: stateFieldName,
15009
+ [fieldName + "Error"]: fieldNameError,
15010
+ loading
15011
+ }
14995
15012
  } = React.useContext(store);
14996
- const handleInputChange = value => {
14997
- dispatch({
14998
- type: SET_TEXT_FIELD,
14999
- payload: {
15000
- [fieldName]: value
15013
+ const [fieldNameState, setFieldNameState] = React.useState(stateFieldName);
15014
+ const [finishedTyping, setFinishedTyping] = React.useState(false);
15015
+ const handleInputChange = React.useCallback(value => {
15016
+ setFieldNameState(value);
15017
+ if (finishedTyping) {
15018
+ if (fieldNameState !== null && fieldNameState !== void 0 && fieldNameState.length) {
15019
+ dispatch({
15020
+ type: SET_TEXT_FIELD,
15021
+ payload: {
15022
+ [fieldName]: value,
15023
+ [fieldName + "Error"]: null
15024
+ }
15025
+ });
15026
+ } else {
15027
+ if (otherProps.required) {
15028
+ dispatch({
15029
+ type: SET_TEXT_FIELD_ERROR,
15030
+ payload: {
15031
+ [fieldName + "Error"]: t("validation.enterFieldName", {
15032
+ fieldName: otherProps.label
15033
+ }),
15034
+ [fieldName]: null
15035
+ }
15036
+ });
15037
+ } else {
15038
+ dispatch({
15039
+ type: SET_TEXT_FIELD,
15040
+ payload: {
15041
+ [fieldName]: value,
15042
+ [fieldName + "Error"]: null
15043
+ }
15044
+ });
15045
+ }
15001
15046
  }
15002
- });
15003
- };
15004
- if (state.loading) {
15047
+ }
15048
+ }, [dispatch, fieldNameState, finishedTyping] // eslint-disable-line react-hooks/exhaustive-deps
15049
+ );
15050
+
15051
+ React.useEffect(() => {
15052
+ handleInputChange(fieldNameState);
15053
+ }, [finishedTyping, fieldNameState, handleInputChange]);
15054
+ if (loading) {
15005
15055
  return /*#__PURE__*/React__default['default'].createElement(Loader, null);
15006
15056
  }
15007
15057
  return /*#__PURE__*/React__default['default'].createElement(Input, Object.assign({
15008
15058
  type: "text",
15009
- value: state[fieldName],
15059
+ error: fieldNameError,
15060
+ value: fieldNameState,
15010
15061
  defaultValue: (_window$Pelcro$user$r = window.Pelcro.user.read()) === null || _window$Pelcro$user$r === void 0 ? void 0 : (_window$Pelcro$user$r2 = _window$Pelcro$user$r.metadata) === null || _window$Pelcro$user$r2 === void 0 ? void 0 : _window$Pelcro$user$r2[fieldName],
15011
- onChange: e => handleInputChange(e.target.value)
15062
+ onChange: e => handleInputChange(e.target.value),
15063
+ onBlur: () => setFinishedTyping(true),
15064
+ onFocus: () => setFinishedTyping(false)
15012
15065
  }, otherProps));
15013
15066
  }
15014
15067
 
@@ -19615,6 +19668,102 @@ const PaymentMethodContainerWithoutStripe = _ref => {
19615
19668
  onSuccess(response);
19616
19669
  }
19617
19670
  };
19671
+ const confirmStripeIntentSetup = (response, flow, paymentMethodId) => {
19672
+ var _response$data2;
19673
+ const setupIntent = (_response$data2 = response.data) === null || _response$data2 === void 0 ? void 0 : _response$data2.setup_intent;
19674
+ if (setupIntent !== null && setupIntent !== void 0 && setupIntent.client_secret) {
19675
+ var _response$data3, _response$data3$sourc;
19676
+ stripe.confirmCardSetup(setupIntent.client_secret, {
19677
+ payment_method: (_response$data3 = response.data) === null || _response$data3 === void 0 ? void 0 : (_response$data3$sourc = _response$data3.source) === null || _response$data3$sourc === void 0 ? void 0 : _response$data3$sourc.object_id
19678
+ }).then(res => {
19679
+ var _response$data4;
19680
+ if (res.error) {
19681
+ dispatch({
19682
+ type: LOADING,
19683
+ payload: false
19684
+ });
19685
+ onFailure(res.error);
19686
+ return dispatch({
19687
+ type: SHOW_ALERT,
19688
+ payload: {
19689
+ type: "error",
19690
+ content: getErrorMessages(res.error)
19691
+ }
19692
+ });
19693
+ }
19694
+ if (flow === "create") {
19695
+ dispatch({
19696
+ type: DISABLE_SUBMIT,
19697
+ payload: false
19698
+ });
19699
+ dispatch({
19700
+ type: LOADING,
19701
+ payload: false
19702
+ });
19703
+ dispatch({
19704
+ type: SHOW_ALERT,
19705
+ payload: {
19706
+ type: "success",
19707
+ content: t("messages.sourceCreated")
19708
+ }
19709
+ });
19710
+ onSuccess(res);
19711
+ return;
19712
+ }
19713
+ if (flow === "update") {
19714
+ dispatch({
19715
+ type: DISABLE_SUBMIT,
19716
+ payload: false
19717
+ });
19718
+ dispatch({
19719
+ type: LOADING,
19720
+ payload: false
19721
+ });
19722
+ dispatch({
19723
+ type: SHOW_ALERT,
19724
+ payload: {
19725
+ type: "success",
19726
+ content: t("messages.sourceUpdated")
19727
+ }
19728
+ });
19729
+ onSuccess(res);
19730
+ return;
19731
+ }
19732
+ if (flow === "replace") {
19733
+ setTimeout(() => {
19734
+ window.Pelcro.paymentMethods.deletePaymentMethod({
19735
+ auth_token: window.Pelcro.user.read().auth_token,
19736
+ payment_method_id: paymentMethodId
19737
+ }, (err, res) => {
19738
+ dispatch({
19739
+ type: DISABLE_SUBMIT,
19740
+ payload: false
19741
+ });
19742
+ dispatch({
19743
+ type: LOADING,
19744
+ payload: false
19745
+ });
19746
+ if (err) {
19747
+ onFailure === null || onFailure === void 0 ? void 0 : onFailure(err);
19748
+ return dispatch({
19749
+ type: SHOW_ALERT,
19750
+ payload: {
19751
+ type: "error",
19752
+ content: getErrorMessages(err)
19753
+ }
19754
+ });
19755
+ }
19756
+ onSuccess(res);
19757
+ });
19758
+ }, 2000);
19759
+ return;
19760
+ }
19761
+ return handlePayment(response === null || response === void 0 ? void 0 : (_response$data4 = response.data) === null || _response$data4 === void 0 ? void 0 : _response$data4.source);
19762
+ });
19763
+ } else {
19764
+ onSuccess(response);
19765
+ }
19766
+ };
19618
19767
  const subscribe = (stripeSource, state, dispatch) => {
19619
19768
  const {
19620
19769
  couponCode
@@ -19900,7 +20049,6 @@ const PaymentMethodContainerWithoutStripe = _ref => {
19900
20049
  return stripe.createSource({
19901
20050
  type: "card"
19902
20051
  }).then(_ref8 => {
19903
- var _source$card2;
19904
20052
  let {
19905
20053
  source,
19906
20054
  error
@@ -19910,17 +20058,19 @@ const PaymentMethodContainerWithoutStripe = _ref => {
19910
20058
  }
19911
20059
 
19912
20060
  // We don't support source creation for 3D secure yet
19913
- if ((source === null || source === void 0 ? void 0 : (_source$card2 = source.card) === null || _source$card2 === void 0 ? void 0 : _source$card2.three_d_secure) === "required") {
19914
- return handlePaymentError({
19915
- error: {
19916
- message: t("messages.cardAuthNotSupported")
19917
- }
19918
- });
19919
- }
20061
+ // if (source?.card?.three_d_secure === "required") {
20062
+ // return handlePaymentError({
20063
+ // error: {
20064
+ // message: t("messages.cardAuthNotSupported")
20065
+ // }
20066
+ // });
20067
+ // }
20068
+
19920
20069
  window.Pelcro.paymentMethods.create({
19921
20070
  auth_token: window.Pelcro.user.read().auth_token,
19922
20071
  token: source.id
19923
20072
  }, (err, res) => {
20073
+ var _res$data, _res$data$setup_inten, _res$data2, _res$data2$setup_inte;
19924
20074
  dispatch({
19925
20075
  type: DISABLE_SUBMIT,
19926
20076
  payload: false
@@ -19939,14 +20089,18 @@ const PaymentMethodContainerWithoutStripe = _ref => {
19939
20089
  }
19940
20090
  });
19941
20091
  }
19942
- dispatch({
19943
- type: SHOW_ALERT,
19944
- payload: {
19945
- type: "success",
19946
- content: t("messages.sourceCreated")
19947
- }
19948
- });
19949
- onSuccess(res);
20092
+ 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") {
20093
+ confirmStripeIntentSetup(res, "create");
20094
+ } else {
20095
+ dispatch({
20096
+ type: SHOW_ALERT,
20097
+ payload: {
20098
+ type: "success",
20099
+ content: t("messages.sourceCreated")
20100
+ }
20101
+ });
20102
+ onSuccess(res);
20103
+ }
19950
20104
  });
19951
20105
  });
19952
20106
  };
@@ -19967,6 +20121,7 @@ const PaymentMethodContainerWithoutStripe = _ref => {
19967
20121
  exp_year: year,
19968
20122
  is_default: isDefault
19969
20123
  }, (err, res) => {
20124
+ var _res$data3, _res$data3$setup_inte, _res$data4, _res$data4$setup_inte;
19970
20125
  dispatch({
19971
20126
  type: DISABLE_SUBMIT,
19972
20127
  payload: false
@@ -19985,14 +20140,18 @@ const PaymentMethodContainerWithoutStripe = _ref => {
19985
20140
  }
19986
20141
  });
19987
20142
  }
19988
- dispatch({
19989
- type: SHOW_ALERT,
19990
- payload: {
19991
- type: "success",
19992
- content: t("messages.sourceUpdated")
19993
- }
19994
- });
19995
- onSuccess(res);
20143
+ 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") {
20144
+ confirmStripeIntentSetup(res, "update");
20145
+ } else {
20146
+ dispatch({
20147
+ type: SHOW_ALERT,
20148
+ payload: {
20149
+ type: "success",
20150
+ content: t("messages.sourceUpdated")
20151
+ }
20152
+ });
20153
+ onSuccess(res);
20154
+ }
19996
20155
  });
19997
20156
  };
19998
20157
  const replacePaymentSource = (state, dispatch) => {
@@ -20002,7 +20161,6 @@ const PaymentMethodContainerWithoutStripe = _ref => {
20002
20161
  return stripe.createSource({
20003
20162
  type: "card"
20004
20163
  }).then(_ref9 => {
20005
- var _source$card3;
20006
20164
  let {
20007
20165
  source,
20008
20166
  error
@@ -20012,17 +20170,19 @@ const PaymentMethodContainerWithoutStripe = _ref => {
20012
20170
  }
20013
20171
 
20014
20172
  // We don't support source creation for 3D secure yet
20015
- if ((source === null || source === void 0 ? void 0 : (_source$card3 = source.card) === null || _source$card3 === void 0 ? void 0 : _source$card3.three_d_secure) === "required") {
20016
- return handlePaymentError({
20017
- error: {
20018
- message: t("messages.cardAuthNotSupported")
20019
- }
20020
- });
20021
- }
20173
+ // if (source?.card?.three_d_secure === "required") {
20174
+ // return handlePaymentError({
20175
+ // error: {
20176
+ // message: t("messages.cardAuthNotSupported")
20177
+ // }
20178
+ // });
20179
+ // }
20180
+
20022
20181
  window.Pelcro.paymentMethods.create({
20023
20182
  auth_token: window.Pelcro.user.read().auth_token,
20024
20183
  token: source.id
20025
20184
  }, (err, res) => {
20185
+ var _res$data5, _res$data5$setup_inte, _res$data6, _res$data6$setup_inte;
20026
20186
  if (err) {
20027
20187
  onFailure(err);
20028
20188
  return dispatch({
@@ -20033,7 +20193,9 @@ const PaymentMethodContainerWithoutStripe = _ref => {
20033
20193
  }
20034
20194
  });
20035
20195
  }
20036
- if (res) {
20196
+ 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") {
20197
+ confirmStripeIntentSetup(res, "replace", paymentMethodId);
20198
+ } else {
20037
20199
  setTimeout(() => {
20038
20200
  window.Pelcro.paymentMethods.deletePaymentMethod({
20039
20201
  auth_token: window.Pelcro.user.read().auth_token,
@@ -20196,12 +20358,12 @@ const PaymentMethodContainerWithoutStripe = _ref => {
20196
20358
  coupon_code: state === null || state === void 0 ? void 0 : state.couponCode,
20197
20359
  address_id: selectedAddressId
20198
20360
  }, (error, res) => {
20199
- var _res$data, _res$data2;
20361
+ var _res$data7, _res$data8;
20200
20362
  if (error) {
20201
20363
  return reject(error);
20202
20364
  }
20203
- const taxAmount = (_res$data = res.data) === null || _res$data === void 0 ? void 0 : _res$data.taxes;
20204
- const totalAmountWithTax = (_res$data2 = res.data) === null || _res$data2 === void 0 ? void 0 : _res$data2.total;
20365
+ const taxAmount = (_res$data7 = res.data) === null || _res$data7 === void 0 ? void 0 : _res$data7.taxes;
20366
+ const totalAmountWithTax = (_res$data8 = res.data) === null || _res$data8 === void 0 ? void 0 : _res$data8.total;
20205
20367
  resolve({
20206
20368
  totalAmountWithTax,
20207
20369
  taxAmount
package/dist/index.esm.js CHANGED
@@ -3221,7 +3221,8 @@ var validation$3 = {
3221
3221
  confirmPassword: "Confirm password is required.",
3222
3222
  enterFirstName: "First name is required.",
3223
3223
  enterLastName: "Last name is required.",
3224
- enterPhone: "Phone number is required."
3224
+ enterPhone: "Phone number is required.",
3225
+ enterFieldName: "{{fieldName}} is required."
3225
3226
  };
3226
3227
  var buttons$n = {
3227
3228
  account: "My account",
@@ -4174,7 +4175,8 @@ var validation$2 = {
4174
4175
  confirmPassword: "Confirmer le mot de passe requis.",
4175
4176
  enterFirstName: "Le prénom est requis.",
4176
4177
  enterLastName: "Le nom de famille est requis.",
4177
- enterPhone: "Le numéro de téléphone est requis."
4178
+ enterPhone: "Le numéro de téléphone est requis.",
4179
+ enterFieldName: "{{fieldName}} est requis."
4178
4180
  };
4179
4181
  var buttons$h = {
4180
4182
  account: "Accès abonné(e)s",
@@ -5117,7 +5119,8 @@ var validation$1 = {
5117
5119
  enterPassword: "비밀번호는 필수 항목입니다.",
5118
5120
  enterFirstName: "이름은 필수 항목입니다.",
5119
5121
  enterLastName: "성은 필수 항목입니다.",
5120
- enterPhone: "전화번호는 필수 항목입니다."
5122
+ enterPhone: "전화번호는 필수 항목입니다.",
5123
+ enterFieldName: "{{fieldName}} 필수."
5121
5124
  };
5122
5125
  var buttons$b = {
5123
5126
  account: "내 계정",
@@ -6166,7 +6169,8 @@ var validation = {
6166
6169
  confirmPassword: "Confirmar la contraseña es obligatorio.",
6167
6170
  enterFirstName: "El nombre es obligatorio.",
6168
6171
  enterLastName: "El apellido es obligatorio.",
6169
- enterPhone: "El número de teléfono es obligatorio."
6172
+ enterPhone: "El número de teléfono es obligatorio.",
6173
+ enterFieldName: "{{fieldName}} es obligatorio."
6170
6174
  };
6171
6175
  var buttons$5 = {
6172
6176
  account: "Mi cuenta",
@@ -12860,6 +12864,7 @@ const SET_FIRST_NAME_ERROR = "SET_FIRST_NAME_ERROR";
12860
12864
  const SET_LAST_NAME_ERROR = "SET_LAST_NAME_ERROR";
12861
12865
  const SET_PHONE_ERROR = "SET_PHONE_ERROR";
12862
12866
  const SET_TEXT_FIELD = "SET_TEXT_FIELD";
12867
+ const SET_TEXT_FIELD_ERROR = "SET_TEXT_FIELD_ERROR";
12863
12868
  const SET_MONTH = "SET_MONTH";
12864
12869
  const SET_YEAR = "SET_YEAR";
12865
12870
  const SET_TOKEN = "SET_TOKEN";
@@ -13809,6 +13814,11 @@ const RegisterContainer = _ref => {
13809
13814
  phoneError: action.payload,
13810
13815
  phone: null
13811
13816
  });
13817
+ case SET_TEXT_FIELD_ERROR:
13818
+ return lib_7({
13819
+ ...state,
13820
+ ...action.payload
13821
+ });
13812
13822
  case SET_CONFIRM_PASSWORD_ERROR:
13813
13823
  return lib_7({
13814
13824
  ...state,
@@ -14959,26 +14969,69 @@ function TextInput(_ref) {
14959
14969
  fieldName,
14960
14970
  ...otherProps
14961
14971
  } = _ref;
14972
+ const {
14973
+ t
14974
+ } = useTranslation("common");
14962
14975
  const {
14963
14976
  dispatch,
14964
- state
14977
+ state: {
14978
+ [fieldName]: stateFieldName,
14979
+ [fieldName + "Error"]: fieldNameError,
14980
+ loading
14981
+ }
14965
14982
  } = useContext(store);
14966
- const handleInputChange = value => {
14967
- dispatch({
14968
- type: SET_TEXT_FIELD,
14969
- payload: {
14970
- [fieldName]: value
14983
+ const [fieldNameState, setFieldNameState] = useState(stateFieldName);
14984
+ const [finishedTyping, setFinishedTyping] = useState(false);
14985
+ const handleInputChange = useCallback(value => {
14986
+ setFieldNameState(value);
14987
+ if (finishedTyping) {
14988
+ if (fieldNameState !== null && fieldNameState !== void 0 && fieldNameState.length) {
14989
+ dispatch({
14990
+ type: SET_TEXT_FIELD,
14991
+ payload: {
14992
+ [fieldName]: value,
14993
+ [fieldName + "Error"]: null
14994
+ }
14995
+ });
14996
+ } else {
14997
+ if (otherProps.required) {
14998
+ dispatch({
14999
+ type: SET_TEXT_FIELD_ERROR,
15000
+ payload: {
15001
+ [fieldName + "Error"]: t("validation.enterFieldName", {
15002
+ fieldName: otherProps.label
15003
+ }),
15004
+ [fieldName]: null
15005
+ }
15006
+ });
15007
+ } else {
15008
+ dispatch({
15009
+ type: SET_TEXT_FIELD,
15010
+ payload: {
15011
+ [fieldName]: value,
15012
+ [fieldName + "Error"]: null
15013
+ }
15014
+ });
15015
+ }
14971
15016
  }
14972
- });
14973
- };
14974
- if (state.loading) {
15017
+ }
15018
+ }, [dispatch, fieldNameState, finishedTyping] // eslint-disable-line react-hooks/exhaustive-deps
15019
+ );
15020
+
15021
+ useEffect(() => {
15022
+ handleInputChange(fieldNameState);
15023
+ }, [finishedTyping, fieldNameState, handleInputChange]);
15024
+ if (loading) {
14975
15025
  return /*#__PURE__*/React__default.createElement(Loader, null);
14976
15026
  }
14977
15027
  return /*#__PURE__*/React__default.createElement(Input, Object.assign({
14978
15028
  type: "text",
14979
- value: state[fieldName],
15029
+ error: fieldNameError,
15030
+ value: fieldNameState,
14980
15031
  defaultValue: (_window$Pelcro$user$r = window.Pelcro.user.read()) === null || _window$Pelcro$user$r === void 0 ? void 0 : (_window$Pelcro$user$r2 = _window$Pelcro$user$r.metadata) === null || _window$Pelcro$user$r2 === void 0 ? void 0 : _window$Pelcro$user$r2[fieldName],
14981
- onChange: e => handleInputChange(e.target.value)
15032
+ onChange: e => handleInputChange(e.target.value),
15033
+ onBlur: () => setFinishedTyping(true),
15034
+ onFocus: () => setFinishedTyping(false)
14982
15035
  }, otherProps));
14983
15036
  }
14984
15037
 
@@ -19585,6 +19638,102 @@ const PaymentMethodContainerWithoutStripe = _ref => {
19585
19638
  onSuccess(response);
19586
19639
  }
19587
19640
  };
19641
+ const confirmStripeIntentSetup = (response, flow, paymentMethodId) => {
19642
+ var _response$data2;
19643
+ const setupIntent = (_response$data2 = response.data) === null || _response$data2 === void 0 ? void 0 : _response$data2.setup_intent;
19644
+ if (setupIntent !== null && setupIntent !== void 0 && setupIntent.client_secret) {
19645
+ var _response$data3, _response$data3$sourc;
19646
+ stripe.confirmCardSetup(setupIntent.client_secret, {
19647
+ payment_method: (_response$data3 = response.data) === null || _response$data3 === void 0 ? void 0 : (_response$data3$sourc = _response$data3.source) === null || _response$data3$sourc === void 0 ? void 0 : _response$data3$sourc.object_id
19648
+ }).then(res => {
19649
+ var _response$data4;
19650
+ if (res.error) {
19651
+ dispatch({
19652
+ type: LOADING,
19653
+ payload: false
19654
+ });
19655
+ onFailure(res.error);
19656
+ return dispatch({
19657
+ type: SHOW_ALERT,
19658
+ payload: {
19659
+ type: "error",
19660
+ content: getErrorMessages(res.error)
19661
+ }
19662
+ });
19663
+ }
19664
+ if (flow === "create") {
19665
+ dispatch({
19666
+ type: DISABLE_SUBMIT,
19667
+ payload: false
19668
+ });
19669
+ dispatch({
19670
+ type: LOADING,
19671
+ payload: false
19672
+ });
19673
+ dispatch({
19674
+ type: SHOW_ALERT,
19675
+ payload: {
19676
+ type: "success",
19677
+ content: t("messages.sourceCreated")
19678
+ }
19679
+ });
19680
+ onSuccess(res);
19681
+ return;
19682
+ }
19683
+ if (flow === "update") {
19684
+ dispatch({
19685
+ type: DISABLE_SUBMIT,
19686
+ payload: false
19687
+ });
19688
+ dispatch({
19689
+ type: LOADING,
19690
+ payload: false
19691
+ });
19692
+ dispatch({
19693
+ type: SHOW_ALERT,
19694
+ payload: {
19695
+ type: "success",
19696
+ content: t("messages.sourceUpdated")
19697
+ }
19698
+ });
19699
+ onSuccess(res);
19700
+ return;
19701
+ }
19702
+ if (flow === "replace") {
19703
+ setTimeout(() => {
19704
+ window.Pelcro.paymentMethods.deletePaymentMethod({
19705
+ auth_token: window.Pelcro.user.read().auth_token,
19706
+ payment_method_id: paymentMethodId
19707
+ }, (err, res) => {
19708
+ dispatch({
19709
+ type: DISABLE_SUBMIT,
19710
+ payload: false
19711
+ });
19712
+ dispatch({
19713
+ type: LOADING,
19714
+ payload: false
19715
+ });
19716
+ if (err) {
19717
+ onFailure === null || onFailure === void 0 ? void 0 : onFailure(err);
19718
+ return dispatch({
19719
+ type: SHOW_ALERT,
19720
+ payload: {
19721
+ type: "error",
19722
+ content: getErrorMessages(err)
19723
+ }
19724
+ });
19725
+ }
19726
+ onSuccess(res);
19727
+ });
19728
+ }, 2000);
19729
+ return;
19730
+ }
19731
+ return handlePayment(response === null || response === void 0 ? void 0 : (_response$data4 = response.data) === null || _response$data4 === void 0 ? void 0 : _response$data4.source);
19732
+ });
19733
+ } else {
19734
+ onSuccess(response);
19735
+ }
19736
+ };
19588
19737
  const subscribe = (stripeSource, state, dispatch) => {
19589
19738
  const {
19590
19739
  couponCode
@@ -19870,7 +20019,6 @@ const PaymentMethodContainerWithoutStripe = _ref => {
19870
20019
  return stripe.createSource({
19871
20020
  type: "card"
19872
20021
  }).then(_ref8 => {
19873
- var _source$card2;
19874
20022
  let {
19875
20023
  source,
19876
20024
  error
@@ -19880,17 +20028,19 @@ const PaymentMethodContainerWithoutStripe = _ref => {
19880
20028
  }
19881
20029
 
19882
20030
  // We don't support source creation for 3D secure yet
19883
- if ((source === null || source === void 0 ? void 0 : (_source$card2 = source.card) === null || _source$card2 === void 0 ? void 0 : _source$card2.three_d_secure) === "required") {
19884
- return handlePaymentError({
19885
- error: {
19886
- message: t("messages.cardAuthNotSupported")
19887
- }
19888
- });
19889
- }
20031
+ // if (source?.card?.three_d_secure === "required") {
20032
+ // return handlePaymentError({
20033
+ // error: {
20034
+ // message: t("messages.cardAuthNotSupported")
20035
+ // }
20036
+ // });
20037
+ // }
20038
+
19890
20039
  window.Pelcro.paymentMethods.create({
19891
20040
  auth_token: window.Pelcro.user.read().auth_token,
19892
20041
  token: source.id
19893
20042
  }, (err, res) => {
20043
+ var _res$data, _res$data$setup_inten, _res$data2, _res$data2$setup_inte;
19894
20044
  dispatch({
19895
20045
  type: DISABLE_SUBMIT,
19896
20046
  payload: false
@@ -19909,14 +20059,18 @@ const PaymentMethodContainerWithoutStripe = _ref => {
19909
20059
  }
19910
20060
  });
19911
20061
  }
19912
- dispatch({
19913
- type: SHOW_ALERT,
19914
- payload: {
19915
- type: "success",
19916
- content: t("messages.sourceCreated")
19917
- }
19918
- });
19919
- onSuccess(res);
20062
+ 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") {
20063
+ confirmStripeIntentSetup(res, "create");
20064
+ } else {
20065
+ dispatch({
20066
+ type: SHOW_ALERT,
20067
+ payload: {
20068
+ type: "success",
20069
+ content: t("messages.sourceCreated")
20070
+ }
20071
+ });
20072
+ onSuccess(res);
20073
+ }
19920
20074
  });
19921
20075
  });
19922
20076
  };
@@ -19937,6 +20091,7 @@ const PaymentMethodContainerWithoutStripe = _ref => {
19937
20091
  exp_year: year,
19938
20092
  is_default: isDefault
19939
20093
  }, (err, res) => {
20094
+ var _res$data3, _res$data3$setup_inte, _res$data4, _res$data4$setup_inte;
19940
20095
  dispatch({
19941
20096
  type: DISABLE_SUBMIT,
19942
20097
  payload: false
@@ -19955,14 +20110,18 @@ const PaymentMethodContainerWithoutStripe = _ref => {
19955
20110
  }
19956
20111
  });
19957
20112
  }
19958
- dispatch({
19959
- type: SHOW_ALERT,
19960
- payload: {
19961
- type: "success",
19962
- content: t("messages.sourceUpdated")
19963
- }
19964
- });
19965
- onSuccess(res);
20113
+ 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") {
20114
+ confirmStripeIntentSetup(res, "update");
20115
+ } else {
20116
+ dispatch({
20117
+ type: SHOW_ALERT,
20118
+ payload: {
20119
+ type: "success",
20120
+ content: t("messages.sourceUpdated")
20121
+ }
20122
+ });
20123
+ onSuccess(res);
20124
+ }
19966
20125
  });
19967
20126
  };
19968
20127
  const replacePaymentSource = (state, dispatch) => {
@@ -19972,7 +20131,6 @@ const PaymentMethodContainerWithoutStripe = _ref => {
19972
20131
  return stripe.createSource({
19973
20132
  type: "card"
19974
20133
  }).then(_ref9 => {
19975
- var _source$card3;
19976
20134
  let {
19977
20135
  source,
19978
20136
  error
@@ -19982,17 +20140,19 @@ const PaymentMethodContainerWithoutStripe = _ref => {
19982
20140
  }
19983
20141
 
19984
20142
  // We don't support source creation for 3D secure yet
19985
- if ((source === null || source === void 0 ? void 0 : (_source$card3 = source.card) === null || _source$card3 === void 0 ? void 0 : _source$card3.three_d_secure) === "required") {
19986
- return handlePaymentError({
19987
- error: {
19988
- message: t("messages.cardAuthNotSupported")
19989
- }
19990
- });
19991
- }
20143
+ // if (source?.card?.three_d_secure === "required") {
20144
+ // return handlePaymentError({
20145
+ // error: {
20146
+ // message: t("messages.cardAuthNotSupported")
20147
+ // }
20148
+ // });
20149
+ // }
20150
+
19992
20151
  window.Pelcro.paymentMethods.create({
19993
20152
  auth_token: window.Pelcro.user.read().auth_token,
19994
20153
  token: source.id
19995
20154
  }, (err, res) => {
20155
+ var _res$data5, _res$data5$setup_inte, _res$data6, _res$data6$setup_inte;
19996
20156
  if (err) {
19997
20157
  onFailure(err);
19998
20158
  return dispatch({
@@ -20003,7 +20163,9 @@ const PaymentMethodContainerWithoutStripe = _ref => {
20003
20163
  }
20004
20164
  });
20005
20165
  }
20006
- if (res) {
20166
+ 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") {
20167
+ confirmStripeIntentSetup(res, "replace", paymentMethodId);
20168
+ } else {
20007
20169
  setTimeout(() => {
20008
20170
  window.Pelcro.paymentMethods.deletePaymentMethod({
20009
20171
  auth_token: window.Pelcro.user.read().auth_token,
@@ -20166,12 +20328,12 @@ const PaymentMethodContainerWithoutStripe = _ref => {
20166
20328
  coupon_code: state === null || state === void 0 ? void 0 : state.couponCode,
20167
20329
  address_id: selectedAddressId
20168
20330
  }, (error, res) => {
20169
- var _res$data, _res$data2;
20331
+ var _res$data7, _res$data8;
20170
20332
  if (error) {
20171
20333
  return reject(error);
20172
20334
  }
20173
- const taxAmount = (_res$data = res.data) === null || _res$data === void 0 ? void 0 : _res$data.taxes;
20174
- const totalAmountWithTax = (_res$data2 = res.data) === null || _res$data2 === void 0 ? void 0 : _res$data2.total;
20335
+ const taxAmount = (_res$data7 = res.data) === null || _res$data7 === void 0 ? void 0 : _res$data7.taxes;
20336
+ const totalAmountWithTax = (_res$data8 = res.data) === null || _res$data8 === void 0 ? void 0 : _res$data8.total;
20175
20337
  resolve({
20176
20338
  totalAmountWithTax,
20177
20339
  taxAmount
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.43",
4
+ "version": "3.26.0-beta.45",
5
5
  "license": "MIT",
6
6
  "private": false,
7
7
  "main": "dist/index.cjs.js",