@pelcro/react-pelcro-js 3.0.0-beta.1 → 3.0.0-beta.2

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,30 @@ 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
+ auth0Script.removeEventListener("load", handleScriptLoaded);
10304
+ };
10305
+ }, [auth0Script, auth0Enabled, auth0Loaded]);
10291
10306
  const auth0InstanceRef = React__default['default'].useRef(null);
10292
10307
  React__default['default'].useEffect(() => {
10293
- if (auth0Enabled && window.auth0 && auth0InstanceRef.current === null) {
10308
+ if (auth0Enabled && auth0Loaded && auth0InstanceRef.current === null) {
10294
10309
  auth0InstanceRef.current = new window.auth0.WebAuth({
10295
10310
  domain: window.Pelcro.site.read().auth0_base_url,
10296
10311
  clientID: window.Pelcro.site.read().auth0_client_id
10297
10312
  });
10298
10313
  }
10299
- }, [auth0Enabled, window.auth0]);
10314
+ }, [auth0Enabled, auth0Loaded]);
10300
10315
  const {
10301
10316
  dispatch: loginDispatch
10302
10317
  } = React.useContext(store$g);
@@ -10307,7 +10322,7 @@ const Auth0LoginButton = ({
10307
10322
  function handleClick() {
10308
10323
  var _auth0InstanceRef$cur, _auth0InstanceRef$cur2, _auth0InstanceRef$cur3;
10309
10324
 
10310
- if (!window.auth0) {
10325
+ if (!auth0Loaded) {
10311
10326
  return console.error("Auth0 sdk script wasn't loaded, you need to load auth0 sdk before rendering the Auth0LoginButton");
10312
10327
  }
10313
10328
 
@@ -19759,6 +19774,11 @@ const moveDefaultPaymentMethodToStart = paymentMethods => {
19759
19774
 
19760
19775
  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
19776
  const paymentMethodsWithoutDefault = paymentMethods.filter(paymentMethod => paymentMethod.id !== defaultPaymentMethod.id);
19777
+
19778
+ if (defaultPaymentMethod.status !== "chargeable") {
19779
+ return paymentMethodsWithoutDefault;
19780
+ }
19781
+
19762
19782
  return [defaultPaymentMethod, ...paymentMethodsWithoutDefault];
19763
19783
  };
19764
19784
 
package/dist/index.esm.js CHANGED
@@ -10258,15 +10258,30 @@ 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
+ auth0Script.removeEventListener("load", handleScriptLoaded);
10274
+ };
10275
+ }, [auth0Script, auth0Enabled, auth0Loaded]);
10261
10276
  const auth0InstanceRef = React__default.useRef(null);
10262
10277
  React__default.useEffect(() => {
10263
- if (auth0Enabled && window.auth0 && auth0InstanceRef.current === null) {
10278
+ if (auth0Enabled && auth0Loaded && auth0InstanceRef.current === null) {
10264
10279
  auth0InstanceRef.current = new window.auth0.WebAuth({
10265
10280
  domain: window.Pelcro.site.read().auth0_base_url,
10266
10281
  clientID: window.Pelcro.site.read().auth0_client_id
10267
10282
  });
10268
10283
  }
10269
- }, [auth0Enabled, window.auth0]);
10284
+ }, [auth0Enabled, auth0Loaded]);
10270
10285
  const {
10271
10286
  dispatch: loginDispatch
10272
10287
  } = useContext(store$g);
@@ -10277,7 +10292,7 @@ const Auth0LoginButton = ({
10277
10292
  function handleClick() {
10278
10293
  var _auth0InstanceRef$cur, _auth0InstanceRef$cur2, _auth0InstanceRef$cur3;
10279
10294
 
10280
- if (!window.auth0) {
10295
+ if (!auth0Loaded) {
10281
10296
  return console.error("Auth0 sdk script wasn't loaded, you need to load auth0 sdk before rendering the Auth0LoginButton");
10282
10297
  }
10283
10298
 
@@ -19729,6 +19744,11 @@ const moveDefaultPaymentMethodToStart = paymentMethods => {
19729
19744
 
19730
19745
  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
19746
  const paymentMethodsWithoutDefault = paymentMethods.filter(paymentMethod => paymentMethod.id !== defaultPaymentMethod.id);
19747
+
19748
+ if (defaultPaymentMethod.status !== "chargeable") {
19749
+ return paymentMethodsWithoutDefault;
19750
+ }
19751
+
19732
19752
  return [defaultPaymentMethod, ...paymentMethodsWithoutDefault];
19733
19753
  };
19734
19754
 
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-beta.2",
5
5
  "license": "MIT",
6
6
  "private": false,
7
7
  "main": "dist/index.cjs.js",