@pelcro/react-pelcro-js 3.48.0 → 3.50.0

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
@@ -3970,6 +3970,10 @@ var labels$V = {
3970
3970
  },
3971
3971
  subCancellation: {
3972
3972
  goBack: "Go back"
3973
+ },
3974
+ emailPreferences: {
3975
+ label: "Email Notifications",
3976
+ description: "Select which email updates you would like to receive:"
3973
3977
  }
3974
3978
  };
3975
3979
  var messages$W = {
@@ -4866,6 +4870,10 @@ var labels$E = {
4866
4870
  },
4867
4871
  subCancellation: {
4868
4872
  goBack: "Retourner"
4873
+ },
4874
+ emailPreferences: {
4875
+ label: "Notifications par courriel",
4876
+ description: "Sélectionnez les mises à jour par courriel que vous souhaitez recevoir:"
4869
4877
  }
4870
4878
  };
4871
4879
  var messages$E = {
@@ -17265,6 +17273,9 @@ class TapGateway {
17265
17273
  }
17266
17274
  }
17267
17275
 
17276
+ /**
17277
+ * Cybersource gateway strategy
17278
+ */
17268
17279
  /**
17269
17280
  * Cybersource gateway strategy
17270
17281
  */
@@ -17311,7 +17322,9 @@ class CybersourceGateway {
17311
17322
  quantity = 1,
17312
17323
  addressId,
17313
17324
  isExistingSource,
17314
- fingerprint_session_id
17325
+ fingerprint_session_id,
17326
+ cardExpirationMonth,
17327
+ cardExpirationYear
17315
17328
  } = options;
17316
17329
  const params = isExistingSource ? {
17317
17330
  source_id: token
@@ -17327,6 +17340,8 @@ class CybersourceGateway {
17327
17340
  coupon_code: couponCode,
17328
17341
  address_id: product.address_required ? addressId : null,
17329
17342
  fingerprint_session_id: fingerprint_session_id,
17343
+ card_expiration_month: cardExpirationMonth,
17344
+ card_expiration_year: cardExpirationYear,
17330
17345
  ...params
17331
17346
  }, (err, res) => {
17332
17347
  callback(err, res);
@@ -17343,7 +17358,9 @@ class CybersourceGateway {
17343
17358
  couponCode,
17344
17359
  product,
17345
17360
  addressId,
17346
- isExistingSource
17361
+ isExistingSource,
17362
+ cardExpirationMonth,
17363
+ cardExpirationYear
17347
17364
  } = options;
17348
17365
  const params = isExistingSource ? {
17349
17366
  source_id: token
@@ -17358,6 +17375,8 @@ class CybersourceGateway {
17358
17375
  campaign_key: window.Pelcro.helpers.getURLParameter("campaign_key"),
17359
17376
  subscription_id: subscriptionIdToRenew,
17360
17377
  address_id: product.address_required ? addressId : null,
17378
+ card_expiration_month: cardExpirationMonth,
17379
+ card_expiration_year: cardExpirationYear,
17361
17380
  ...params
17362
17381
  }, (err, res) => {
17363
17382
  callback(err, res);
@@ -17375,7 +17394,9 @@ class CybersourceGateway {
17375
17394
  giftRecipient,
17376
17395
  quantity = 1,
17377
17396
  addressId,
17378
- isExistingSource
17397
+ isExistingSource,
17398
+ cardExpirationMonth,
17399
+ cardExpirationYear
17379
17400
  } = options;
17380
17401
  const params = isExistingSource ? {
17381
17402
  source_id: token
@@ -17395,6 +17416,8 @@ class CybersourceGateway {
17395
17416
  gift_start_date: giftRecipient === null || giftRecipient === void 0 ? void 0 : giftRecipient.startDate,
17396
17417
  gift_message: giftRecipient === null || giftRecipient === void 0 ? void 0 : giftRecipient.giftMessage,
17397
17418
  address_id: product.address_required ? addressId : null,
17419
+ card_expiration_month: cardExpirationMonth,
17420
+ card_expiration_year: cardExpirationYear,
17398
17421
  ...params
17399
17422
  }, (err, res) => {
17400
17423
  callback(err, res);
@@ -17411,7 +17434,9 @@ class CybersourceGateway {
17411
17434
  plan,
17412
17435
  couponCode,
17413
17436
  addressId,
17414
- isExistingSource
17437
+ isExistingSource,
17438
+ cardExpirationMonth,
17439
+ cardExpirationYear
17415
17440
  } = options;
17416
17441
  const params = isExistingSource ? {
17417
17442
  source_id: token
@@ -17425,6 +17450,8 @@ class CybersourceGateway {
17425
17450
  coupon_code: couponCode,
17426
17451
  subscription_id: subscriptionIdToRenew,
17427
17452
  address_id: product.address_required ? addressId : null,
17453
+ card_expiration_month: cardExpirationMonth,
17454
+ card_expiration_year: cardExpirationYear,
17428
17455
  ...params
17429
17456
  }, (err, res) => {
17430
17457
  callback(err, res);
@@ -17439,7 +17466,9 @@ class CybersourceGateway {
17439
17466
  items,
17440
17467
  couponCode,
17441
17468
  addressId,
17442
- isExistingSource
17469
+ isExistingSource,
17470
+ cardExpirationMonth,
17471
+ cardExpirationYear
17443
17472
  } = options;
17444
17473
  const params = isExistingSource ? {
17445
17474
  source_id: token
@@ -17454,7 +17483,9 @@ class CybersourceGateway {
17454
17483
  ...params,
17455
17484
  ...(addressId && {
17456
17485
  address_id: addressId
17457
- })
17486
+ }),
17487
+ card_expiration_month: cardExpirationMonth,
17488
+ card_expiration_year: cardExpirationYear
17458
17489
  }, (err, res) => {
17459
17490
  callback(err, res);
17460
17491
  });
@@ -17861,7 +17892,7 @@ const PaymentMethodContainerWithoutStripe = _ref => {
17861
17892
  }
17862
17893
  });
17863
17894
  }
17864
- handleCybersourcePayment(response.token, state);
17895
+ handleCybersourcePayment(response, state);
17865
17896
  });
17866
17897
  };
17867
17898
  function handleCybersourcePayment(paymentRequest, state) {
@@ -17879,7 +17910,9 @@ const PaymentMethodContainerWithoutStripe = _ref => {
17879
17910
  window.Pelcro.source.create({
17880
17911
  auth_token: window.Pelcro.user.read().auth_token,
17881
17912
  token: paymentRequest,
17882
- gateway: "cybersource"
17913
+ gateway: "cybersource",
17914
+ cardExpirationMonth: state.month,
17915
+ cardExpirationYear: state.year
17883
17916
  }, (err, res) => {
17884
17917
  dispatch({
17885
17918
  type: DISABLE_SUBMIT,
@@ -17907,6 +17940,12 @@ const PaymentMethodContainerWithoutStripe = _ref => {
17907
17940
  content: t("messages.sourceUpdated")
17908
17941
  }
17909
17942
  });
17943
+
17944
+ // Reinitialize Cybersource microform after successful payment
17945
+ setTimeout(() => {
17946
+ cybersourceInstanceRef.current = null;
17947
+ initCybersourceScript();
17948
+ }, 1000);
17910
17949
  onSuccess(res);
17911
17950
  } //
17912
17951
  );
@@ -17930,11 +17969,19 @@ const PaymentMethodContainerWithoutStripe = _ref => {
17930
17969
  product,
17931
17970
  isExistingSource: isUsingExistingPaymentMethod,
17932
17971
  subscriptionIdToRenew,
17933
- addressId: selectedAddressId
17972
+ addressId: selectedAddressId,
17973
+ cardExpirationMonth: state.month,
17974
+ cardExpirationYear: state.year
17934
17975
  }, (err, res) => {
17935
17976
  if (err) {
17936
17977
  return handlePaymentError(err);
17937
17978
  }
17979
+
17980
+ // Reinitialize Cybersource microform after successful payment
17981
+ setTimeout(() => {
17982
+ cybersourceInstanceRef.current = null;
17983
+ initCybersourceScript();
17984
+ }, 1000);
17938
17985
  onSuccess(res);
17939
17986
  });
17940
17987
  } else if (giftSubscriprition) {
@@ -17947,11 +17994,19 @@ const PaymentMethodContainerWithoutStripe = _ref => {
17947
17994
  product,
17948
17995
  isExistingSource: isUsingExistingPaymentMethod,
17949
17996
  giftRecipient,
17950
- addressId: selectedAddressId
17997
+ addressId: selectedAddressId,
17998
+ cardExpirationMonth: state.month,
17999
+ cardExpirationYear: state.year
17951
18000
  }, (err, res) => {
17952
18001
  if (err) {
17953
18002
  return handlePaymentError(err);
17954
18003
  }
18004
+
18005
+ // Reinitialize Cybersource microform after successful payment
18006
+ setTimeout(() => {
18007
+ cybersourceInstanceRef.current = null;
18008
+ initCybersourceScript();
18009
+ }, 1000);
17955
18010
  onSuccess(res);
17956
18011
  });
