@pelcro/react-pelcro-js 3.2.0-beta.12 → 3.2.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
@@ -3244,7 +3244,8 @@ function withTranslation(ns) {
3244
3244
  var validation$1 = {
3245
3245
  validEmail: "le courriel n’est pas valide",
3246
3246
  enterEmail: "Un courriel est requis.",
3247
- enterPassword: "Mot de passe requis."
3247
+ enterPassword: "Mot de passe requis.",
3248
+ confirmPassword: "Confirmer le mot de passe requis."
3248
3249
  };
3249
3250
  var buttons$9 = {
3250
3251
  account: "Accès abonné(e)s",
@@ -3332,7 +3333,8 @@ var common_fr = {
3332
3333
  var validation = {
3333
3334
  validEmail: "Email address is not valid.",
3334
3335
  enterEmail: "Email address is required.",
3335
- enterPassword: "Password is required."
3336
+ enterPassword: "Password is required.",
3337
+ confirmPassword: "Confirm password is required."
3336
3338
  };
3337
3339
  var buttons$8 = {
3338
3340
  account: "My account",
@@ -6436,6 +6438,19 @@ if (process.env.NODE_ENV === "development") {
6436
6438
  c$1("Pelcro Store", usePelcro);
6437
6439
  }
6438
6440
 
6441
+ /**
6442
+ * List of zero-decimal currencies.
6443
+ * @see https://stripe.com/docs/currencies#zero-decimal
6444
+ *
6445
+ */
6446
+
6447
+ const ZERO_DECIMAL_CURRENCIES = ['BIF', 'CLP', 'DJF', 'GNF', 'JPY', 'KMF', 'KRW', 'MGA', 'PYG', 'RWF', 'UGX', 'VND', 'VUV', 'XAF', 'XOF', 'XPF'];
6448
+ /**
6449
+ * @param {string}
6450
+ * @return {boolean}
6451
+ */
6452
+
6453
+ const isCurrencyZeroDecimal = currency => ZERO_DECIMAL_CURRENCIES.includes(currency);
6439
6454
  const sortCountries = countries => {
6440
6455
  const sortable = [];
6441
6456
  delete countries.CA;
@@ -6522,7 +6537,7 @@ const getFormattedPriceByLocal = (amount, currency = "USD", locale = "en") => {
6522
6537
  style: "currency",
6523
6538
  currency
6524
6539
  });
6525
- return formatter.format(amount / 100);
6540
+ return isCurrencyZeroDecimal(currency) ? formatter.format(amount) : formatter.format(amount / 100);
6526
6541
  };
6527
6542
  /** check wether or not the user have any addresses
6528
6543
  * @return {boolean} true if the user have at least one address, false otherwise
@@ -6539,7 +6554,7 @@ const calcAndFormatItemsTotal = (items, currency) => {
6539
6554
  let totalWithoutDividingBy100 = 0;
6540
6555
 
6541
6556
  for (const item of items) {
6542
- totalWithoutDividingBy100 += parseFloat(item.price ? (item.price * item.quantity).toFixed(2) : item.amount.toFixed(2));
6557
+ totalWithoutDividingBy100 += parseFloat(item.price ? isCurrencyZeroDecimal(currency) ? item.price * item.quantity : (item.price * item.quantity).toFixed(2) : isCurrencyZeroDecimal(currency) ? item.amount : item.amount.toFixed(2));
6543
6558
  }
6544
6559
 
6545
6560
  return getFormattedPriceByLocal(totalWithoutDividingBy100, currency, getPageOrDefaultLanguage());
@@ -6619,7 +6634,7 @@ const disableScroll = () => {
6619
6634
  }
6620
6635
  };
6621
6636
  const trackSubscriptionOnGA = () => {
6622
- var _ReactGA$set, _window$Pelcro$user$r5, _window$Pelcro$user$r6, _ReactGA$plugin, _ReactGA$plugin$execu, _ReactGA$plugin2, _ReactGA$plugin2$exec, _ReactGA$plugin3, _ReactGA$plugin3$exec, _ReactGA$event;
6637
+ var _window$Pelcro$user$r5, _window$Pelcro$user$r6, _ReactGA$set, _ReactGA$plugin, _ReactGA$plugin$execu, _ReactGA$plugin2, _ReactGA$plugin2$exec, _ReactGA$plugin3, _ReactGA$plugin3$exec, _ReactGA$event;
6623
6638
 
6624
6639
  const {
6625
6640
  product,
@@ -6640,13 +6655,14 @@ const trackSubscriptionOnGA = () => {
6640
6655
  return;
6641
6656
  }
6642
6657
 
6658
+ const currencyCode = (_window$Pelcro$user$r5 = (_window$Pelcro$user$r6 = window.Pelcro.user.read()) === null || _window$Pelcro$user$r6 === void 0 ? void 0 : _window$Pelcro$user$r6.currency) !== null && _window$Pelcro$user$r5 !== void 0 ? _window$Pelcro$user$r5 : plan.currency;
6643
6659
  ReactGA === null || ReactGA === void 0 ? void 0 : (_ReactGA$set = ReactGA.set) === null || _ReactGA$set === void 0 ? void 0 : _ReactGA$set.call(ReactGA, {
6644
- currencyCode: (_window$Pelcro$user$r5 = (_window$Pelcro$user$r6 = window.Pelcro.user.read()) === null || _window$Pelcro$user$r6 === void 0 ? void 0 : _window$Pelcro$user$r6.currency) !== null && _window$Pelcro$user$r5 !== void 0 ? _window$Pelcro$user$r5 : plan.currency
6660
+ currencyCode: currencyCode
6645
6661
  });
6646
6662
  ReactGA === null || ReactGA === void 0 ? void 0 : (_ReactGA$plugin = ReactGA.plugin) === null || _ReactGA$plugin === void 0 ? void 0 : (_ReactGA$plugin$execu = _ReactGA$plugin.execute) === null || _ReactGA$plugin$execu === void 0 ? void 0 : _ReactGA$plugin$execu.call(_ReactGA$plugin, "ecommerce", "addTransaction", {
6647
6663
  id: lastSubscriptionId,
6648
6664
  affiliation: "Pelcro",
6649
- revenue: plan !== null && plan !== void 0 && plan.amount ? plan.amount / 100 : 0,
6665
+ revenue: plan !== null && plan !== void 0 && plan.amount ? isCurrencyZeroDecimal(currencyCode) ? plan.amount : plan.amount / 100 : 0,
6650
6666
  coupon: couponCode
6651
6667
  });
6652
6668
  ReactGA === null || ReactGA === void 0 ? void 0 : (_ReactGA$plugin2 = ReactGA.plugin) === null || _ReactGA$plugin2 === void 0 ? void 0 : (_ReactGA$plugin2$exec = _ReactGA$plugin2.execute) === null || _ReactGA$plugin2$exec === void 0 ? void 0 : _ReactGA$plugin2$exec.call(_ReactGA$plugin2, "ecommerce", "addItem", {
@@ -6654,7 +6670,7 @@ const trackSubscriptionOnGA = () => {
6654
6670
  name: product.name,
6655
6671
  category: product.description,
6656
6672
  variant: plan.nickname,
6657
- price: plan !== null && plan !== void 0 && plan.amount ? plan.amount / 100 : 0,
6673
+ price: plan !== null && plan !== void 0 && plan.amount ? isCurrencyZeroDecimal(currencyCode) ? plan.amount : plan.amount / 100 : 0,
6658
6674
  quantity: 1
6659
6675
  });
6660
6676
  ReactGA === null || ReactGA === void 0 ? void 0 : (_ReactGA$plugin3 = ReactGA.plugin) === null || _ReactGA$plugin3 === void 0 ? void 0 : (_ReactGA$plugin3$exec = _ReactGA$plugin3.execute) === null || _ReactGA$plugin3$exec === void 0 ? void 0 : _ReactGA$plugin3$exec.call(_ReactGA$plugin3, "ecommerce", "send");
@@ -8649,17 +8665,21 @@ const getErrorMessages = error => {
8649
8665
  return error === null || error === void 0 ? void 0 : (_error$response4 = error.response) === null || _error$response4 === void 0 ? void 0 : (_error$response4$data = _error$response4.data) === null || _error$response4$data === void 0 ? void 0 : (_error$response4$data2 = _error$response4$data.error) === null || _error$response4$data2 === void 0 ? void 0 : _error$response4$data2.message;
8650
8666
  }
8651
8667
 
8652
- if (error !== null && error !== void 0 && error.message) {
8653
- return error.message;
8654
- }
8668
+ if (error !== null && error !== void 0 && (_error$response5 = error.response) !== null && _error$response5 !== void 0 && (_error$response5$data = _error$response5.data) !== null && _error$response5$data !== void 0 && _error$response5$data.errors) {
8669
+ var _error$response6, _error$response6$data;
8670
+
8671
+ const errorMessages = []; // enumerable error (ex: validation errors)
8655
8672
 
8656
- const errorMessages = []; // enumerable error (ex: validation errors)
8673
+ Object.values(error === null || error === void 0 ? void 0 : (_error$response6 = error.response) === null || _error$response6 === void 0 ? void 0 : (_error$response6$data = _error$response6.data) === null || _error$response6$data === void 0 ? void 0 : _error$response6$data.errors).forEach(([errorMessage]) => {
8674
+ errorMessages.push(errorMessage);
8675
+ }); // convert to multiline string
8657
8676
 
8658
- Object.values(error === null || error === void 0 ? void 0 : (_error$response5 = error.response) === null || _error$response5 === void 0 ? void 0 : (_error$response5$data = _error$response5.data) === null || _error$response5$data === void 0 ? void 0 : _error$response5$data.errors).forEach(([errorMessage]) => {
8659
- errorMessages.push(errorMessage);
8660
- }); // convert to multiline string
8677
+ return errorMessages.join("\n");
8678
+ }
8661
8679
 
8662
- return errorMessages.join("\n");
8680
+ if (error !== null && error !== void 0 && error.message) {
8681
+ return error.message;
8682
+ }
8663
8683
  };
8664
8684
  /**
8665
8685
  * Executes function after a wait time of inactivity
@@ -9841,6 +9861,9 @@ function ConfirmPassword({
9841
9861
  store,
9842
9862
  ...otherProps
9843
9863
  }) {
9864
+ const {
9865
+ t
9866
+ } = useTranslation("common");
9844
9867
  const {
9845
9868
  dispatch,
9846
9869
  state: {
@@ -9865,7 +9888,7 @@ function ConfirmPassword({
9865
9888
  } else if (finishedTyping) {
9866
9889
  dispatch({
9867
9890
  type: SET_CONFIRM_PASSWORD_ERROR,
9868
- payload: "Confirm password is required."
9891
+ payload: t("validation.confirmPassword")
9869
9892
  });
9870
9893
  }
9871
9894
  }, [dispatch, password, finishedTyping]);
package/dist/index.esm.js CHANGED
@@ -3214,7 +3214,8 @@ function withTranslation(ns) {
3214
3214
  var validation$1 = {
3215
3215
  validEmail: "le courriel n’est pas valide",
3216
3216
  enterEmail: "Un courriel est requis.",
3217
- enterPassword: "Mot de passe requis."
3217
+ enterPassword: "Mot de passe requis.",
3218
+ confirmPassword: "Confirmer le mot de passe requis."
3218
3219
  };
3219
3220
  var buttons$9 = {
3220
3221
  account: "Accès abonné(e)s",
@@ -3302,7 +3303,8 @@ var common_fr = {
3302
3303
  var validation = {
3303
3304
  validEmail: "Email address is not valid.",
3304
3305
  enterEmail: "Email address is required.",
3305
- enterPassword: "Password is required."
3306
+ enterPassword: "Password is required.",
3307
+ confirmPassword: "Confirm password is required."
3306
3308
  };
3307
3309
  var buttons$8 = {
3308
3310
  account: "My account",
@@ -6406,6 +6408,19 @@ if (process.env.NODE_ENV === "development") {
6406
6408
  c$1("Pelcro Store", usePelcro);
6407
6409
  }
6408
6410
 
6411
+ /**
6412
+ * List of zero-decimal currencies.
6413
+ * @see https://stripe.com/docs/currencies#zero-decimal
6414
+ *
6415
+ */
6416
+
6417
+ const ZERO_DECIMAL_CURRENCIES = ['BIF', 'CLP', 'DJF', 'GNF', 'JPY', 'KMF', 'KRW', 'MGA', 'PYG', 'RWF', 'UGX', 'VND', 'VUV', 'XAF', 'XOF', 'XPF'];
6418
+ /**
6419
+ * @param {string}
6420
+ * @return {boolean}
6421
+ */
6422
+
6423
+ const isCurrencyZeroDecimal = currency => ZERO_DECIMAL_CURRENCIES.includes(currency);
6409
6424
  const sortCountries = countries => {
6410
6425
  const sortable = [];
6411
6426
  delete countries.CA;
@@ -6492,7 +6507,7 @@ const getFormattedPriceByLocal = (amount, currency = "USD", locale = "en") => {
6492
6507
  style: "currency",
6493
6508
  currency
6494
6509
  });
6495
- return formatter.format(amount / 100);
6510
+ return isCurrencyZeroDecimal(currency) ? formatter.format(amount) : formatter.format(amount / 100);
6496
6511
  };
6497
6512
  /** check wether or not the user have any addresses
6498
6513
  * @return {boolean} true if the user have at least one address, false otherwise
@@ -6509,7 +6524,7 @@ const calcAndFormatItemsTotal = (items, currency) => {
6509
6524
  let totalWithoutDividingBy100 = 0;
6510
6525
 
6511
6526
  for (const item of items) {
6512
- totalWithoutDividingBy100 += parseFloat(item.price ? (item.price * item.quantity).toFixed(2) : item.amount.toFixed(2));
6527
+ totalWithoutDividingBy100 += parseFloat(item.price ? isCurrencyZeroDecimal(currency) ? item.price * item.quantity : (item.price * item.quantity).toFixed(2) : isCurrencyZeroDecimal(currency) ? item.amount : item.amount.toFixed(2));
6513
6528
  }
6514
6529
 
6515
6530
  return getFormattedPriceByLocal(totalWithoutDividingBy100, currency, getPageOrDefaultLanguage());
@@ -6589,7 +6604,7 @@ const disableScroll = () => {
6589
6604
  }
6590
6605
  };
6591
6606
  const trackSubscriptionOnGA = () => {
6592
- var _ReactGA$set, _window$Pelcro$user$r5, _window$Pelcro$user$r6, _ReactGA$plugin, _ReactGA$plugin$execu, _ReactGA$plugin2, _ReactGA$plugin2$exec, _ReactGA$plugin3, _ReactGA$plugin3$exec, _ReactGA$event;
6607
+ var _window$Pelcro$user$r5, _window$Pelcro$user$r6, _ReactGA$set, _ReactGA$plugin, _ReactGA$plugin$execu, _ReactGA$plugin2, _ReactGA$plugin2$exec, _ReactGA$plugin3, _ReactGA$plugin3$exec, _ReactGA$event;
6593
6608
 
6594
6609
  const {
6595
6610
  product,
@@ -6610,13 +6625,14 @@ const trackSubscriptionOnGA = () => {
6610
6625
  return;
6611
6626
  }
6612
6627
 
6628
+ const currencyCode = (_window$Pelcro$user$r5 = (_window$Pelcro$user$r6 = window.Pelcro.user.read()) === null || _window$Pelcro$user$r6 === void 0 ? void 0 : _window$Pelcro$user$r6.currency) !== null && _window$Pelcro$user$r5 !== void 0 ? _window$Pelcro$user$r5 : plan.currency;
6613
6629
  ReactGA === null || ReactGA === void 0 ? void 0 : (_ReactGA$set = ReactGA.set) === null || _ReactGA$set === void 0 ? void 0 : _ReactGA$set.call(ReactGA, {
6614
- currencyCode: (_window$Pelcro$user$r5 = (_window$Pelcro$user$r6 = window.Pelcro.user.read()) === null || _window$Pelcro$user$r6 === void 0 ? void 0 : _window$Pelcro$user$r6.currency) !== null && _window$Pelcro$user$r5 !== void 0 ? _window$Pelcro$user$r5 : plan.currency
6630
+ currencyCode: currencyCode
6615
6631
  });
6616
6632
  ReactGA === null || ReactGA === void 0 ? void 0 : (_ReactGA$plugin = ReactGA.plugin) === null || _ReactGA$plugin === void 0 ? void 0 : (_ReactGA$plugin$execu = _ReactGA$plugin.execute) === null || _ReactGA$plugin$execu === void 0 ? void 0 : _ReactGA$plugin$execu.call(_ReactGA$plugin, "ecommerce", "addTransaction", {
6617
6633
  id: lastSubscriptionId,
6618
6634
  affiliation: "Pelcro",
6619
- revenue: plan !== null && plan !== void 0 && plan.amount ? plan.amount / 100 : 0,
6635
+ revenue: plan !== null && plan !== void 0 && plan.amount ? isCurrencyZeroDecimal(currencyCode) ? plan.amount : plan.amount / 100 : 0,
6620
6636
  coupon: couponCode
6621
6637
  });
6622
6638
  ReactGA === null || ReactGA === void 0 ? void 0 : (_ReactGA$plugin2 = ReactGA.plugin) === null || _ReactGA$plugin2 === void 0 ? void 0 : (_ReactGA$plugin2$exec = _ReactGA$plugin2.execute) === null || _ReactGA$plugin2$exec === void 0 ? void 0 : _ReactGA$plugin2$exec.call(_ReactGA$plugin2, "ecommerce", "addItem", {
@@ -6624,7 +6640,7 @@ const trackSubscriptionOnGA = () => {
6624
6640
  name: product.name,
6625
6641
  category: product.description,
6626
6642
  variant: plan.nickname,
6627
- price: plan !== null && plan !== void 0 && plan.amount ? plan.amount / 100 : 0,
6643
+ price: plan !== null && plan !== void 0 && plan.amount ? isCurrencyZeroDecimal(currencyCode) ? plan.amount : plan.amount / 100 : 0,
6628
6644
  quantity: 1
6629
6645
  });
6630
6646
  ReactGA === null || ReactGA === void 0 ? void 0 : (_ReactGA$plugin3 = ReactGA.plugin) === null || _ReactGA$plugin3 === void 0 ? void 0 : (_ReactGA$plugin3$exec = _ReactGA$plugin3.execute) === null || _ReactGA$plugin3$exec === void 0 ? void 0 : _ReactGA$plugin3$exec.call(_ReactGA$plugin3, "ecommerce", "send");
@@ -8619,17 +8635,21 @@ const getErrorMessages = error => {
8619
8635
  return error === null || error === void 0 ? void 0 : (_error$response4 = error.response) === null || _error$response4 === void 0 ? void 0 : (_error$response4$data = _error$response4.data) === null || _error$response4$data === void 0 ? void 0 : (_error$response4$data2 = _error$response4$data.error) === null || _error$response4$data2 === void 0 ? void 0 : _error$response4$data2.message;
8620
8636
  }
8621
8637
 
8622
- if (error !== null && error !== void 0 && error.message) {
8623
- return error.message;
8624
- }
8638
+ if (error !== null && error !== void 0 && (_error$response5 = error.response) !== null && _error$response5 !== void 0 && (_error$response5$data = _error$response5.data) !== null && _error$response5$data !== void 0 && _error$response5$data.errors) {
8639
+ var _error$response6, _error$response6$data;
8640
+
8641
+ const errorMessages = []; // enumerable error (ex: validation errors)
8625
8642
 
8626
- const errorMessages = []; // enumerable error (ex: validation errors)
8643
+ Object.values(error === null || error === void 0 ? void 0 : (_error$response6 = error.response) === null || _error$response6 === void 0 ? void 0 : (_error$response6$data = _error$response6.data) === null || _error$response6$data === void 0 ? void 0 : _error$response6$data.errors).forEach(([errorMessage]) => {
8644
+ errorMessages.push(errorMessage);
8645
+ }); // convert to multiline string
8627
8646
 
8628
- Object.values(error === null || error === void 0 ? void 0 : (_error$response5 = error.response) === null || _error$response5 === void 0 ? void 0 : (_error$response5$data = _error$response5.data) === null || _error$response5$data === void 0 ? void 0 : _error$response5$data.errors).forEach(([errorMessage]) => {
8629
- errorMessages.push(errorMessage);
8630
- }); // convert to multiline string
8647
+ return errorMessages.join("\n");
8648
+ }
8631
8649
 
8632
- return errorMessages.join("\n");
8650
+ if (error !== null && error !== void 0 && error.message) {
8651
+ return error.message;
8652
+ }
8633
8653
  };
8634
8654
  /**
8635
8655
  * Executes function after a wait time of inactivity
@@ -9811,6 +9831,9 @@ function ConfirmPassword({
9811
9831
  store,
9812
9832
  ...otherProps
9813
9833
  }) {
9834
+ const {
9835
+ t
9836
+ } = useTranslation("common");
9814
9837
  const {
9815
9838
  dispatch,
9816
9839
  state: {
@@ -9835,7 +9858,7 @@ function ConfirmPassword({
9835
9858
  } else if (finishedTyping) {
9836
9859
  dispatch({
9837
9860
  type: SET_CONFIRM_PASSWORD_ERROR,
9838
- payload: "Confirm password is required."
9861
+ payload: t("validation.confirmPassword")
9839
9862
  });
9840
9863
  }
9841
9864
  }, [dispatch, password, finishedTyping]);
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.2.0-beta.12",
4
+ "version": "3.2.0-beta.15",
5
5
  "license": "MIT",
6
6
  "private": false,
7
7
  "main": "dist/index.cjs.js",