@salesforcedevs/dw-components 1.3.148-canary.1 → 1.3.148-canary.11

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.1",
3
+ "version": "1.3.148-canary.11",
4
4
  "description": "Lightning web components for https://developer.salesforce.com",
5
5
  "license": "MIT",
6
6
  "engines": {
@@ -38,7 +38,12 @@
38
38
  form-metadata={stepDatum.formMetadata}
39
39
  incoming-user-info={formIncomingUserInfo}
40
40
  onformvaliditychange={handleFormValidityChange}
41
- ></dw-j2s-form>
41
+ recaptcha-token={recaptchaToken}
42
+ >
43
+ <div slot="form-captcha-slot">
44
+ <slot name="captcha-slot"></slot>
45
+ </div>
46
+ </dw-j2s-form>
42
47
  </template>
43
48
  </template>
44
49
  </div>
@@ -1,14 +1,8 @@
1
1
  import { api, LightningElement } from "lwc";
2
2
  import StepSequence from "dx/stepSequence";
3
3
  import { getListWithUuids } from "dxUtils/list";
4
+ import { track } from "dxUtils/analytics";
4
5
  import { toJson } from "dxUtils/normalizers";
5
- import Button from "dx/button";
6
-
7
- function isNoAnimationCookieSet() {
8
- return document.cookie
9
- .split(";")
10
- .some((ck) => ck.trim() === "no_j2s_animation=true");
11
- }
12
6
 
13
7
  export type StepDatum = {
14
8
  bodyHtml?: string;
@@ -42,14 +36,23 @@ export type StepDatum = {
42
36
  stepTitle: string;
43
37
  };
44
38
 
39
+ function isNoAnimationCookieSet() {
40
+ return document.cookie
41
+ .split(";")
42
+ .some((ck) => ck.trim() === "no_j2s_animation=true");
43
+ }
44
+
45
45
  export default class J2sCardSequence extends LightningElement {
46
46
  _didRenderStaticInnerHtml = false;
47
47
  _isDrmLoading = false;
48
+ _isFormSubmitting = false;
48
49
  _isJ2sFormInvalid = false;
49
50
  _isTbidLoading = false;
50
51
  _stepsData: StepDatum[] = [];
51
52
  @api animateTransitions = false;
52
53
  @api drmDomain: string = "https://drm.my.salesforce-sites.com";
54
+ @api formHandler: string =
55
+ "https://formhandlermule-1s9xrb.5sc6y6-4.usa-e2.cloudhub.io/form_handler";
53
56
  @api tbidApiBaseUrl: string | undefined;
54
57
  @api useHistory: boolean = false;
55
58
 
@@ -87,11 +90,14 @@ export default class J2sCardSequence extends LightningElement {
87
90
 
88
91
  private countries = "[]";
89
92
  private currentSequenceStep = 0;
93
+ private recaptchaToken = "";
90
94
  private sessionStorageId = "j2s-card-sequence";
91
95
  private tbidUserInfo: any; // TODO typings?
92
96
 
93
97
  private get isLoading() {
94
- return this._isDrmLoading || this._isTbidLoading;
98
+ return (
99
+ this._isDrmLoading || this._isTbidLoading || this._isFormSubmitting
100
+ );
95
101
  }
96
102
 
97
103
  private get isLoggedIn() {
@@ -152,6 +158,16 @@ export default class J2sCardSequence extends LightningElement {
152
158
  );
153
159
  }
154
160
 
161
+ @api
162
+ recaptchaCallback(responseToken: string) {
163
+ this.recaptchaToken = responseToken;
164
+ }
165
+
166
+ @api
167
+ recaptchaExpiredCallback() {
168
+ this.recaptchaToken = "";
169
+ }
170
+
155
171
  connectedCallback() {
156
172
  this.getCountryList();
157
173
  this.getTbidUserInfo();
@@ -175,6 +191,15 @@ export default class J2sCardSequence extends LightningElement {
175
191
  }
176
192
  }
177
193
 
194
+ handleFormValidityChange({ detail }: CustomEvent) {
195
+ this.isJ2sFormInvalid = !detail.isValid;
196
+ }
197
+
198
+ handleStepSequenceChange({ detail }: CustomEvent) {
199
+ this.currentSequenceStep = detail.stepIndex;
200
+ this.resetCustomButtonColors();
201
+ }
202
+
178
203
  handleGetStarted(evt: Event) {
179
204
  // If the user is not yet logged in, we need to prevent moving immediately to the next
180
205
  // step, but set storage up so that they are on the second step when they return to the
@@ -188,25 +213,77 @@ export default class J2sCardSequence extends LightningElement {
188
213
  }
189
214
  }
190
215
 
191
- handleFormValidityChange({ detail }: CustomEvent) {
192
- this.isJ2sFormInvalid = !detail.isValid;
193
- }
216
+ async handleFormSubmit(evt: Event) {
217
+ if (!this.formHandler || this.isJ2sFormInvalid || !this.isLoggedIn) {
218
+ return;
219
+ }
194
220
 
195
- handleStepSequenceChange({ detail }: CustomEvent) {
196
- this.currentSequenceStep = detail.stepIndex;
197
- this.resetCustomButtonColors();
221
+ evt.preventDefault(); // don't proceed automatically to next step
222
+ this._isFormSubmitting = true;
223
+
224
+ try {
225
+ const formData = (this.template.querySelector("dw-j2s-form") as any)
226
+ ?.formDataForDrm;
227
+ // For some countries, explicit approvals will be present; for others, it is implicitly assumed
228
+ if (typeof formData.Opt_In__c !== "boolean") {
229
+ formData.Opt_In__c = true;
230
+ }
231
+ if (typeof formData.Privacy_Statement__c !== "boolean") {
232
+ formData.Privacy_Statement__c = true;
233
+ }
234
+
235
+ const res = await fetch(this.formHandler, {
236
+ method: "POST",
237
+ headers: {
238
+ "Captcha-Response": this.recaptchaToken
239
+ },
240
+ body: JSON.stringify({
241
+ ...formData,
242
+ handlerName: "J2S Registration Page",
243
+ TBID__c: this.tbidUserInfo.user_id
244
+ })
245
+ });
246
+
247
+ if (res.ok) {
248
+ const resData = await res.json();
249
+ const resOutput = resData.handlePostRequestOutput || resData;
250
+ if (resOutput?.status === "success") {
251
+ this.jumpToStepIndex(2);
252
+ } else {
253
+ throw new Error(
254
+ `Form submission failed. (status: ${resOutput.status}, message: ${resOutput.errorMessage})`
255
+ );
256
+ }
257
+ }
258
+ } catch (ex) {
259
+ console.error(ex); // TODO
260
+ }
261
+
262
+ this._isFormSubmitting = false;
198
263
  }
199
264
 
200
265
  primaryActionHandler(evt: Event) {
201
- if ((evt.target as Button)?.disabled) {
266
+ const target = evt.target as HTMLButtonElement;
267
+
268
+ if (!target || target.disabled) {
202
269
  evt.preventDefault();
203
270
  return;
204
271
  }
205
272
 
273
+ track(target, "custEv_ctaButtonClick", {
274
+ click_text: target.textContent,
275
+ element_title: this.stepsData[this.currentSequenceStep].stepTitle,
276
+ click_url:
277
+ this.stepsData[this.currentSequenceStep].primaryAction.link ||
278
+ "",
279
+ element_type: "button",
280
+ content_category: "cta"
281
+ });
282
+
206
283
  if (!this.currentSequenceStep) {
207
284
  this.handleGetStarted(evt);
208
- } else if (this.currentSequenceStep === 2) {
209
- // TODO: send data to DRM
285
+ } else if (this.currentSequenceStep === 1) {
286
+ this.handleFormSubmit(evt);
210
287
  }
211
288
  }
212
289
 
@@ -236,19 +313,18 @@ export default class J2sCardSequence extends LightningElement {
236
313
  );
237
314
  }
238
315
 
239
- private jumpToStepOne() {
240
- this.initialStepIndex = 0; // update sessionStorage value
241
- (
242
- this.template.querySelector(
243
- "dx-step-sequence"
244
- ) as unknown as StepSequence
245
- )?.jumpToStep(0);
316
+ private jumpToStepIndex(stepIndex: number) {
317
+ this.initialStepIndex = stepIndex; // update sessionStorage value
318
+ ((this.template.querySelector(
319
+ "dx-step-sequence"
320
+ ) as unknown) as StepSequence)?.jumpToStep(stepIndex);
246
321
  }
247
322
 
248
323
  // HTML is received via config from DSC and should be static after initial render.
249
324
  private updateStaticInnerHtml() {
250
- const bodyMarkupContainers =
251
- this.template.querySelectorAll("span.body-markup");
325
+ const bodyMarkupContainers = this.template.querySelectorAll(
326
+ "span.body-markup"
327
+ );
252
328
  const secondaryActionMarkupContainers = this.template.querySelectorAll(
253
329
  "span.secondary-action-markup"
254
330
  );
@@ -272,7 +348,7 @@ export default class J2sCardSequence extends LightningElement {
272
348
  private async getCountryList() {
273
349
  this._isDrmLoading = true;
274
350
 
275
- const errorMsg = "Error while getting county list";
351
+ const errorMsg = "Error while getting country list";
276
352
  try {
277
353
  const res = await fetch(
278
354
  `${this.drmDomain}/utilities/services/apexrest/countries`
@@ -287,7 +363,7 @@ export default class J2sCardSequence extends LightningElement {
287
363
  if (this.initialStepIndex > 0) {
288
364
  // Page loaded on a step higher than the first, but we can't get data for the form;
289
365
  // send user back to the start for now.
290
- this.jumpToStepOne();
366
+ this.jumpToStepIndex(0);
291
367
  }
292
368
  }
293
369
 
@@ -309,7 +385,7 @@ export default class J2sCardSequence extends LightningElement {
309
385
  if (!this.tbidUserInfo && this.initialStepIndex > 0) {
310
386
  // login failed and the user was previously beyond the start step; need to send them
311
387
  // back to the start:
312
- this.jumpToStepOne();
388
+ this.jumpToStepIndex(0);
313
389
  }
314
390
 
315
391
  this._isTbidLoading = false;
@@ -1,46 +1,61 @@
1
- export const stepsData = [
2
- {
3
- showStepNumber: "true",
4
- stepTitle: "Get started now.",
5
- bodyHtml:
6
- '<p class="dx-text-display-7">Register for Journey to Salesforce and you\'ll be on your way to becoming a Salesforce Developer.</p><ul class="dx-text-display-8"><li>Step 1: Log in or sign up for a free Trailblazer.me account</li><li>Step 2: Confirm your program registration</li><li>Step 3: Begin your journey!</li></ul>',
7
- primaryActionText: "Get Started"
8
- },
9
- {
10
- showStepNumber: "true",
11
- stepTitle: "Complete your registration.",
12
- formData: {
13
- countriesWithReferralInput: ["IN"],
14
- countriewWithRequiredJobRole: ["CA"],
15
- notAvailableAlertInfo: {
16
- title: "Not Available",
17
- body: 'The Journey to Salesforce program is not currently available in your country. See the <a href="https://www.google.com/">program FAQs</a> for a list of participating countries.'
1
+ export const stepSequenceData = {
2
+ animateTransitions: "true",
3
+ stepsData: [
4
+ {
5
+ bodyHtml:
6
+ '<p class="dx-text-display-7">Register for Journey to Salesforce and you\'ll be on your way to becoming a Salesforce Developer.</p><ul class="dx-text-display-8"><li>Step 1: Log in or sign up for a free Trailblazer.me account</li><li>Step 2: Confirm your program registration</li><li>Step 3: Begin your journey!</li></ul>',
7
+ primaryAction: {
8
+ text: "Get Started"
18
9
  },
19
- participatingCountryCodes: ["US", "CA", "IN"]
10
+ showStepNumber: "true",
11
+ stepTitle: "Get started now."
20
12
  },
21
- bodyHtml:
22
- '<p class="dx-text-display-7">You\'re almost done! Please review your information and agree to the Journey to Salesforce program terms and conditions.</p>',
23
- secondaryActionHtml:
24
- '<span class="required-notice">* Required to participate in Journey to Salesforce</span>',
25
- primaryActionText: "Complete Registration"
26
- },
27
- {
28
- showStepNumber: "true",
29
- stepTitle: "Your Registration is Confirmed",
30
- headerData: {
31
- iconSymbol: "check-circle",
32
- iconSprite: "general",
33
- iconColor: "green-vibrant-65",
34
- backgroundColor: "green-vibrant-95",
35
- textColor: "indigo-vibrant-20"
13
+ {
14
+ bodyHtml:
15
+ '<p class="dx-text-display-7">You\'re almost done! Please review your information and agree to the Journey to Salesforce program terms and conditions.</p>',
16
+ formData: {
17
+ countriesWithReferralInput: ["IN"],
18
+ countriesWithRequiredJobRole: ["CA"],
19
+ formId: "j2s-form",
20
+ j2sTerms:
21
+ 'I agree to the Journey to Salesforce Program Terms, subject to the <a href="http://www.google.com">Salesforce Program Agreement</a>.',
22
+ notAvailableAlertInfo: {
23
+ title: "Not Available",
24
+ body:
25
+ 'The Journey to Salesforce program is not currently available in your country. See the <a href="https://www.google.com/">program FAQs</a> for a list of participating countries.'
26
+ },
27
+ participatingCountryCodes: ["US", "CA", "IN"]
28
+ },
29
+ primaryAction: {
30
+ text: "Complete Registration"
31
+ },
32
+ secondaryActionHtml:
33
+ '<span class="required-notice">* Required to participate in Journey to Salesforce</span>',
34
+ showStepNumber: "true",
35
+ stepTitle: "Complete your registration."
36
36
  },
37
- bodyHtml:
38
- '<div class="dx-text-display-8"><p>Welcome to Journey to Salesforce! Congratulations on taking this step in your journey towards becoming a Salesforce Developer. Through this program you\'ll gain the knowledge, experience, and skills to help you excel in the Salesforce ecosystem.</p><p>To get started, click the button below to join the Journey to Salesforce community, and make sure to check your email for links to bookmark!</p>',
39
- secondaryActionHtml:
40
- '<span class="dx-text-display-7">Ready to jump in?</span>',
41
- primaryActionText: "Join Slack",
42
- primaryActionVariant: "custom",
43
- primaryActionIconSprite: "utility",
44
- primaryActionIconSymbol: "new_window"
45
- }
46
- ];
37
+ {
38
+ bodyHtml:
39
+ '<div class="dx-text-display-8"><p>Welcome to Journey to Salesforce! Congratulations on taking this step in your journey towards becoming a Salesforce Developer. Through this program you\'ll gain the knowledge, experience, and skills to help you excel in the Salesforce ecosystem.</p><p>To get started, click the button below to join the Journey to Salesforce community, and make sure to check your email for links to bookmark!</p></div>',
40
+ headerData: {
41
+ backgroundColor: "green-vibrant-95",
42
+ iconSymbol: "check-circle",
43
+ iconSprite: "general",
44
+ iconColor: "green-vibrant-65",
45
+ textColor: "indigo-vibrant-20"
46
+ },
47
+ primaryAction: {
48
+ iconSprite: "utility",
49
+ iconSymbol: "new_window",
50
+ link:
51
+ "https://salesforce-external.slack.com/archives/C05HJK4PGJV",
52
+ text: "Join Slack",
53
+ variant: "custom"
54
+ },
55
+ secondaryActionHtml:
56
+ '<span class="dx-text-display-7">Ready to jump in?</span>',
57
+ showStepNumber: "true",
58
+ stepTitle: "Your Registration is Confirmed"
59
+ }
60
+ ]
61
+ };
@@ -21,8 +21,8 @@
21
21
  }
22
22
 
23
23
  .form-row .terms {
24
- --dx-c-checkbox-text-line-height: 20px;
25
- --dx-c-checkbox-font-size: 14px;
24
+ --dx-c-checkbox-text-line-height: var(--dx-g-text-lg);
25
+ --dx-c-checkbox-font-size: var(--dx-g-text-sm);
26
26
 
27
27
  font-family: var(--dx-g-font-sans);
28
28
  font-size: var(--dx-c-checkbox-font-size);
@@ -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
+ }
@@ -1,11 +1,12 @@
1
1
  <template>
2
+ <!-- For the names of the form fields, see: https://salesforce.quip.com/daInAFETbPGm -->
2
3
  <form class="j2s-form">
3
4
  <div class="form-row">
4
5
  <dx-input
5
6
  class="first-name-field"
6
7
  label="First Name"
7
8
  missing-error-message="Enter your first name"
8
- name="first_name"
9
+ name="FirstName"
9
10
  placeholder="Your first name"
10
11
  required
11
12
  validity-on-blur
@@ -16,7 +17,7 @@
16
17
  class="last-name-field"
17
18
  label="Last Name"
18
19
  missing-error-message="Enter your last name"
19
- name="last_name"
20
+ name="LastName"
20
21
  placeholder="Your last name"
21
22
  required
22
23
  validity-on-blur
@@ -29,7 +30,7 @@
29
30
  class="company-name-field"
30
31
  label="Company Name"
31
32
  missing-error-message="Enter your company name"
32
- name="company_name"
33
+ name="Company__c"
33
34
  placeholder="Your company name"
34
35
  required
35
36
  validity-on-blur
@@ -41,7 +42,7 @@
41
42
  class="job-role-field"
42
43
  label="Job Role"
43
44
  message-when-value-missing="Select your job role"
44
- name="job_role"
45
+ name="DRM_Role__c"
45
46
  options={jobRoles}
46
47
  placeholder="Select Job Role"
47
48
  value={state.jobRole}
@@ -51,7 +52,7 @@
51
52
  class="job-role-field"
52
53
  label="Job Role"
53
54
  message-when-value-missing="Select your job role"
54
- name="job_role"
55
+ name="DRM_Role__c"
55
56
  options={jobRoles}
56
57
  placeholder="Select Job Role"
57
58
  required
@@ -61,7 +62,7 @@
61
62
  </div>
62
63
  <div class="form-row">
63
64
  <dx-input
64
- name="email"
65
+ name="Email"
65
66
  type="email"
66
67
  placeholder="Your email address"
67
68
  label="Email"
@@ -74,7 +75,7 @@
74
75
  <dx-select
75
76
  label="Country/Region"
76
77
  message-when-value-missing="Select your country/region"
77
- name="country"
78
+ name="MailingCountry"
78
79
  options={countries}
79
80
  placeholder="Select Country/Region"
80
81
  required
@@ -84,7 +85,7 @@
84
85
  </div>
85
86
  <div class="form-row" if:true={isCountryWithReferralInput}>
86
87
  <dx-input
87
- name="referral_email"
88
+ name="Referral_Email__c"
88
89
  class="referral-email-field full-width"
89
90
  label="If anyone has referred you, please share their Email ID below, with their consent."
90
91
  type="email"
@@ -102,7 +103,7 @@
102
103
  <div class="form-row" if:true={state.showMarketingText}>
103
104
  <dx-checkbox
104
105
  value="marketing-terms"
105
- name="marketing_terms"
106
+ name="Opt_In__c"
106
107
  required
107
108
  class="terms"
108
109
  onchange={handleRequiredFieldUpdate}
@@ -127,7 +128,7 @@
127
128
  <dx-checkbox
128
129
  if:true={state.showLegalCheckbox}
129
130
  value="legal-terms"
130
- name="legal_terms"
131
+ name="Privacy_Statement__c"
131
132
  required
132
133
  class="terms"
133
134
  onchange={handleRequiredFieldUpdate}
@@ -153,6 +154,7 @@
153
154
  class="legal-terms no-checkbox"
154
155
  ></span>
155
156
  </div>
157
+ <slot class="form-captcha-slot" name="form-captcha-slot"></slot>
156
158
  </div>
157
159
  </form>
158
160
  </template>
@@ -31,12 +31,14 @@ export type J2sFormState = {
31
31
  };
32
32
 
33
33
  export default class J2sForm extends LightningElementWithState<J2sFormState> {
34
- private _didSetFormId = false;
35
- private _isInitialRender = true;
36
- private _incomingUserInfo: any = {}; // TODO typings
37
- private _formMetadata: any = {}; // TODO typings
38
34
  private _countriesJson = "";
39
35
  private _countriesLookup: any = {}; // TODO typings
36
+ private _didSetFormId = false;
37
+ private _formMetadata: any = {}; // TODO typings
38
+ private _incomingUserInfo: any = {}; // TODO typings
39
+ private _isInitialRender = true;
40
+ private _recaptchaToken = "";
41
+
40
42
  @api id = "";
41
43
  @api referralText = "";
42
44
 
@@ -72,6 +74,33 @@ export default class J2sForm extends LightningElementWithState<J2sFormState> {
72
74
  this._formMetadata = toJson(value);
73
75
  }
74
76
 
77
+ @api
78
+ get formDataForDrm() {
79
+ // We should be able to just get the formData from the form automatically using `new FormData(theForm)`,
80
+ // but our custom form elements don't seem to implement what it is required for that currently. See:
81
+ // https://web.dev/more-capable-form-controls/#defining-a-form-associated-custom-element
82
+ const formData: any = {};
83
+ this.template
84
+ .querySelectorAll("form [name]")
85
+ .forEach((namedElement) => {
86
+ const typedElement = namedElement as HTMLInputElement;
87
+ formData[typedElement.name] =
88
+ typeof typedElement.checked === "boolean"
89
+ ? typedElement.checked
90
+ : typedElement.value;
91
+ });
92
+ return formData;
93
+ }
94
+
95
+ @api
96
+ get recaptchaToken() {
97
+ return this._recaptchaToken;
98
+ }
99
+ set recaptchaToken(value: string) {
100
+ this._recaptchaToken = value;
101
+ this.handleRequiredFieldUpdate();
102
+ }
103
+
75
104
  private participatingCountryCodes = ["US", "CA", "IN"];
76
105
  private countriesWithReferralInput = ["IN"];
77
106
  private countriesWithRequiredJobRole = ["CA"];
@@ -173,17 +202,6 @@ export default class J2sForm extends LightningElementWithState<J2sFormState> {
173
202
  }
174
203
  }
175
204
 
176
- private updateInnerHtml(selector: string, html: string): void {
177
- const element = this.template.querySelector(selector);
178
- if (element) {
179
- element.innerHTML = html;
180
- }
181
- }
182
-
183
- private isParticipatingCountry(country: string) {
184
- return this.participatingCountryCodes.includes(country);
185
- }
186
-
187
205
  handleRequiredFieldUpdate() {
188
206
  const isFormNowValid = this.checkValidity();
189
207
  if (this.state.isFormValid !== isFormNowValid) {
@@ -220,8 +238,20 @@ export default class J2sForm extends LightningElementWithState<J2sFormState> {
220
238
  ?.classList.toggle("hidden");
221
239
  }
222
240
 
241
+ private updateInnerHtml(selector: string, html: string): void {
242
+ const element = this.template.querySelector(selector);
243
+ if (element) {
244
+ element.innerHTML = html;
245
+ }
246
+ }
247
+
248
+ private isParticipatingCountry(country: string) {
249
+ return this.participatingCountryCodes.includes(country);
250
+ }
251
+
223
252
  private checkValidity() {
224
253
  return (
254
+ Boolean(this.recaptchaToken) &&
225
255
  this.isParticipatingCountry(this.state.country) &&
226
256
  this.requiredFormFields.every(
227
257
  (requiredFormField) =>