17957
18012
  } else if (renewSubscription) {
@@ -17964,11 +18019,19 @@ const PaymentMethodContainerWithoutStripe = _ref => {
17964
18019
  product,
17965
18020
  isExistingSource: isUsingExistingPaymentMethod,
17966
18021
  subscriptionIdToRenew,
17967
- addressId: selectedAddressId
18022
+ addressId: selectedAddressId,
18023
+ cardExpirationMonth: state.month,
18024
+ cardExpirationYear: state.year
17968
18025
  }, (err, res) => {
17969
18026
  if (err) {
17970
18027
  return handlePaymentError(err);
17971
18028
  }
18029
+
18030
+ // Reinitialize Cybersource microform after successful payment
18031
+ setTimeout(() => {
18032
+ cybersourceInstanceRef.current = null;
18033
+ initCybersourceScript();
18034
+ }, 1000);
17972
18035
  onSuccess(res);
17973
18036
  });
17974
18037
  } else if (createSubscription) {
@@ -17981,22 +18044,27 @@ const PaymentMethodContainerWithoutStripe = _ref => {
17981
18044
  product,
17982
18045
  isExistingSource: isUsingExistingPaymentMethod,
17983
18046
  addressId: selectedAddressId,
17984
- fingerprint_session_id: state.cyberSourceSessionId
18047
+ fingerprint_session_id: state.cyberSourceSessionId,
18048
+ cardExpirationMonth: state.month,
18049
+ cardExpirationYear: state.year
17985
18050
  }, (err, res) => {
17986
18051
  if (err) {
17987
18052
  return handlePaymentError(err);
17988
18053
  }
18054
+
18055
+ // Reinitialize Cybersource microform after successful payment
18056
+ setTimeout(() => {
18057
+ cybersourceInstanceRef.current = null;
18058
+ initCybersourceScript();
18059
+ }, 1000);
17989
18060
  onSuccess(res);
17990
18061
  });
17991
18062
  }
17992
18063
  }
17993
18064
  }
17994
- const tokenizeCard = (error, microformInstance) => {
17995
- if (error) {
17996
- return;
17997
- }
17998
- cybersourceInstanceRef.current = microformInstance;
17999
- };
18065
+
18066
+ // No longer needed - microform instance is stored directly in initCybersourceScript
18067
+
18000
18068
  const appendCybersourceFingerprintScripts = () => {
18001
18069
  var _window$Pelcro$site$r, _window$Pelcro$site$r2, _window$Pelcro$site$r3, _window$Pelcro$site$r4;
18002
18070
  const uniqueId = crypto.randomUUID();
@@ -18020,6 +18088,12 @@ const PaymentMethodContainerWithoutStripe = _ref => {
18020
18088
  }
18021
18089
  };
18022
18090
  const initCybersourceScript = () => {
18091
+ // Clear existing card number field before reinitializing
18092
+ const cardNumberElement = document.querySelector("#cybersourceCardNumber");
18093
+ if (cardNumberElement) {
18094
+ cardNumberElement.innerHTML = "";
18095
+ }
18096
+
18023
18097
  // jwk api call
18024
18098
  window.Pelcro.payment.getJWK({
18025
18099
  auth_token: window.Pelcro.user.read().auth_token,
@@ -18044,34 +18118,56 @@ const PaymentMethodContainerWithoutStripe = _ref => {
18044
18118
  });
18045
18119
  }
18046
18120
  const {
18047
- key: jwk
18121
+ key: jwk,
18122
+ captureContext,
18123
+ js_client
18048
18124
  } = res;
18049
- // SETUP MICROFORM
18050
- FLEX.microform({
18051
- keyId: jwk.kid,
18052
- keystore: jwk,
18053
- container: "#cybersourceCardNumber",
18054
- placeholder: "Card Number",
18055
- styles: {
18056
- input: {
18057
- "font-size": "14px",
18058
- "font-family": "helvetica, tahoma, calibri, sans-serif",
18059
- color: "#555"
18060
- },
18061
- ":focus": {
18062
- color: "blue"
18063
- },
18064
- ":disabled": {
18065
- cursor: "not-allowed"
18066
- },
18067
- valid: {
18068
- color: "#3c763d"
18069
- },
18070
- invalid: {
18071
- color: "#a94442"
18125
+
18126
+ // Load the SDK from the dynamic URL (if not already loaded)
18127
+ const existingScript = document.querySelector(`script[src="${js_client}"]`);
18128
+ if (!existingScript) {
18129
+ window.Pelcro.helpers.loadSDK(js_client, "cybersource-cdn");
18130
+ }
18131
+ const initializeMicroform = () => {
18132
+ // SETUP MICROFORM
18133
+ // eslint-disable-next-line no-undef
18134
+ const flex = new Flex(captureContext);
18135
+ const microform = flex.microform({
18136
+ styles: {
18137
+ input: {
18138
+ "font-size": "14px",
18139
+ "font-family": "helvetica, tahoma, calibri, sans-serif",
18140
+ color: "#555"
18141
+ },
18142
+ ":focus": {
18143
+ color: "blue"
18144
+ },
18145
+ ":disabled": {
18146
+ cursor: "not-allowed"
18147
+ },
18148
+ valid: {
18149
+ color: "#3c763d"
18150
+ },
18151
+ invalid: {
18152
+ color: "#a94442"
18153
+ }
18072
18154
  }
18073
- }
18074
- }, tokenizeCard);
18155
+ });
18156
+ const number = microform.createField("number", {
18157
+ placeholder: "Enter your card number"
18158
+ });
18159
+ number.load("#cybersourceCardNumber");
18160
+ cybersourceInstanceRef.current = microform;
18161
+ };
18162
+
18163
+ // Wait for SDK to load then initialize microform
18164
+ if (existingScript) {
18165
+ // Script already loaded, initialize immediately
18166
+ initializeMicroform();
18167
+ } else {
18168
+ // Wait for new script to load
18169
+ document.querySelector(`script[src="${js_client}"]`).addEventListener("load", initializeMicroform);
18170
+ }
18075
18171
  });
18076
18172
  };
18077
18173
 
