@gudhub/ssg-web-components-library 1.0.107 → 1.0.109

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/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@gudhub/ssg-web-components-library",
3
- "version": "1.0.107",
3
+ "version": "1.0.109",
4
4
  "description": "",
5
5
  "main": "index.js",
6
6
  "type": "module",
@@ -8,7 +8,8 @@ let recaptchaPromise = null;
8
8
 
9
9
  function loadRecaptcha(siteKey) {
10
10
  if (!siteKey) {
11
- return Promise.reject(new Error('reCAPTCHA site key is missing'));
11
+ console.warn('reCAPTCHA site key is missing');
12
+ return Promise.resolve(null);
12
13
  }
13
14
 
14
15
  if (window.grecaptcha) return Promise.resolve(window.grecaptcha);
@@ -64,7 +65,9 @@ class GetInTouchForm extends GHComponent {
64
65
  this.initConfig(this.config);
65
66
  this.attachEventListeners();
66
67
 
67
- loadRecaptcha(this.recaptcha_site_key).catch(console.error);
68
+ if (this.recaptcha_site_key) {
69
+ loadRecaptcha(this.recaptcha_site_key).catch(console.error);
70
+ }
68
71
  }
69
72
  }
70
73
 
@@ -110,7 +113,8 @@ class GetInTouchForm extends GHComponent {
110
113
 
111
114
  async getRecaptchaToken(action = 'submit') {
112
115
  if (!this.recaptcha_site_key) {
113
- throw new Error('reCAPTCHA site key is missing');
116
+ console.warn('reCAPTCHA site key is missing');
117
+ return null;
114
118
  }
115
119
 
116
120
  const grecaptcha = await loadRecaptcha(this.recaptcha_site_key);
@@ -124,19 +128,22 @@ class GetInTouchForm extends GHComponent {
124
128
  });
125
129
  }
126
130
 
127
- async handleSubmit(event) {
128
- event.preventDefault();
129
- const form = event.target;
131
+ async handleSubmit(e) {
132
+ e.preventDefault();
130
133
 
134
+ const form = e.target;
131
135
  const validationResults = await this.inputsValidation(form);
132
136
 
133
137
  if (validationResults.every(({ isValid }) => isValid)) {
134
138
  this.addLoader();
135
139
 
136
140
  try {
137
- const token = await this.getRecaptchaToken();
141
+ let token = null;
138
142
 
139
- await this.verifyRecaptcha(token);
143
+ if (this.recaptcha_site_key) {
144
+ token = await this.getRecaptchaToken();
145
+ await this.verifyRecaptcha(token);
146
+ }
140
147
 
141
148
  this.handleSuccessFormValidation(form, token);
142
149
 
@@ -146,7 +153,6 @@ class GetInTouchForm extends GHComponent {
146
153
  }
147
154
 
148
155
  this.removeLoader();
149
-
150
156
  } else {
151
157
  validationResults
152
158
  .filter(item => typeof item === 'object')