@pelcro/react-pelcro-js 3.0.0-beta.1 → 3.0.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
@@ -10288,15 +10288,32 @@ const Auth0LoginButton = ({
10288
10288
  iconClassName = ""
10289
10289
  }) => {
10290
10290
  const auth0Enabled = Boolean(window.Pelcro.site.read().auth0_client_id && window.Pelcro.site.read().auth0_base_url);
10291
+ const auth0Script = document.querySelector("#auth0-sdk");
10292
+ const [auth0Loaded, setAuth0Loaded] = React.useState(Boolean(window.auth0));
10293
+ React__default['default'].useEffect(() => {
10294
+ function handleScriptLoaded() {
10295
+ setAuth0Loaded(true);
10296
+ }
10297
+
10298
+ if (auth0Enabled && !auth0Loaded) {
10299
+ auth0Script.addEventListener("load", handleScriptLoaded);
10300
+ }
10301
+
10302
+ return () => {
10303
+ var _auth0Script$removeEv;
10304
+
10305
+ auth0Script === null || auth0Script === void 0 ? void 0 : (_auth0Script$removeEv = auth0Script.removeEventListener) === null || _auth0Script$removeEv === void 0 ? void 0 : _auth0Script$removeEv.call(auth0Script, "load", handleScriptLoaded);
10306
+ };
10307
+ }, [auth0Script, auth0Enabled, auth0Loaded]);
10291
10308
  const auth0InstanceRef = React__default['default'].useRef(null);
10292
10309
  React__default['default'].useEffect(() => {
10293
- if (auth0Enabled && window.auth0 && auth0InstanceRef.current === null) {
10310
+ if (auth0Enabled && auth0Loaded && auth0InstanceRef.current === null) {
10294
10311
  auth0InstanceRef.current = new window.auth0.WebAuth({
10295
10312
  domain: window.Pelcro.site.read().auth0_base_url,
10296
10313
  clientID: window.Pelcro.site.read().auth0_client_id
10297
10314
  });
10298
10315
  }
10299
- }, [auth0Enabled, window.auth0]);
10316
+ }, [auth0Enabled, auth0Loaded]);
10300
10317
  const {
10301
10318
  dispatch: loginDispatch
10302
10319
  } = React.useContext(store$g);
@@ -10307,7 +10324,7 @@ const Auth0LoginButton = ({
10307
10324
  function handleClick() {
10308
10325
  var _auth0InstanceRef$cur, _auth0InstanceRef$cur2, _auth0InstanceRef$cur3;
10309
10326
 
10310
- if (!window.auth0) {
10327
+ if (!auth0Loaded) {
10311
10328
  return console.error("Auth0 sdk script wasn't loaded, you need to load auth0 sdk before rendering the Auth0LoginButton");
10312
10329
  }
10313
10330
 
@@ -19759,6 +19776,11 @@ const moveDefaultPaymentMethodToStart = paymentMethods => {
19759
19776
 
19760
19777
  const defaultPaymentMethod = (_window$Pelcro$user$r = window.Pelcro.user.read()) === null || _window$Pelcro$user$r === void 0 ? void 0 : _window$Pelcro$user$r.source;
19761
19778
  const paymentMethodsWithoutDefault = paymentMethods.filter(paymentMethod => paymentMethod.id !== defaultPaymentMethod.id);
19779
+
19780
+ if (defaultPaymentMethod.status !== "chargeable") {
19781
+ return paymentMethodsWithoutDefault;
19782
+ }
19783
+
19762
19784
  return [defaultPaymentMethod, ...paymentMethodsWithoutDefault];
19763
19785
  };
19764
19786
 
package/dist/index.esm.js CHANGED
@@ -10258,15 +10258,32 @@ const Auth0LoginButton = ({
10258
10258
  iconClassName = ""
10259
10259
  }) => {
10260
10260
  const auth0Enabled = Boolean(window.Pelcro.site.read().auth0_client_id && window.Pelcro.site.read().auth0_base_url);
10261
+ const auth0Script = document.querySelector("#auth0-sdk");
10262
+ const [auth0Loaded, setAuth0Loaded] = useState(Boolean(window.auth0));
10263
+ React__default.useEffect(() => {
10264
+ function handleScriptLoaded() {
10265
+ setAuth0Loaded(true);
10266
+ }
10267
+
10268
+ if (auth0Enabled && !auth0Loaded) {
10269
+ auth0Script.addEventListener("load", handleScriptLoaded);
10270
+ }
10271
+
10272
+ return () => {
10273
+ var _auth0Script$removeEv;
10274
+
10275
+ auth0Script === null || auth0Script === void 0 ? void 0 : (_auth0Script$removeEv = auth0Script.removeEventListener) === null || _auth0Script$removeEv === void 0 ? void 0 : _auth0Script$removeEv.call(auth0Script, "load", handleScriptLoaded);
10276
+ };
10277
+ }, [auth0Script, auth0Enabled, auth0Loaded]);
10261
10278
  const auth0InstanceRef = React__default.useRef(null);
10262
10279
  React__default.useEffect(() => {
10263
- if (auth0Enabled && window.auth0 && auth0InstanceRef.current === null) {
10280
+ if (auth0Enabled && auth0Loaded && auth0InstanceRef.current === null) {
10264
10281
  auth0InstanceRef.current = new window.auth0.WebAuth({
10265
10282
  domain: window.Pelcro.site.read().auth0_base_url,
10266
10283
  clientID: window.Pelcro.site.read().auth0_client_id
10267
10284
  });
10268
10285
  }
10269
- }, [auth0Enabled, window.auth0]);
10286
+ }, [auth0Enabled, auth0Loaded]);
10270
10287
  const {
10271
10288
  dispatch: loginDispatch
10272
10289
  } = useContext(store$g);
@@ -10277,7 +10294,7 @@ const Auth0LoginButton = ({
10277
10294
  function handleClick() {
10278
10295
  var _auth0InstanceRef$cur, _auth0InstanceRef$cur2, _auth0InstanceRef$cur3;
10279
10296
 
10280
- if (!window.auth0) {
10297
+ if (!auth0Loaded) {
10281
10298
  return console.error("Auth0 sdk script wasn't loaded, you need to load auth0 sdk before rendering the Auth0LoginButton");
10282
10299
  }
10283
10300
 
@@ -19729,6 +19746,11 @@ const moveDefaultPaymentMethodToStart = paymentMethods => {
19729
19746
 
19730
19747
  const defaultPaymentMethod = (_window$Pelcro$user$r = window.Pelcro.user.read()) === null || _window$Pelcro$user$r === void 0 ? void 0 : _window$Pelcro$user$r.source;
19731
19748
  const paymentMethodsWithoutDefault = paymentMethods.filter(paymentMethod => paymentMethod.id !== defaultPaymentMethod.id);
19749
+
19750
+ if (defaultPaymentMethod.status !== "chargeable") {
19751
+ return paymentMethodsWithoutDefault;
19752
+ }
19753
+
19732
19754
  return [defaultPaymentMethod, ...paymentMethodsWithoutDefault];
19733
19755
  };
19734
19756
 
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.0.0-beta.1",
4
+ "version": "3.0.0",
5
5
  "license": "MIT",
6
6
  "private": false,
7
7
  "main": "dist/index.cjs.js",