@@ -19185,13 +19281,7 @@ const PaymentMethodContainerWithoutStripe = _ref => {
19185
19281
  if (cardProcessor === "tap" && !selectedPaymentMethodId && window.Tapjsli) {
19186
19282
  initTapScript();
19187
19283
  }
19188
- if (cardProcessor === "cybersource" && !selectedPaymentMethodId && !window.FLEX) {
19189
- window.Pelcro.helpers.loadSDK("https://flex.cybersource.com/cybersource/assets/microform/0.4/flex-microform.min.js", "cybersource-cdn");
19190
- document.querySelector('script[src="https://flex.cybersource.com/cybersource/assets/microform/0.4/flex-microform.min.js"]').addEventListener("load", () => {
19191
- initCybersourceScript();
19192
- });
19193
- }
19194
- if (cardProcessor === "cybersource" && !selectedPaymentMethodId && window.FLEX) {
19284
+ if (cardProcessor === "cybersource" && !selectedPaymentMethodId) {
19195
19285
  initCybersourceScript();
19196
19286
  }
19197
19287
  if (cardProcessor === "cybersource") {
@@ -19707,7 +19797,10 @@ const PaymentMethodContainerWithoutStripe = _ref => {
19707
19797
  gift_recipient_last_name: giftRecipient === null || giftRecipient === void 0 ? void 0 : giftRecipient.lastName,
19708
19798
  gift_start_date: giftRecipient === null || giftRecipient === void 0 ? void 0 : giftRecipient.startDate,
19709
19799
  gift_message: giftRecipient === null || giftRecipient === void 0 ? void 0 : giftRecipient.giftMessage,
19710
- address_id: product.address_required ? selectedAddressId : null
19800
+ address_id: product.address_required ? selectedAddressId : null,
19801
+ metadata: props === null || props === void 0 ? void 0 : props.subCreateMetadata,
19802
+ cardExpirationMonth: state === null || state === void 0 ? void 0 : state.month,
19803
+ cardExpirationYear: state === null || state === void 0 ? void 0 : state.year
19711
19804
  }, (err, res) => {
19712
19805
  var _res$data;
19713
19806
  if (res !== null && res !== void 0 && (_res$data = res.data) !== null && _res$data !== void 0 && _res$data.setup_intent) {
@@ -19882,7 +19975,9 @@ const PaymentMethodContainerWithoutStripe = _ref => {
19882
19975
  isExistingSource: Boolean(selectedPaymentMethodId),
19883
19976
  items: mappedOrderItems,
19884
19977
  addressId: selectedAddressId,
19885
- couponCode
19978
+ couponCode,
19979
+ cardExpirationMonth: state === null || state === void 0 ? void 0 : state.month,
19980
+ cardExpirationYear: state === null || state === void 0 ? void 0 : state.year
19886
19981
  }, (err, orderResponse) => {
19887
19982
  var _window$Pelcro2, _window$Pelcro2$user, _window$Pelcro2$user$;
19888
19983
  if (err) {
@@ -20163,7 +20258,9 @@ const PaymentMethodContainerWithoutStripe = _ref => {
20163
20258
  campaign_key: window.Pelcro.helpers.getURLParameter("campaign_key"),
20164
20259
  ...(selectedAddressId && {
20165
20260
  address_id: selectedAddressId
20166
- })
20261
+ }),
20262
+ cardExpirationMonth: state === null || state === void 0 ? void 0 : state.month,
20263
+ cardExpirationYear: state === null || state === void 0 ? void 0 : state.year
20167
20264
  }, (err, res) => {
20168
20265
  if (err) {
20169
20266
  return handlePaymentError(err);
@@ -31567,6 +31664,123 @@ function getMemberShipStatus(status) {
31567
31664
  };
31568
31665
  }
31569
31666
 
31667
+ const EmailPreferencesMenu = props => {
31668
+ const {
31669
+ t
31670
+ } = useTranslation("dashboard");
31671
+ const [options, setOptions] = React.useState([]);
31672
+ const [loading, setLoading] = React.useState({});
31673
+ const [alert, setAlert] = React.useState({});
31674
+ const [isLoading, setIsLoading] = React.useState(true);
31675
+ const [error, setError] = React.useState(null);
31676
+ React.useEffect(() => {
31677
+ var _window$Pelcro, _window$Pelcro$uiSett, _window$Pelcro$user$r, _window$Pelcro$user$r2;
31678
+ const options = ((_window$Pelcro = window.Pelcro) === null || _window$Pelcro === void 0 ? void 0 : (_window$Pelcro$uiSett = _window$Pelcro.uiSettings) === null || _window$Pelcro$uiSett === void 0 ? void 0 : _window$Pelcro$uiSett.newsletters) || [];
31679
+ const email = (_window$Pelcro$user$r = (_window$Pelcro$user$r2 = window.Pelcro.user.read()) === null || _window$Pelcro$user$r2 === void 0 ? void 0 : _window$Pelcro$user$r2.email) !== null && _window$Pelcro$user$r !== void 0 ? _window$Pelcro$user$r : window.Pelcro.helpers.getURLParameter("email");
31680
+ setIsLoading(true);
31681
+ window.Pelcro.newsletter.getByEmail(email, (err, res) => {
31682
+ var _res$data$lists$split, _res$data, _res$data$lists;
31683
+ if (err) {
31684
+ setIsLoading(false);
31685
+ setError(t("messages.error") || "Failed to load preferences.");
31686
+ return;
31687
+ }
31688
+ const selectedIds = (_res$data$lists$split = res === null || res === void 0 ? void 0 : (_res$data = res.data) === null || _res$data === void 0 ? void 0 : (_res$data$lists = _res$data.lists) === null || _res$data$lists === void 0 ? void 0 : _res$data$lists.split(",")) !== null && _res$data$lists$split !== void 0 ? _res$data$lists$split : [];
31689
+ setOptions(options.map(opt => ({
31690
+ ...opt,
31691
+ id: String(opt.id),
31692
+ selected: selectedIds.includes(String(opt.id))
31693
+ })));
31694
+ setIsLoading(false);
31695
+ setError(null);
31696
+ });
31697
+ }, [t]);
31698
+ const handleCheckboxChange = id => e => {
31699
+ const checked = e.target.checked;
31700
+ setOptions(prevOptions => {
31701
+ var _window$Pelcro$user$r3, _window$Pelcro$user$r4;
31702
+ const newOptions = prevOptions.map(opt => opt.id === id ? {
31703
+ ...opt,
31704
+ selected: checked
31705
+ } : opt);
31706
+ // Set loading for this checkbox
31707
+ setLoading(prev => ({
31708
+ ...prev,
31709
+ [id]: true
31710
+ }));
31711
+ setAlert(prev => ({
31712
+ ...prev,
31713
+ [id]: null
31714
+ }));
31715
+ // Save to backend
31716
+ const selectedIds = newOptions.filter(opt => opt.selected).map(opt => opt.id);
31717
+ const email = (_window$Pelcro$user$r3 = (_window$Pelcro$user$r4 = window.Pelcro.user.read()) === null || _window$Pelcro$user$r4 === void 0 ? void 0 : _window$Pelcro$user$r4.email) !== null && _window$Pelcro$user$r3 !== void 0 ? _window$Pelcro$user$r3 : window.Pelcro.helpers.getURLParameter("email");
31718
+ const requestData = {
31719
+ email,
31720
+ source: "web",
31721
+ lists: selectedIds.join(",")
31722
+ };
31723
+
31724
+ // Check if this is a new subscription
31725
+ window.Pelcro.newsletter.getByEmail(email, (err, res) => {
31726
+ if (err) {
31727
+ setLoading(prev => ({
31728
+ ...prev,
31729
+ [id]: false
31730
+ }));
31731
+ setAlert(prev => ({
31732
+ ...prev,
31733
+ [id]: "Error checking subscription status"
31734
+ }));
31735
+ return;
31736
+ }
31737
+ const didSubToNewslettersBefore = Boolean(res.data.email);
31738
+ const callback = err => {
31739
+ setLoading(prev => ({
31740
+ ...prev,
31741
+ [id]: false
31742
+ }));
31743
+ setAlert(prev => ({
31744
+ ...prev,
31745
+ [id]: err ? "Error saving" : "Saved!"
31746
+ }));
31747
+ };
31748
+ if (didSubToNewslettersBefore) {
31749
+ window.Pelcro.newsletter.update(requestData, callback);
31750
+ } else {
31751
+ window.Pelcro.newsletter.create(requestData, callback);
31752
+ }
31753
+ });
31754
+ return newOptions;
31755
+ });
31756
+ };
31757
+ if (isLoading) return /*#__PURE__*/React__default['default'].createElement("div", {
31758
+ className: "plc-flex plc-justify-center plc-items-center plc-h-32"
31759
+ }, /*#__PURE__*/React__default['default'].createElement(Loader, {
31760
+ width: 60,
31761
+ height: 100
31762
+ }));
31763
+ if (error) return /*#__PURE__*/React__default['default'].createElement("div", {
31764
+ className: "plc-text-red-600 plc-p-4"
31765
+ }, error);
31766
+ return /*#__PURE__*/React__default['default'].createElement("div", null, /*#__PURE__*/React__default['default'].createElement("div", {
31767
+ className: "plc-mb-4 plc-text-sm plc-text-gray-600"
31768
+ }, t("labels.emailPreferences.description") || "Select which email updates you would like to receive."), options.map(opt => /*#__PURE__*/React__default['default'].createElement("div", {
31769
+ key: opt.id,
31770
+ className: "plc-flex plc-items-center plc-mb-2"
31771
+ }, /*#__PURE__*/React__default['default'].createElement("input", {
31772
+ type: "checkbox",
31773
+ id: `email-pref-${opt.id}`,
31774
+ checked: !!opt.selected,
31775
+ onChange: handleCheckboxChange(opt.id),
31776
+ disabled: loading[opt.id],
31777
+ className: "plc-mr-2"
31778
+ }), /*#__PURE__*/React__default['default'].createElement("label", {
31779
+ htmlFor: `email-pref-${opt.id}`,
31780
+ className: "plc-text-base"
31781
+ }, opt.label))));
31782
+ };
31783
+
31570
31784
  const SUB_MENUS = {
31571
31785
  PROFILE: "profile",
31572
31786
  SUBSCRIPTIONS: "subscriptions",
@@ -31577,7 +31791,8 @@ const SUB_MENUS = {
31577
31791
  GIFTS: "gifts",
31578
31792
  ORDERS: "orders",
31579
31793
  INVOICES: "invoices",
31580
- SAVED_ITEMS: "saved-items"
31794
+ SAVED_ITEMS: "saved-items",
31795
+ EMAIL_PREFERENCES: "email-preferences"
31581
31796
  };
31582
31797
 
31583
31798
  /**
@@ -32071,13 +32286,14 @@ class Dashboard extends React.Component {
32071
32286
  this.enableReactGA4 = (_window = window) === null || _window === void 0 ? void 0 : (_window$Pelcro = _window.Pelcro) === null || _window$Pelcro === void 0 ? void 0 : (_window$Pelcro$uiSett = _window$Pelcro.uiSettings) === null || _window$Pelcro$uiSett === void 0 ? void 0 : _window$Pelcro$uiSett.enableReactGA4;
32072
32287
  }
32073
32288
  render() {
32074
- var _window$Pelcro$user$r3, _window$Pelcro2, _window$Pelcro2$uiSet;
32289
+ var _window$Pelcro$user$r3, _window$Pelcro2, _window$Pelcro2$uiSet, _window$Pelcro3, _window$Pelcro3$uiSet;
32075
32290
  const {
32076
32291
  isOpen
32077
32292
  } = this.state;
32078
32293
  const userHasName = this.user.first_name || this.user.last_name;
32079
32294
  const profilePicture = (_window$Pelcro$user$r3 = window.Pelcro.user.read().profile_photo) !== null && _window$Pelcro$user$r3 !== void 0 ? _window$Pelcro$user$r3 : userSolidIcon;
32080
32295
  const newsletters = (_window$Pelcro2 = window.Pelcro) === null || _window$Pelcro2 === void 0 ? void 0 : (_window$Pelcro2$uiSet = _window$Pelcro2.uiSettings) === null || _window$Pelcro2$uiSet === void 0 ? void 0 : _window$Pelcro2$uiSet.newsletters;
32296
+ const emailNotifications = (_window$Pelcro3 = window.Pelcro) === null || _window$Pelcro3 === void 0 ? void 0 : (_window$Pelcro3$uiSet = _window$Pelcro3.uiSettings) === null || _window$Pelcro3$uiSet === void 0 ? void 0 : _window$Pelcro3$uiSet.emailNotifications;
32081
32297
  const siteHasNewslettersDefined = Array.isArray(newsletters) && newsletters.length > 0;
32082
32298
  return /*#__PURE__*/React__default['default'].createElement(Transition, {
32083
32299
  className: "plc-fixed plc-inset-y-0 plc-right-0 plc-h-full plc-max-w-xl plc-overflow-y-auto plc-text-left plc-bg-white plc-shadow-xl plc-z-max",
@@ -32155,7 +32371,7 @@ class Dashboard extends React.Component {
32155
32371
  }),
32156
32372
  className: "plc-text-sm plc-text-gray-500 hover:plc-text-primary-700",
32157
32373
  onClick: this.displayChangePassword
32158
- }, this.locale("labels.changePassword")), siteHasNewslettersDefined && /*#__PURE__*/React__default['default'].createElement(Button, {
32374
+ }, this.locale("labels.changePassword")), siteHasNewslettersDefined && emailNotifications !== true && /*#__PURE__*/React__default['default'].createElement(Button, {
32159
32375
  variant: "ghost",
32160
32376
  icon: /*#__PURE__*/React__default['default'].createElement(SvgNewsletter, {
32161
32377
  className: "plc-w-5 plc-h-5 plc-mr-1"
@@ -32245,6 +32461,12 @@ class Dashboard extends React.Component {
32245
32461
  icon: /*#__PURE__*/React__default['default'].createElement(SvgBookmark, null),
32246
32462
  title: this.locale("labels.savedItems.label"),
32247
32463
  content: /*#__PURE__*/React__default['default'].createElement(SavedItemsMenu, null)
32464
+ }), /*#__PURE__*/React__default['default'].createElement(Accordion.item, {
32465
+ show: emailNotifications === true,
32466
+ name: SUB_MENUS.EMAIL_PREFERENCES,
32467
+ icon: /*#__PURE__*/React__default['default'].createElement(SvgBookmark, null),
32468
+ title: this.locale("labels.emailPreferences.label"),
32469
+ content: /*#__PURE__*/React__default['default'].createElement(EmailPreferencesMenu, null)
32248
32470
  }), /*#__PURE__*/React__default['default'].createElement(Button, {
32249
32471
  variant: "outline",
32250
32472
  icon: /*#__PURE__*/React__default['default'].createElement(SvgExit, null),
package/dist/index.esm.js CHANGED
@@ -3940,6 +3940,10 @@ var labels$V = {
3940
3940
  },
3941
3941
  subCancellation: {
3942
3942
  goBack: "Go back"
3943
+ },
3944
+ emailPreferences: {
3945
+ label: "Email Notifications",
3946
+ description: "Select which email updates you would like to receive:"
3943
3947
  }
3944
3948
  };
3945
3949
  var messages$W = {
@@ -4836,6 +4840,10 @@ var labels$E = {
4836
4840
  },
4837
4841
  subCancellation: {
4838
4842
  goBack: "Retourner"
4843
+ },
4844
+ emailPreferences: {
4845
+ label: "Notifications par courriel",
4846
+ description: "Sélectionnez les mises à jour par courriel que vous souhaitez recevoir:"
4839
4847
  }
4840
4848
  };
4841
4849
  var messages$E = {
@@ -17235,6 +17243,9 @@ class TapGateway {
17235
17243
  }
17236
17244
  }
17237
17245
 
17246
+ /**
17247
+ * Cybersource gateway strategy
17248
+ */
17238
17249
  /**
17239
17250
  * Cybersource gateway strategy
17240
17251
  */
@@ -17281,7 +17292,9 @@ class CybersourceGateway {
17281
17292
  quantity = 1,
17282
17293
  addressId,
17283
17294
  isExistingSource,
17284
- fingerprint_session_id
17295
+ fingerprint_session_id,
17296
+ cardExpirationMonth,
17297
+ cardExpirationYear
17285
17298
  } = options;
17286
17299
  const params = isExistingSource ? {
17287
17300
  source_id: token
@@ -17297,6 +17310,8 @@ class CybersourceGateway {
17297
17310
  coupon_code: couponCode,
17298
17311
  address_id: product.address_required ? addressId : null,
17299
17312
  fingerprint_session_id: fingerprint_session_id,
17313
+ card_expiration_month: cardExpirationMonth,
17314
+ card_expiration_year: cardExpirationYear,
17300
17315
  ...params
17301
17316
  }, (err, res) => {
17302
17317
  callback(err, res);
@@ -17313,7 +17328,9 @@ class CybersourceGateway {
17313
17328
  couponCode,
17314
17329
  product,
17315
17330
  addressId,
17316
- isExistingSource
17331
+ isExistingSource,
17332
+ cardExpirationMonth,
17333
+ cardExpirationYear
17317
17334
  } = options;
17318
17335
  const params = isExistingSource ? {
17319
17336
  source_id: token
@@ -17328,6 +17345,8 @@ class CybersourceGateway {
17328
17345
  campaign_key: window.Pelcro.helpers.getURLParameter("campaign_key"),
17329
17346
  subscription_id: subscriptionIdToRenew,
17330
17347
  address_id: product.address_required ? addressId : null,
17348
+ card_expiration_month: cardExpirationMonth,
17349
+ card_expiration_year: cardExpirationYear,
17331
17350
  ...params
17332
17351
  }, (err, res) => {
17333
17352
  callback(err, res);
@@ -17345,7 +17364,9 @@ class CybersourceGateway {
17345
17364
  giftRecipient,
17346
17365
  quantity = 1,
17347
17366
  addressId,
17348
- isExistingSource
17367
+ isExistingSource,
17368
+ cardExpirationMonth,
17369
+ cardExpirationYear
17349
17370
  } = options;
17350
17371
  const params = isExistingSource ? {
17351
17372
  source_id: token
@@ -17365,6 +17386,8 @@ class CybersourceGateway {
17365
17386
  gift_start_date: giftRecipient === null || giftRecipient === void 0 ? void 0 : giftRecipient.startDate,
17366
17387
  gift_message: giftRecipient === null || giftRecipient === void 0 ? void 0 : giftRecipient.giftMessage,
17367
17388
  address_id: product.address_required ? addressId : null,
17389
+ card_expiration_month: cardExpirationMonth,
17390
+ card_expiration_year: cardExpirationYear,
17368
17391
  ...params
17369
17392
  }, (err, res) => {
17370
17393
  callback(err, res);
@@ -17381,7 +17404,9 @@ class CybersourceGateway {
17381
17404
  plan,
17382
17405
  couponCode,
17383
17406
  addressId,
17384
- isExistingSource
17407
+ isExistingSource,
17408
+ cardExpirationMonth,
17409
+ cardExpirationYear
17385
17410
  } = options;
17386
17411
  const params = isExistingSource ? {
17387
17412
  source_id: token
@@ -17395,6 +17420,8 @@ class CybersourceGateway {
17395
17420
  coupon_code: couponCode,
17396
17421
  subscription_id: subscriptionIdToRenew,
17397
17422
  address_id: product.address_required ? addressId : null,
17423
+ card_expiration_month: cardExpirationMonth,
17424
+ card_expiration_year: cardExpirationYear,
17398
17425
  ...params
17399
17426
  }, (err, res) => {
17400
17427
  callback(err, res);
@@ -17409,7 +17436,9 @@ class CybersourceGateway {
17409
17436
  items,
17410
17437
  couponCode,
17411
17438
  addressId,
17412
- isExistingSource
17439
+ isExistingSource,
17440
+ cardExpirationMonth,
17441
+ cardExpirationYear
17413
17442
  } = options;
17414
17443
  const params = isExistingSource ? {
17415
17444
  source_id: token
@@ -17424,7 +17453,9 @@ class CybersourceGateway {
17424
17453
  ...params,
17425
17454
  ...(addressId && {
17426
17455
  address_id: addressId
17427
- })
17456
+ }),
17457
+ card_expiration_month: cardExpirationMonth,
17458
+ card_expiration_year: cardExpirationYear
17428
17459
  }, (err, res) => {
17429
17460
  callback(err, res);
17430
17461
  });
@@ -17831,7 +17862,7 @@ const PaymentMethodContainerWithoutStripe = _ref => {
17831
17862
  }
17832
17863
  });
17833
17864
  }
17834
- handleCybersourcePayment(response.token, state);
17865
+ handleCybersourcePayment(response, state);
17835
17866
  });
17836
17867
  };
17837
17868
  function handleCybersourcePayment(paymentRequest, state) {
@@ -17849,7 +17880,9 @@ const PaymentMethodContainerWithoutStripe = _ref => {
17849
17880
  window.Pelcro.source.create({
17850
17881
  auth_token: window.Pelcro.user.read().auth_token,
17851
17882
  token: paymentRequest,
17852
- gateway: "cybersource"
17883
+ gateway: "cybersource",
17884
+ cardExpirationMonth: state.month,
17885
+ cardExpirationYear: state.year
17853
17886
  }, (err, res) => {
17854
17887
  dispatch({
17855
17888
  type: DISABLE_SUBMIT,
@@ -17877,6 +17910,12 @@ const PaymentMethodContainerWithoutStripe = _ref => {
17877
17910
  content: t("messages.sourceUpdated")
17878
17911
  }
17879
17912
  });
17913
+
17914
+ // Reinitialize Cybersource microform after successful payment
17915
+ setTimeout(() => {
17916
+ cybersourceInstanceRef.current = null;
17917
+ initCybersourceScript();
17918
+ }, 1000);
17880
17919
  onSuccess(res);
17881
17920
  } //
17882
17921
  );
@@ -17900,11 +17939,19 @@ const PaymentMethodContainerWithoutStripe = _ref => {
17900
17939
  product,
17901
17940
  isExistingSource: isUsingExistingPaymentMethod,
17902
17941
  subscriptionIdToRenew,
17903
- addressId: selectedAddressId
17942
+ addressId: selectedAddressId,
17943
+ cardExpirationMonth: state.month,
17944
+ cardExpirationYear: state.year
17904
17945
  }, (err, res) => {
17905
17946
  if (err) {
17906
17947
  return handlePaymentError(err);
17907
17948
  }
17949
+
17950
+ // Reinitialize Cybersource microform after successful payment
17951
+ setTimeout(() => {
17952
+ cybersourceInstanceRef.current = null;
17953
+ initCybersourceScript();
17954
+ }, 1000);
17908
17955
  onSuccess(res);
17909
17956
  });
17910
17957
  } else if (giftSubscriprition) {
@@ -17917,11 +17964,19 @@ const PaymentMethodContainerWithoutStripe = _ref => {
17917
17964
  product,
17918
17965
  isExistingSource: isUsingExistingPaymentMethod,
17919
17966
  giftRecipient,
17920
- addressId: selectedAddressId
17967
+ addressId: selectedAddressId,
17968
+ cardExpirationMonth: state.month,
17969
+ cardExpirationYear: state.year
17921
17970
  }, (err, res) => {
17922
17971
  if (err) {
17923
17972
  return handlePaymentError(err);
17924
17973
  }
17974
+
17975
+ // Reinitialize Cybersource microform after successful payment
17976
+ setTimeout(() => {
17977
+ cybersourceInstanceRef.current = null;
17978
+ initCybersourceScript();
17979
+ }, 1000);
17925
17980
  onSuccess(res);
17926
17981
  });
17927
17982
  } else if (renewSubscription) {
@@ -17934,11 +17989,19 @@ const PaymentMethodContainerWithoutStripe = _ref => {
17934
17989
  product,
17935
17990
  isExistingSource: isUsingExistingPaymentMethod,
17936
17991
  subscriptionIdToRenew,
17937
- addressId: selectedAddressId
17992
+ addressId: selectedAddressId,
17993
+ cardExpirationMonth: state.month,
17994
+ cardExpirationYear: state.year
17938
17995
  }, (err, res) => {
17939
17996
  if (err) {
17940
17997
  return handlePaymentError(err);
17941
17998
  }
17999
+
18000
+ // Reinitialize Cybersource microform after successful payment
18001
+ setTimeout(() => {
18002
+ cybersourceInstanceRef.current = null;
18003
+ initCybersourceScript();
18004
+ }, 1000);
17942
18005
  onSuccess(res);
17943
18006
  });
17944
18007
  } else if (createSubscription) {
@@ -17951,22 +18014,27 @@ const PaymentMethodContainerWithoutStripe = _ref => {
17951
18014
  product,
17952
18015
  isExistingSource: isUsingExistingPaymentMethod,
17953
18016
  addressId: selectedAddressId,
17954
- fingerprint_session_id: state.cyberSourceSessionId
18017
+ fingerprint_session_id: state.cyberSourceSessionId,
18018
+ cardExpirationMonth: state.month,
18019
+ cardExpirationYear: state.year
17955
18020
  }, (err, res) => {
17956
18021
  if (err) {
17957
18022
  return handlePaymentError(err);
17958
18023
  }
18024
+
18025
+ // Reinitialize Cybersource microform after successful payment
18026
+ setTimeout(() => {
18027
+ cybersourceInstanceRef.current = null;
18028
+ initCybersourceScript();
18029
+ }, 1000);
17959
18030
  onSuccess(res);
17960
18031
  });
17961
18032
  }
17962
18033
  }
17963
18034
  }
17964
- const tokenizeCard = (error, microformInstance) => {
17965
- if (error) {
17966
- return;
17967
- }
17968
- cybersourceInstanceRef.current = microformInstance;
17969
- };
18035
+
18036
+ // No longer needed - microform instance is stored directly in initCybersourceScript
18037
+
17970
18038
  const appendCybersourceFingerprintScripts = () => {
17971
18039
  var _window$Pelcro$site$r, _window$Pelcro$site$r2, _window$Pelcro$site$r3, _window$Pelcro$site$r4;
17972
18040
  const uniqueId = crypto.randomUUID();
@@ -17990,6 +18058,12 @@ const PaymentMethodContainerWithoutStripe = _ref => {
17990
18058
  }
17991
18059
  };
17992
18060
  const initCybersourceScript = () => {
18061
+ // Clear existing card number field before reinitializing
18062
+ const cardNumberElement = document.querySelector("#cybersourceCardNumber");
18063
+ if (cardNumberElement) {
18064
+ cardNumberElement.innerHTML = "";
18065
+ }
18066
+
17993
18067
  // jwk api call
17994
18068
  window.Pelcro.payment.getJWK({
17995
18069
  auth_token: window.Pelcro.user.read().auth_token,
@@ -18014,34 +18088,56 @@ const PaymentMethodContainerWithoutStripe = _ref => {
18014
18088
  });
18015
18089
  }
18016
18090
  const {
18017
- key: jwk
18091
+ key: jwk,
18092
+ captureContext,
18093
+ js_client
18018
18094
  } = res;
18019
- // SETUP MICROFORM
18020
- FLEX.microform({
18021
- keyId: jwk.kid,
18022
- keystore: jwk,
18023
- container: "#cybersourceCardNumber",
18024
- placeholder: "Card Number",
18025
- styles: {
18026
- input: {
18027
- "font-size": "14px",
18028
- "font-family": "helvetica, tahoma, calibri, sans-serif",
18029
- color: "#555"
18030
- },
18031
- ":focus": {
18032
- color: "blue"
18033
- },
18034
- ":disabled": {
18035
- cursor: "not-allowed"
18036
- },
18037
- valid: {
18038
- color: "#3c763d"
18039
- },
18040
- invalid: {
18041
- color: "#a94442"
18095
+
18096
+ // Load the SDK from the dynamic URL (if not already loaded)
18097
+ const existingScript = document.querySelector(`script[src="${js_client}"]`);
18098
+ if (!existingScript) {
18099
+ window.Pelcro.helpers.loadSDK(js_client, "cybersource-cdn");
18100
+ }
18101
+ const initializeMicroform = () => {
18102
+ // SETUP MICROFORM
18103
+ // eslint-disable-next-line no-undef
18104
+ const flex = new Flex(captureContext);
18105
+ const microform = flex.microform({
18106
+ styles: {
18107
+ input: {
18108
+ "font-size": "14px",
18109
+ "font-family": "helvetica, tahoma, calibri, sans-serif",
18110
+ color: "#555"
18111
+ },
18112
+ ":focus": {
18113
+ color: "blue"
18114
+ },
18115
+ ":disabled": {
18116
+ cursor: "not-allowed"
18117
+ },
18118
+ valid: {
18119
+ color: "#3c763d"
18120
+ },
18121
+ invalid: {
18122
+ color: "#a94442"
18123
+ }
18042
18124
  }
18043
- }
18044
- }, tokenizeCard);
18125
+ });
18126
+ const number = microform.createField("number", {
18127
+ placeholder: "Enter your card number"
18128
+ });
18129
+ number.load("#cybersourceCardNumber");
18130
+ cybersourceInstanceRef.current = microform;
18131
+ };
18132
+
18133
+ // Wait for SDK to load then initialize microform
18134
+ if (existingScript) {
18135
+ // Script already loaded, initialize immediately
18136
+ initializeMicroform();
18137
+ } else {
18138
+ // Wait for new script to load
18139
+ document.querySelector(`script[src="${js_client}"]`).addEventListener("load", initializeMicroform);
18140
+ }
18045
18141
  });
18046
18142
  };
18047
18143
 
@@ -19155,13 +19251,7 @@ const PaymentMethodContainerWithoutStripe = _ref => {
19155
19251
  if (cardProcessor === "tap" && !selectedPaymentMethodId && window.Tapjsli) {
19156
19252
  initTapScript();
19157
19253
  }
19158
- if (cardProcessor === "cybersource" && !selectedPaymentMethodId && !window.FLEX) {
19159
- window.Pelcro.helpers.loadSDK("https://flex.cybersource.com/cybersource/assets/microform/0.4/flex-microform.min.js", "cybersource-cdn");
19160
- document.querySelector('script[src="https://flex.cybersource.com/cybersource/assets/microform/0.4/flex-microform.min.js"]').addEventListener("load", () => {
19161
- initCybersourceScript();
19162
- });
19163
- }
19164
- if (cardProcessor === "cybersource" && !selectedPaymentMethodId && window.FLEX) {
19254
+ if (cardProcessor === "cybersource" && !selectedPaymentMethodId) {
19165
19255
  initCybersourceScript();
19166
19256
  }
19167
19257
  if (cardProcessor === "cybersource") {
@@ -19677,7 +19767,10 @@ const PaymentMethodContainerWithoutStripe = _ref => {
19677
19767
  gift_recipient_last_name: giftRecipient === null || giftRecipient === void 0 ? void 0 : giftRecipient.lastName,
19678
19768
  gift_start_date: giftRecipient === null || giftRecipient === void 0 ? void 0 : giftRecipient.startDate,
19679
19769
  gift_message: giftRecipient === null || giftRecipient === void 0 ? void 0 : giftRecipient.giftMessage,
19680
- address_id: product.address_required ? selectedAddressId : null
19770
+ address_id: product.address_required ? selectedAddressId : null,
19771
+ metadata: props === null || props === void 0 ? void 0 : props.subCreateMetadata,
19772
+ cardExpirationMonth: state === null || state === void 0 ? void 0 : state.month,
19773
+ cardExpirationYear: state === null || state === void 0 ? void 0 : state.year
19681
19774
  }, (err, res) => {
19682
19775
  var _res$data;
19683
19776
  if (res !== null && res !== void 0 && (_res$data = res.data) !== null && _res$data !== void 0 && _res$data.setup_intent) {
@@ -19852,7 +19945,9 @@ const PaymentMethodContainerWithoutStripe = _ref => {
19852
19945
  isExistingSource: Boolean(selectedPaymentMethodId),
19853
19946
  items: mappedOrderItems,
19854
19947
  addressId: selectedAddressId,
19855
- couponCode
19948
+ couponCode,
19949
+ cardExpirationMonth: state === null || state === void 0 ? void 0 : state.month,
19950
+ cardExpirationYear: state === null || state === void 0 ? void 0 : state.year
19856
19951
  }, (err, orderResponse) => {
19857
19952
  var _window$Pelcro2, _window$Pelcro2$user, _window$Pelcro2$user$;
19858
19953
  if (err) {
@@ -20133,7 +20228,9 @@ const PaymentMethodContainerWithoutStripe = _ref => {
20133
20228
  campaign_key: window.Pelcro.helpers.getURLParameter("campaign_key"),
20134
20229
  ...(selectedAddressId && {
20135
20230
  address_id: selectedAddressId
20136
- })
20231
+ }),
20232
+ cardExpirationMonth: state === null || state === void 0 ? void 0 : state.month,
20233
+ cardExpirationYear: state === null || state === void 0 ? void 0 : state.year
20137
20234
  }, (err, res) => {
20138
20235
  if (err) {
20139
20236
  return handlePaymentError(err);
@@ -31537,6 +31634,123 @@ function getMemberShipStatus(status) {
31537
31634
  };
31538
31635
  }
31539
31636
 
31637
+ const EmailPreferencesMenu = props => {
31638
+ const {
31639
+ t
31640
+ } = useTranslation("dashboard");
31641
+ const [options, setOptions] = useState([]);
31642
+ const [loading, setLoading] = useState({});
31643
+ const [alert, setAlert] = useState({});
31644
+ const [isLoading, setIsLoading] = useState(true);
31645
+ const [error, setError] = useState(null);
31646
+ useEffect(() => {
31647
+ var _window$Pelcro, _window$Pelcro$uiSett, _window$Pelcro$user$r, _window$Pelcro$user$r2;
31648
+ const options = ((_window$Pelcro = window.Pelcro) === null || _window$Pelcro === void 0 ? void 0 : (_window$Pelcro$uiSett = _window$Pelcro.uiSettings) === null || _window$Pelcro$uiSett === void 0 ? void 0 : _window$Pelcro$uiSett.newsletters) || [];
31649
+ const email = (_window$Pelcro$user$r = (_window$Pelcro$user$r2 = window.Pelcro.user.read()) === null || _window$Pelcro$user$r2 === void 0 ? void 0 : _window$Pelcro$user$r2.email) !== null && _window$Pelcro$user$r !== void 0 ? _window$Pelcro$user$r : window.Pelcro.helpers.getURLParameter("email");
31650
+ setIsLoading(true);
31651
+ window.Pelcro.newsletter.getByEmail(email, (err, res) => {
31652
+ var _res$data$lists$split, _res$data, _res$data$lists;
31653
+ if (err) {
31654
+ setIsLoading(false);
31655
+ setError(t("messages.error") || "Failed to load preferences.");
31656
+ return;
31657
+ }
31658
+ const selectedIds = (_res$data$lists$split = res === null || res === void 0 ? void 0 : (_res$data = res.data) === null || _res$data === void 0 ? void 0 : (_res$data$lists = _res$data.lists) === null || _res$data$lists === void 0 ? void 0 : _res$data$lists.split(",")) !== null && _res$data$lists$split !== void 0 ? _res$data$lists$split : [];
31659
+ setOptions(options.map(opt => ({
31660
+ ...opt,
31661
+ id: String(opt.id),
31662
+ selected: selectedIds.includes(String(opt.id))
31663
+ })));
31664
+ setIsLoading(false);
31665
+ setError(null);
31666
+ });
31667
+ }, [t]);
31668
+ const handleCheckboxChange = id => e => {
31669
+ const checked = e.target.checked;
31670
+ setOptions(prevOptions => {
31671
+ var _window$Pelcro$user$r3, _window$Pelcro$user$r4;
31672
+ const newOptions = prevOptions.map(opt => opt.id === id ? {
31673
+ ...opt,
31674
+ selected: checked
31675
+ } : opt);
31676
+ // Set loading for this checkbox
31677
+ setLoading(prev => ({
31678
+ ...prev,
31679
+ [id]: true
31680
+ }));
31681
+ setAlert(prev => ({
31682
+ ...prev,
31683
+ [id]: null
31684
+ }));
31685
+ // Save to backend
31686
+ const selectedIds = newOptions.filter(opt => opt.selected).map(opt => opt.id);
31687
+ const email = (_window$Pelcro$user$r3 = (_window$Pelcro$user$r4 = window.Pelcro.user.read()) === null || _window$Pelcro$user$r4 === void 0 ? void 0 : _window$Pelcro$user$r4.email) !== null && _window$Pelcro$user$r3 !== void 0 ? _window$Pelcro$user$r3 : window.Pelcro.helpers.getURLParameter("email");
31688
+ const requestData = {
31689
+ email,
31690
+ source: "web",
31691
+ lists: selectedIds.join(",")
31692
+ };
31693
+
31694
+ // Check if this is a new subscription
31695
+ window.Pelcro.newsletter.getByEmail(email, (err, res) => {
31696
+ if (err) {
31697
+ setLoading(prev => ({
31698
+ ...prev,
31699
+ [id]: false
31700
+ }));
31701
+ setAlert(prev => ({
31702
+ ...prev,
31703
+ [id]: "Error checking subscription status"
31704
+ }));
31705
+ return;
31706
+ }
31707
+ const didSubToNewslettersBefore = Boolean(res.data.email);
31708
+ const callback = err => {
31709
+ setLoading(prev => ({
31710
+ ...prev,
31711
+ [id]: false
31712
+ }));
31713
+ setAlert(prev => ({
31714
+ ...prev,
31715
+ [id]: err ? "Error saving" : "Saved!"
31716
+ }));
31717
+ };
31718
+ if (didSubToNewslettersBefore) {
31719
+ window.Pelcro.newsletter.update(requestData, callback);
31720
+ } else {
31721
+ window.Pelcro.newsletter.create(requestData, callback);
31722
+ }
31723
+ });
31724
+ return newOptions;
31725
+ });
31726
+ };
31727
+ if (isLoading) return /*#__PURE__*/React__default.createElement("div", {
31728
+ className: "plc-flex plc-justify-center plc-items-center plc-h-32"
31729
+ }, /*#__PURE__*/React__default.createElement(Loader, {
31730
+ width: 60,
31731
+ height: 100
31732
+ }));
31733
+ if (error) return /*#__PURE__*/React__default.createElement("div", {
31734
+ className: "plc-text-red-600 plc-p-4"
31735
+ }, error);
31736
+ return /*#__PURE__*/React__default.createElement("div", null, /*#__PURE__*/React__default.createElement("div", {
31737
+ className: "plc-mb-4 plc-text-sm plc-text-gray-600"
31738
+ }, t("labels.emailPreferences.description") || "Select which email updates you would like to receive."), options.map(opt => /*#__PURE__*/React__default.createElement("div", {
31739
+ key: opt.id,
31740
+ className: "plc-flex plc-items-center plc-mb-2"
31741
+ }, /*#__PURE__*/React__default.createElement("input", {
31742
+ type: "checkbox",
31743
+ id: `email-pref-${opt.id}`,
31744
+ checked: !!opt.selected,
31745
+ onChange: handleCheckboxChange(opt.id),
31746
+ disabled: loading[opt.id],
31747
+ className: "plc-mr-2"
31748
+ }), /*#__PURE__*/React__default.createElement("label", {
31749
+ htmlFor: `email-pref-${opt.id}`,
31750
+ className: "plc-text-base"
31751
+ }, opt.label))));
31752
+ };
31753
+
31540
31754
  const SUB_MENUS = {
31541
31755
  PROFILE: "profile",
31542
31756
  SUBSCRIPTIONS: "subscriptions",
@@ -31547,7 +31761,8 @@ const SUB_MENUS = {
31547
31761
  GIFTS: "gifts",
31548
31762
  ORDERS: "orders",
31549
31763
  INVOICES: "invoices",
31550
- SAVED_ITEMS: "saved-items"
31764
+ SAVED_ITEMS: "saved-items",
31765
+ EMAIL_PREFERENCES: "email-preferences"
31551
31766
  };
31552
31767
 
31553
31768
  /**
@@ -32041,13 +32256,14 @@ class Dashboard extends Component {
32041
32256
  this.enableReactGA4 = (_window = window) === null || _window === void 0 ? void 0 : (_window$Pelcro = _window.Pelcro) === null || _window$Pelcro === void 0 ? void 0 : (_window$Pelcro$uiSett = _window$Pelcro.uiSettings) === null || _window$Pelcro$uiSett === void 0 ? void 0 : _window$Pelcro$uiSett.enableReactGA4;
32042
32257
  }
32043
32258
  render() {
32044
- var _window$Pelcro$user$r3, _window$Pelcro2, _window$Pelcro2$uiSet;
32259
+ var _window$Pelcro$user$r3, _window$Pelcro2, _window$Pelcro2$uiSet, _window$Pelcro3, _window$Pelcro3$uiSet;
32045
32260
  const {
32046
32261
  isOpen
32047
32262
  } = this.state;
32048
32263
  const userHasName = this.user.first_name || this.user.last_name;
32049
32264
  const profilePicture = (_window$Pelcro$user$r3 = window.Pelcro.user.read().profile_photo) !== null && _window$Pelcro$user$r3 !== void 0 ? _window$Pelcro$user$r3 : userSolidIcon;
32050
32265
  const newsletters = (_window$Pelcro2 = window.Pelcro) === null || _window$Pelcro2 === void 0 ? void 0 : (_window$Pelcro2$uiSet = _window$Pelcro2.uiSettings) === null || _window$Pelcro2$uiSet === void 0 ? void 0 : _window$Pelcro2$uiSet.newsletters;
32266
+ const emailNotifications = (_window$Pelcro3 = window.Pelcro) === null || _window$Pelcro3 === void 0 ? void 0 : (_window$Pelcro3$uiSet = _window$Pelcro3.uiSettings) === null || _window$Pelcro3$uiSet === void 0 ? void 0 : _window$Pelcro3$uiSet.emailNotifications;
32051
32267
  const siteHasNewslettersDefined = Array.isArray(newsletters) && newsletters.length > 0;
32052
32268
  return /*#__PURE__*/React__default.createElement(Transition, {
32053
32269
  className: "plc-fixed plc-inset-y-0 plc-right-0 plc-h-full plc-max-w-xl plc-overflow-y-auto plc-text-left plc-bg-white plc-shadow-xl plc-z-max",
@@ -32125,7 +32341,7 @@ class Dashboard extends Component {
32125
32341
  }),
32126
32342
  className: "plc-text-sm plc-text-gray-500 hover:plc-text-primary-700",
32127
32343
  onClick: this.displayChangePassword
32128
- }, this.locale("labels.changePassword")), siteHasNewslettersDefined && /*#__PURE__*/React__default.createElement(Button, {
32344
+ }, this.locale("labels.changePassword")), siteHasNewslettersDefined && emailNotifications !== true && /*#__PURE__*/React__default.createElement(Button, {
32129
32345
  variant: "ghost",
32130
32346
  icon: /*#__PURE__*/React__default.createElement(SvgNewsletter, {
32131
32347
  className: "plc-w-5 plc-h-5 plc-mr-1"
@@ -32215,6 +32431,12 @@ class Dashboard extends Component {
32215
32431
  icon: /*#__PURE__*/React__default.createElement(SvgBookmark, null),
32216
32432
  title: this.locale("labels.savedItems.label"),
32217
32433
  content: /*#__PURE__*/React__default.createElement(SavedItemsMenu, null)
32434
+ }), /*#__PURE__*/React__default.createElement(Accordion.item, {
32435
+ show: emailNotifications === true,
32436
+ name: SUB_MENUS.EMAIL_PREFERENCES,
32437
+ icon: /*#__PURE__*/React__default.createElement(SvgBookmark, null),
32438
+ title: this.locale("labels.emailPreferences.label"),
32439
+ content: /*#__PURE__*/React__default.createElement(EmailPreferencesMenu, null)
32218
32440
  }), /*#__PURE__*/React__default.createElement(Button, {
32219
32441
  variant: "outline",
32220
32442
  icon: /*#__PURE__*/React__default.createElement(SvgExit, null),
package/dist/pelcro.css CHANGED
@@ -2838,6 +2838,11 @@ apple-pay-button {
2838
2838
  color: rgba(180, 48, 43, var(--tw-text-opacity));
2839
2839
  }
2840
2840
 
2841
+ .pelcro-root .plc-text-red-600 {
2842
+ --tw-text-opacity: 1;
2843
+ color: rgba(139, 37, 33, var(--tw-text-opacity));
2844
+ }
2845
+
2841
2846
  .pelcro-root .plc-text-red-700 {
2842
2847
  --tw-text-opacity: 1;
2843
2848
  color: rgba(98, 26, 23, var(--tw-text-opacity));
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.48.0",
4
+ "version": "3.50.0",
5
5
  "license": "MIT",
6
6
  "private": false,
7
7
  "main": "dist/index.cjs.js",