@pelcro/react-pelcro-js 3.13.0-beta.14 → 3.13.0-beta.15

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
@@ -8313,7 +8313,7 @@ class PelcroActions {
8313
8313
  return console.error("invalid subscription id");
8314
8314
  }
8315
8315
 
8316
- if ((subscriptionToManageMembers === null || subscriptionToManageMembers === void 0 ? void 0 : (_subscriptionToManage = subscriptionToManageMembers.plan) === null || _subscriptionToManage === void 0 ? void 0 : _subscriptionToManage.type) !== 'membership') {
8316
+ if ((subscriptionToManageMembers === null || subscriptionToManageMembers === void 0 ? void 0 : (_subscriptionToManage = subscriptionToManageMembers.plan) === null || _subscriptionToManage === void 0 ? void 0 : _subscriptionToManage.type) !== "membership") {
8317
8317
  return console.error("subscription is not from type membership");
8318
8318
  }
8319
8319
 
@@ -13482,7 +13482,7 @@ function LoginModal({
13482
13482
  resetView();
13483
13483
  const viewFromURL = getStableViewID(window.Pelcro.helpers.getURLParameter("view"));
13484
13484
 
13485
- if (viewFromURL === "invoice-details") {
13485
+ if (viewFromURL === "invoice-details" || viewFromURL === "gift-redeem") {
13486
13486
  initViewFromURL();
13487
13487
  }
13488
13488
  };
@@ -14066,7 +14066,7 @@ function RegisterModal(props) {
14066
14066
 
14067
14067
 
14068
14068
  if (giftCode) {
14069
- return switchToAddressView();
14069
+ return switchView("gift-redeem"); // return switchToAddressView();
14070
14070
  } // Check if the subscription is meant as a gift (if so, gather recipients info)
14071
14071
 
14072
14072
 
@@ -25275,6 +25275,7 @@ const GiftCreateModal = ({
25275
25275
  GiftCreateModal.viewId = "gift-create";
25276
25276
 
25277
25277
  const initialState$6 = {
25278
+ isSubmitting: false,
25278
25279
  giftCode: "",
25279
25280
  buttonDisabled: true,
25280
25281
  alert: {
@@ -25293,14 +25294,24 @@ const GiftRedeemContainer = ({
25293
25294
  onSuccess = () => {},
25294
25295
  onFailure = () => {},
25295
25296
  onDisplay = () => {},
25296
- children
25297
+ children,
25298
+ ...props
25297
25299
  }) => {
25300
+ var _ref, _props$subscriptionId;
25301
+
25298
25302
  const {
25299
25303
  t
25300
25304
  } = useTranslation("register");
25301
25305
  const {
25302
25306
  set
25303
25307
  } = usePelcro();
25308
+ const {
25309
+ switchView,
25310
+ switchToAddressView,
25311
+ isAuthenticated,
25312
+ subscriptionIdToRenew: subscriptionIdToRenewFromStore
25313
+ } = usePelcro();
25314
+ const subscriptionIdToRenew = (_ref = (_props$subscriptionId = props.subscriptionIdToRenew) !== null && _props$subscriptionId !== void 0 ? _props$subscriptionId : subscriptionIdToRenewFromStore) !== null && _ref !== void 0 ? _ref : undefined;
25304
25315
  React.useEffect(() => {
25305
25316
  onDisplay();
25306
25317
  }, []);
@@ -25321,7 +25332,41 @@ const GiftRedeemContainer = ({
25321
25332
  set({
25322
25333
  giftCode
25323
25334
  });
25324
- onSuccess(giftCode);
25335
+
25336
+ if (!isAuthenticated()) {
25337
+ switchView("register");
25338
+ } else {
25339
+ console.log("Shaker");
25340
+ window.Pelcro.subscription.redeemGift({
25341
+ auth_token: window.Pelcro.user.read().auth_token,
25342
+ gift_code: giftCode,
25343
+ // redeem gift as a future phase of an existing subscription
25344
+ subscription_id: subscriptionIdToRenew
25345
+ }, (err, res) => {
25346
+ dispatch({
25347
+ type: LOADING,
25348
+ payload: false
25349
+ });
25350
+
25351
+ if (err) {
25352
+ dispatch({
25353
+ type: SHOW_ALERT,
25354
+ payload: {
25355
+ type: "error",
25356
+ content: getErrorMessages(err)
25357
+ }
25358
+ });
25359
+
25360
+ if (getErrorMessages(err) === "Address ID is required") {
25361
+ switchToAddressView();
25362
+ } else {
25363
+ return onFailure(err);
25364
+ }
25365
+ } else {
25366
+ return onSuccess(giftCode);
25367
+ }
25368
+ });
25369
+ }
25325
25370
  }
25326
25371
  };
25327
25372
 
@@ -25342,8 +25387,14 @@ const GiftRedeemContainer = ({
25342
25387
  buttonDisabled: action.payload
25343
25388
  });
25344
25389
 
25390
+ case LOADING:
25391
+ return lib_7({ ...state,
25392
+ isSubmitting: action.payload
25393
+ });
25394
+
25345
25395
  case HANDLE_SUBMIT:
25346
25396
  return lib_5({ ...state,
25397
+ isSubmitting: true,
25347
25398
  buttonDisabled: true
25348
25399
  }, (state, dispatch) => handleRedeem(state, dispatch));
25349
25400
 
@@ -25412,7 +25463,8 @@ const GiftRedeemSubmitButton = ({
25412
25463
  const {
25413
25464
  dispatch,
25414
25465
  state: {
25415
- disableSubmit
25466
+ disableSubmit,
25467
+ isSubmitting
25416
25468
  }
25417
25469
  } = React.useContext(store$6);
25418
25470
  const {
@@ -25425,7 +25477,8 @@ const GiftRedeemSubmitButton = ({
25425
25477
  });
25426
25478
  onClick === null || onClick === void 0 ? void 0 : onClick();
25427
25479
  },
25428
- disabled: disableSubmit
25480
+ disabled: disableSubmit,
25481
+ isLoading: isSubmitting
25429
25482
  }, otherProps), name !== null && name !== void 0 ? name : t("redeem.buttons.redeem"));
25430
25483
  };
25431
25484
 
@@ -25476,12 +25529,7 @@ const GiftRedeemModal = ({
25476
25529
  var _otherProps$onSuccess;
25477
25530
 
25478
25531
  (_otherProps$onSuccess = otherProps.onSuccess) === null || _otherProps$onSuccess === void 0 ? void 0 : _otherProps$onSuccess.call(otherProps, giftCode);
25479
-
25480
- if (isAuthenticated()) {
25481
- switchToAddressView();
25482
- } else {
25483
- switchView("register");
25484
- }
25532
+ switchView("subscription-success");
25485
25533
  };
25486
25534
 
25487
25535
  return /*#__PURE__*/React__default['default'].createElement(Modal, {
package/dist/index.esm.js CHANGED
@@ -8283,7 +8283,7 @@ class PelcroActions {
8283
8283
  return console.error("invalid subscription id");
8284
8284
  }
8285
8285
 
8286
- if ((subscriptionToManageMembers === null || subscriptionToManageMembers === void 0 ? void 0 : (_subscriptionToManage = subscriptionToManageMembers.plan) === null || _subscriptionToManage === void 0 ? void 0 : _subscriptionToManage.type) !== 'membership') {
8286
+ if ((subscriptionToManageMembers === null || subscriptionToManageMembers === void 0 ? void 0 : (_subscriptionToManage = subscriptionToManageMembers.plan) === null || _subscriptionToManage === void 0 ? void 0 : _subscriptionToManage.type) !== "membership") {
8287
8287
  return console.error("subscription is not from type membership");
8288
8288
  }
8289
8289
 
@@ -13452,7 +13452,7 @@ function LoginModal({
13452
13452
  resetView();
13453
13453
  const viewFromURL = getStableViewID(window.Pelcro.helpers.getURLParameter("view"));
13454
13454
 
13455
- if (viewFromURL === "invoice-details") {
13455
+ if (viewFromURL === "invoice-details" || viewFromURL === "gift-redeem") {
13456
13456
  initViewFromURL();
13457
13457
  }
13458
13458
  };
@@ -14036,7 +14036,7 @@ function RegisterModal(props) {
14036
14036
 
14037
14037
 
14038
14038
  if (giftCode) {
14039
- return switchToAddressView();
14039
+ return switchView("gift-redeem"); // return switchToAddressView();
14040
14040
  } // Check if the subscription is meant as a gift (if so, gather recipients info)
14041
14041
 
14042
14042
 
@@ -25245,6 +25245,7 @@ const GiftCreateModal = ({
25245
25245
  GiftCreateModal.viewId = "gift-create";
25246
25246
 
25247
25247
  const initialState$6 = {
25248
+ isSubmitting: false,
25248
25249
  giftCode: "",
25249
25250
  buttonDisabled: true,
25250
25251
  alert: {
@@ -25263,14 +25264,24 @@ const GiftRedeemContainer = ({
25263
25264
  onSuccess = () => {},
25264
25265
  onFailure = () => {},
25265
25266
  onDisplay = () => {},
25266
- children
25267
+ children,
25268
+ ...props
25267
25269
  }) => {
25270
+ var _ref, _props$subscriptionId;
25271
+
25268
25272
  const {
25269
25273
  t
25270
25274
  } = useTranslation("register");
25271
25275
  const {
25272
25276
  set
25273
25277
  } = usePelcro();
25278
+ const {
25279
+ switchView,
25280
+ switchToAddressView,
25281
+ isAuthenticated,
25282
+ subscriptionIdToRenew: subscriptionIdToRenewFromStore
25283
+ } = usePelcro();
25284
+ const subscriptionIdToRenew = (_ref = (_props$subscriptionId = props.subscriptionIdToRenew) !== null && _props$subscriptionId !== void 0 ? _props$subscriptionId : subscriptionIdToRenewFromStore) !== null && _ref !== void 0 ? _ref : undefined;
25274
25285
  useEffect(() => {
25275
25286
  onDisplay();
25276
25287
  }, []);
@@ -25291,7 +25302,41 @@ const GiftRedeemContainer = ({
25291
25302
  set({
25292
25303
  giftCode
25293
25304
  });
25294
- onSuccess(giftCode);
25305
+
25306
+ if (!isAuthenticated()) {
25307
+ switchView("register");
25308
+ } else {
25309
+ console.log("Shaker");
25310
+ window.Pelcro.subscription.redeemGift({
25311
+ auth_token: window.Pelcro.user.read().auth_token,
25312
+ gift_code: giftCode,
25313
+ // redeem gift as a future phase of an existing subscription
25314
+ subscription_id: subscriptionIdToRenew
25315
+ }, (err, res) => {
25316
+ dispatch({
25317
+ type: LOADING,
25318
+ payload: false
25319
+ });
25320
+
25321
+ if (err) {
25322
+ dispatch({
25323
+ type: SHOW_ALERT,
25324
+ payload: {
25325
+ type: "error",
25326
+ content: getErrorMessages(err)
25327
+ }
25328
+ });
25329
+
25330
+ if (getErrorMessages(err) === "Address ID is required") {
25331
+ switchToAddressView();
25332
+ } else {
25333
+ return onFailure(err);
25334
+ }
25335
+ } else {
25336
+ return onSuccess(giftCode);
25337
+ }
25338
+ });
25339
+ }
25295
25340
  }
25296
25341
  };
25297
25342
 
@@ -25312,8 +25357,14 @@ const GiftRedeemContainer = ({
25312
25357
  buttonDisabled: action.payload
25313
25358
  });
25314
25359
 
25360
+ case LOADING:
25361
+ return lib_7({ ...state,
25362
+ isSubmitting: action.payload
25363
+ });
25364
+
25315
25365
  case HANDLE_SUBMIT:
25316
25366
  return lib_5({ ...state,
25367
+ isSubmitting: true,
25317
25368
  buttonDisabled: true
25318
25369
  }, (state, dispatch) => handleRedeem(state, dispatch));
25319
25370
 
@@ -25382,7 +25433,8 @@ const GiftRedeemSubmitButton = ({
25382
25433
  const {
25383
25434
  dispatch,
25384
25435
  state: {
25385
- disableSubmit
25436
+ disableSubmit,
25437
+ isSubmitting
25386
25438
  }
25387
25439
  } = useContext(store$6);
25388
25440
  const {
@@ -25395,7 +25447,8 @@ const GiftRedeemSubmitButton = ({
25395
25447
  });
25396
25448
  onClick === null || onClick === void 0 ? void 0 : onClick();
25397
25449
  },
25398
- disabled: disableSubmit
25450
+ disabled: disableSubmit,
25451
+ isLoading: isSubmitting
25399
25452
  }, otherProps), name !== null && name !== void 0 ? name : t("redeem.buttons.redeem"));
25400
25453
  };
25401
25454
 
@@ -25446,12 +25499,7 @@ const GiftRedeemModal = ({
25446
25499
  var _otherProps$onSuccess;
25447
25500
 
25448
25501
  (_otherProps$onSuccess = otherProps.onSuccess) === null || _otherProps$onSuccess === void 0 ? void 0 : _otherProps$onSuccess.call(otherProps, giftCode);
25449
-
25450
- if (isAuthenticated()) {
25451
- switchToAddressView();
25452
- } else {
25453
- switchView("register");
25454
- }
25502
+ switchView("subscription-success");
25455
25503
  };
25456
25504
 
25457
25505
  return /*#__PURE__*/React__default.createElement(Modal, {
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.13.0-beta.14",
4
+ "version": "3.13.0-beta.15",
5
5
  "license": "MIT",
6
6
  "private": false,
7
7
  "main": "dist/index.cjs.js",