@salesforcedevs/dw-components 1.3.148-canary.13 → 1.3.148-canary.14

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.13",
3
+ "version": "1.3.148-canary.14",
4
4
  "description": "Lightning web components for https://developer.salesforce.com",
5
5
  "license": "MIT",
6
6
  "engines": {
@@ -36,18 +36,13 @@ export type StepDatum = {
36
36
  stepTitle: string;
37
37
  };
38
38
 
39
- function isNoAnimationCookieSet() {
40
- return document.cookie
41
- .split(";")
42
- .some((ck) => ck.trim() === "no_j2s_animation=true");
43
- }
44
-
45
39
  export default class J2sCardSequence extends LightningElement {
46
40
  _didRenderStaticInnerHtml = false;
47
41
  _isDrmLoading = false;
48
42
  _isFormSubmitting = false;
49
43
  _isJ2sFormInvalid = false;
50
44
  _isTbidLoading = false;
45
+ _recaptchaResetTimeoutId: number | null = null;
51
46
  _stepsData: StepDatum[] = [];
52
47
  @api animateTransitions = false;
53
48
  @api drmDomain: string = "https://drm.my.salesforce-sites.com";
@@ -161,11 +156,13 @@ export default class J2sCardSequence extends LightningElement {
161
156
  @api
162
157
  recaptchaCallback(responseToken: string) {
163
158
  this.recaptchaToken = responseToken;
159
+ clearTimeout(this._recaptchaResetTimeoutId as number);
164
160
  }
165
161
 
166
162
  @api
167
163
  recaptchaExpiredCallback() {
168
164
  this.recaptchaToken = "";
165
+ clearTimeout(this._recaptchaResetTimeoutId as number);
169
166
  }
170
167
 
171
168
  connectedCallback() {
@@ -174,10 +171,6 @@ export default class J2sCardSequence extends LightningElement {
174
171
  // This has to be defined here since it depends on a variable that depends on sessionStorage.
175
172
  this.currentSequenceStep = this.initialStepIndex;
176
173
  this.resetCustomButtonColors();
177
- if (isNoAnimationCookieSet()) {
178
- /* eslint-disable-next-line @lwc/lwc/no-api-reassignments */
179
- this.animateTransitions = false;
180
- }
181
174
  }
182
175
 
183
176
  renderedCallback() {
@@ -199,6 +192,21 @@ export default class J2sCardSequence extends LightningElement {
199
192
  handleStepSequenceChange({ detail }: CustomEvent) {
200
193
  this.currentSequenceStep = detail.stepIndex;
201
194
  this.resetCustomButtonColors();
195
+
196
+ if (
197
+ this.currentSequenceStep !== 1 &&
198
+ this.recaptchaToken &&
199
+ this._recaptchaResetTimeoutId === null
200
+ ) {
201
+ // If the recaptcha element expires on its own while you are not on the 2nd (form) step, it messes with the
202
+ // page's layout (basically breaks it). So, we need to reset it _before_ expiration if you leave that step.
203
+ // We do it with a timeout so that the token is not immediately wiped if the user goes back and forth a bit.
204
+ this._recaptchaResetTimeoutId = window.setTimeout(() => {
205
+ this._recaptchaResetTimeoutId = null;
206
+ this.recaptchaToken = "";
207
+ (window as any).grecaptcha.reset();
208
+ }, 1000 * 30 /* 30 seconds */);
209
+ }
202
210
  }
203
211
 
204
212
  handleGetStarted(evt: Event) {
@@ -209,8 +217,7 @@ export default class J2sCardSequence extends LightningElement {
209
217
  evt.preventDefault();
210
218
  this.initialStepIndex = 1;
211
219
  this._isTbidLoading = true;
212
- // @ts-ignore: call out to the tbid-controller on DSC
213
- window.__startTbidLogin();
220
+ (window as any).__startTbidLogin?.(); // call out to DSC tbid controller
214
221
  }
215
222
  }
216
223
 
@@ -249,7 +256,8 @@ export default class J2sCardSequence extends LightningElement {
249
256
  const resData = await res.json();
250
257
  const resOutput = resData.handlePostRequestOutput || resData;
251
258
  if (resOutput?.status === "success") {
252
- this.jumpToStepIndex(2);
259
+ this.jumpToStepIndex(2, false);
260
+ this.initialStepIndex = 0; // don't save final step in storage; rather, reset the starting step
253
261
  } else {
254
262
  throw new Error(
255
263
  `Form submission failed. (status: ${resOutput.status}, message: ${resOutput.errorMessage})`
@@ -314,8 +322,10 @@ export default class J2sCardSequence extends LightningElement {
314
322
  );
315
323
  }
316
324
 
317
- private jumpToStepIndex(stepIndex: number) {
318
- this.initialStepIndex = stepIndex; // update sessionStorage value
325
+ private jumpToStepIndex(stepIndex: number, andStoreIndex = true) {
326
+ if (andStoreIndex) {
327
+ this.initialStepIndex = stepIndex; // update sessionStorage value
328
+ }
319
329
  ((this.template.querySelector(
320
330
  "dx-step-sequence"
321
331
  ) as unknown) as StepSequence)?.jumpToStep(stepIndex);