@salesforcedevs/dw-components 1.3.148-canary.4 → 1.3.148-canary.6

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": "@salesforcedevs/dw-components",
3
- "version": "1.3.148-canary.4",
3
+ "version": "1.3.148-canary.6",
4
4
  "description": "Lightning web components for https://developer.salesforce.com",
5
5
  "license": "MIT",
6
6
  "engines": {
@@ -35,12 +35,14 @@
35
35
  <dw-j2s-form
36
36
  id={stepDatum.formData.formId}
37
37
  countries={countries}
38
- drm-recaptcha-site-key={drmRecaptchaSiteKey}
39
38
  form-metadata={stepDatum.formMetadata}
40
39
  incoming-user-info={formIncomingUserInfo}
41
40
  onformvaliditychange={handleFormValidityChange}
41
+ recaptcha-token={recaptchaToken}
42
42
  >
43
- <slot name="captcha-slot"></slot>
43
+ <div slot="form-captcha-slot">
44
+ <slot name="captcha-slot"></slot>
45
+ </div>
44
46
  </dw-j2s-form>
45
47
  </template>
46
48
  </template>
@@ -51,7 +51,6 @@ export default class J2sCardSequence extends LightningElement {
51
51
  _stepsData: StepDatum[] = [];
52
52
  @api animateTransitions = false;
53
53
  @api drmDomain: string = "https://drm.my.salesforce-sites.com";
54
- @api drmRecaptchaSiteKey: string = "";
55
54
  @api formHandler: string =
56
55
  "https://formhandlermule-1s9xrb.5sc6y6-4.usa-e2.cloudhub.io/form_handler";
57
56
  @api tbidApiBaseUrl: string | undefined;
@@ -91,6 +90,7 @@ export default class J2sCardSequence extends LightningElement {
91
90
 
92
91
  private countries = "[]";
93
92
  private currentSequenceStep = 0;
93
+ private recaptchaToken = "";
94
94
  private sessionStorageId = "j2s-card-sequence";
95
95
  private tbidUserInfo: any; // TODO typings?
96
96
 
@@ -158,6 +158,16 @@ export default class J2sCardSequence extends LightningElement {
158
158
  );
159
159
  }
160
160
 
161
+ @api
162
+ recaptchaCallback(responseToken: string) {
163
+ this.recaptchaToken = responseToken;
164
+ }
165
+
166
+ @api
167
+ recaptchaExpiredCallback() {
168
+ this.recaptchaToken = "";
169
+ }
170
+
161
171
  connectedCallback() {
162
172
  this.getCountryList();
163
173
  this.getTbidUserInfo();
@@ -44,3 +44,9 @@
44
44
  .form-terms-container {
45
45
  padding-top: var(--dx-g-spacing-sm);
46
46
  }
47
+
48
+ .form-captcha-slot {
49
+ align-items: center;
50
+ display: flex;
51
+ justify-content: center;
52
+ }
@@ -154,7 +154,7 @@
154
154
  class="legal-terms no-checkbox"
155
155
  ></span>
156
156
  </div>
157
- <slot name="captcha-slot"></slot>
157
+ <slot class="form-captcha-slot" name="form-captcha-slot"></slot>
158
158
  </div>
159
159
  </form>
160
160
  </template>
@@ -33,15 +33,13 @@ export type J2sFormState = {
33
33
  export default class J2sForm extends LightningElementWithState<J2sFormState> {
34
34
  private _countriesJson = "";
35
35
  private _countriesLookup: any = {}; // TODO typings
36
- private _didRenderRecaptcha = false;
37
36
  private _didSetFormId = false;
38
37
  private _formMetadata: any = {}; // TODO typings
39
38
  private _incomingUserInfo: any = {}; // TODO typings
40
39
  private _isInitialRender = true;
40
+ private _recaptchaToken = "";
41
41
 
42
- @api drmRecaptchaSiteKey = "";
43
42
  @api id = "";
44
- private recaptcha: any = null;
45
43
  @api referralText = "";
46
44
 
47
45
  @api
@@ -92,6 +90,15 @@ export default class J2sForm extends LightningElementWithState<J2sFormState> {
92
90
  return formData;
93
91
  }
94
92
 
93
+ @api
94
+ get recaptchaToken() {
95
+ return this._recaptchaToken;
96
+ }
97
+ set recaptchaToken(value: string) {
98
+ this._recaptchaToken = value;
99
+ this.handleRequiredFieldUpdate();
100
+ }
101
+
95
102
  private participatingCountryCodes = ["US", "CA", "IN"];
96
103
  private countriesWithReferralInput = ["IN"];
97
104
  private countriesWithRequiredJobRole = ["CA"];
@@ -138,12 +145,6 @@ export default class J2sForm extends LightningElementWithState<J2sFormState> {
138
145
  }
139
146
 
140
147
  this.state = initialState as J2sFormState;
141
-
142
- if ((window as any).grecaptcha) {
143
- this.setRecaptcha();
144
- } else {
145
- window.addEventListener("recaptchaloaded", this.setRecaptcha);
146
- }
147
148
  }
148
149
 
149
150
  renderedCallback(): void {
@@ -197,31 +198,8 @@ export default class J2sForm extends LightningElementWithState<J2sFormState> {
197
198
  this._didSetFormId = true;
198
199
  this.template.querySelector("form")?.setAttribute("id", this.id);
199
200
  }
200
-
201
- // if (!this._didRenderRecaptcha && this.recaptcha) {
202
- // this._didRenderRecaptcha = true;
203
- // this.recaptcha.render(this.template.querySelector(".captcha"), {
204
- // sitekey: this.drmRecaptchaSiteKey,
205
- // callback: (recaptchaToken: string) => {
206
- // console.log("got captcha", recaptchaToken);
207
- // },
208
- // "expired-callback": () => {},
209
- // "error-callback": (...args: any[]) => {
210
- // console.log("RECAPTCHA ERROR");
211
- // console.log(...args);
212
- // }
213
- // });
214
- // }
215
201
  }
216
202
 
217
- disconnectedCallback() {
218
- window.removeEventListener("recaptchaloaded", this.setRecaptcha);
219
- }
220
-
221
- setRecaptcha = () => {
222
- this.recaptcha = (window as any).grecaptcha;
223
- };
224
-
225
203
  handleRequiredFieldUpdate() {
226
204
  const isFormNowValid = this.checkValidity();
227
205
  if (this.state.isFormValid !== isFormNowValid) {
@@ -271,6 +249,7 @@ export default class J2sForm extends LightningElementWithState<J2sFormState> {
271
249
 
272
250
  private checkValidity() {
273
251
  return (
252
+ Boolean(this.recaptchaToken) &&
274
253
  this.isParticipatingCountry(this.state.country) &&
275
254
  this.requiredFormFields.every(
276
255
  (requiredFormField) =>