@salesforcedevs/dw-components 0.79.1 → 1.0.0

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.
Files changed (76) hide show
  1. package/lwc.config.json +10 -1
  2. package/package.json +16 -12
  3. package/src/modules/dw/blogsGrid/blogsGrid.css +14 -7
  4. package/src/modules/dw/blogsGrid/blogsGrid.html +15 -12
  5. package/src/modules/dw/blogsGrid/blogsGrid.ts +23 -9
  6. package/src/modules/dw/browseTrials/browseTrials.css +35 -0
  7. package/src/modules/dw/browseTrials/browseTrials.html +86 -0
  8. package/src/modules/dw/browseTrials/browseTrials.ts +116 -0
  9. package/src/modules/dw/cardBlogPostProvider/cardBlogPostProvider.css +2 -0
  10. package/src/modules/dw/cardBlogPostProvider/cardBlogPostProvider.html +3 -3
  11. package/src/modules/dw/cardPodcastEpisodeProvider/cardPodcastEpisodeProvider.css +2 -0
  12. package/src/modules/dw/cardPodcastEpisodeProvider/cardPodcastEpisodeProvider.html +2 -1
  13. package/src/modules/dw/codeSamplesGrid/codeSamplesGrid.css +85 -9
  14. package/src/modules/dw/codeSamplesGrid/codeSamplesGrid.html +74 -112
  15. package/src/modules/dw/codeSamplesGrid/codeSamplesGrid.ts +14 -376
  16. package/src/modules/dw/contentArchive/contentArchive.css +5 -4
  17. package/src/modules/dw/contentArchive/contentArchive.html +58 -24
  18. package/src/modules/dw/contentArchive/contentArchive.ts +46 -8
  19. package/src/modules/dw/contentArchive/contentArchive.types.ts +8 -4
  20. package/src/modules/dw/contentArchive/utils.ts +30 -14
  21. package/src/modules/dw/deSignupForm/deSignupForm.css +11 -10
  22. package/src/modules/dw/deSignupForm/deSignupForm.html +39 -25
  23. package/src/modules/dw/deSignupForm/deSignupForm.ts +205 -133
  24. package/src/modules/dw/deSignupForm/submitForm.ts +7 -3
  25. package/src/modules/dw/docsGrid/docsGrid.css +0 -1
  26. package/src/modules/dw/docsGrid/docsGrid.html +6 -2
  27. package/src/modules/dw/docsGrid/docsGrid.ts +103 -38
  28. package/src/modules/dw/eventsList/eventsList.css +4 -4
  29. package/src/modules/dw/eventsList/eventsList.html +5 -5
  30. package/src/modules/dw/eventsList/eventsList.ts +47 -48
  31. package/src/modules/dw/j2sCardSequence/j2sCardSequence.css +14 -0
  32. package/src/modules/dw/j2sCardSequence/j2sCardSequence.html +41 -0
  33. package/src/modules/dw/j2sCardSequence/j2sCardSequence.ts +487 -0
  34. package/src/modules/dw/j2sCardSequenceStep/j2sCardSequenceStep.css +76 -0
  35. package/src/modules/dw/j2sCardSequenceStep/j2sCardSequenceStep.html +64 -0
  36. package/src/modules/dw/j2sCardSequenceStep/j2sCardSequenceStep.ts +157 -0
  37. package/src/modules/dw/j2sForm/j2sForm.css +65 -0
  38. package/src/modules/dw/j2sForm/j2sForm.html +217 -0
  39. package/src/modules/dw/j2sForm/j2sForm.ts +371 -0
  40. package/src/modules/dw/j2sForm/mockProps.ts +3102 -0
  41. package/src/modules/dw/languageSelector/languageSelector.css +86 -0
  42. package/src/modules/dw/languageSelector/languageSelector.html +36 -0
  43. package/src/modules/dw/languageSelector/languageSelector.ts +119 -0
  44. package/src/modules/dw/newsletterForm/newsletterForm.css +2 -2
  45. package/src/modules/dw/newsletterForm/newsletterForm.html +35 -10
  46. package/src/modules/dw/newsletterForm/newsletterForm.ts +107 -78
  47. package/src/modules/dw/podcastSubscription/podcastSubscription.css +8 -8
  48. package/src/modules/dw/podcastSubscription/podcastSubscription.html +2 -2
  49. package/src/modules/dw/podcastSubscription/podcastSubscription.ts +4 -4
  50. package/src/modules/dw/podcastsGrid/podcastsGrid.css +7 -0
  51. package/src/modules/dw/podcastsGrid/podcastsGrid.html +6 -1
  52. package/src/modules/dw/podcastsGrid/podcastsGrid.ts +3 -3
  53. package/src/modules/dw/podcastsPromo/podcastsPromo.css +14 -0
  54. package/src/modules/dw/podcastsPromo/podcastsPromo.html +16 -8
  55. package/src/modules/dw/podcastsPromo/podcastsPromo.ts +11 -2
  56. package/src/modules/dw/rcgTable/altData.ts +72 -9
  57. package/src/modules/dw/rcgTable/getTableData.ts +1 -1
  58. package/src/modules/dw/rcgTable/rcgTable.ts +3 -3
  59. package/src/modules/dw/slackCta/slackCta.css +5 -6
  60. package/src/modules/dw/slackCta/slackCta.html +1 -1
  61. package/src/modules/dw/slackSuccess/slackSuccess.css +1 -1
  62. package/src/modules/dw/slackSuccess/slackSuccess.html +2 -2
  63. package/src/modules/dw/tbidLoginMenu/tbidLoginMenu.css +119 -0
  64. package/src/modules/dw/tbidLoginMenu/tbidLoginMenu.html +192 -0
  65. package/src/modules/dw/tbidLoginMenu/tbidLoginMenu.ts +148 -0
  66. package/src/modules/dw/videoGrid/types.ts +12 -0
  67. package/src/modules/dw/videoGrid/videoGrid.css +24 -0
  68. package/src/modules/dw/videoGrid/videoGrid.html +41 -0
  69. package/src/modules/dw/videoGrid/videoGrid.ts +41 -0
  70. package/src/modules/dw/youtubeVideoGrid/types.ts +8 -0
  71. package/src/modules/dw/youtubeVideoGrid/youtubeVideoGrid.css +18 -0
  72. package/src/modules/dw/youtubeVideoGrid/youtubeVideoGrid.html +40 -0
  73. package/src/modules/dw/youtubeVideoGrid/youtubeVideoGrid.ts +66 -0
  74. package/src/modules/dwHelpers/mobileDividers/mobileDividers.css +19 -0
  75. package/src/modules/dwUtils/forms/forms.ts +514 -0
  76. package/src/modules/{dwBaseElements → dwUtils}/postsGrid/postsGrid.ts +10 -13
@@ -0,0 +1,371 @@
1
+ import { toJson } from "dxUtils/normalizers";
2
+ import { stateMap } from "dwUtils/forms";
3
+ import { DateTime } from "luxon";
4
+ import { api } from "lwc";
5
+ import debounce from "debounce";
6
+ import { LightningElementWithState } from "dxBaseElements/lightningElementWithState";
7
+ import { DrmFormData } from "dw/j2sCardSequence";
8
+
9
+ const closingTimeUSCanada = DateTime.fromISO("2024-05-09", {
10
+ zone: "America/Los_Angeles"
11
+ });
12
+
13
+ // Hard-coding for now because we can't get information about an endpoint for this
14
+ const tbidValidRoles = [
15
+ "Developer",
16
+ "Administrator",
17
+ "Architect",
18
+ "Sales Representative / Manager",
19
+ "Marketer",
20
+ "Service Agent / Supervisor",
21
+ "Data Analyst",
22
+ "Consultant",
23
+ "Business Operations Manager",
24
+ "Designer",
25
+ "Educator",
26
+ "Student",
27
+ "Executive",
28
+ "Product Manager"
29
+ ];
30
+
31
+ export type J2sFormState = DrmFormData & {
32
+ legalText: string;
33
+ marketingText: string;
34
+ learnMore: string;
35
+ showLegalCheckbox: boolean;
36
+ showMarketingText: boolean;
37
+ isFormValid: boolean;
38
+ };
39
+
40
+ const debounceCallback = (callback: Function) =>
41
+ debounce(callback, 1000 / 15 /* 15fps roughly */);
42
+
43
+ export default class J2sForm extends LightningElementWithState<J2sFormState> {
44
+ private _countriesJson = "";
45
+ private _countriesLookup: any = {}; // TODO typings
46
+ private _didSetFormId = false;
47
+ private _isInitialRender = true;
48
+ private _recaptchaToken = "";
49
+
50
+ @api hasAlreadyRegistered = false;
51
+ @api formMetadata: any = {};
52
+ @api id = "";
53
+ @api incomingUserInfo = {} as DrmFormData;
54
+ @api referralText = "";
55
+
56
+ @api
57
+ get countries() {
58
+ return this._countriesJson || "[]";
59
+ }
60
+ set countries(value: string) {
61
+ this._countriesJson = value;
62
+
63
+ // Store a lookup table of country data by value so that we don't have to loop all the time
64
+ const countries = toJson(value);
65
+ const countriesLookup: any = {};
66
+ countries.forEach((country: any) => {
67
+ countriesLookup[country.value] = country;
68
+ });
69
+ this._countriesLookup = countriesLookup;
70
+ }
71
+
72
+ @api
73
+ get formDataForDrm(): Partial<DrmFormData> {
74
+ // We should be able to just get the formData from the form automatically using `new FormData(theForm)`,
75
+ // but our custom form elements don't seem to implement what it is required for that currently. See:
76
+ // https://web.dev/more-capable-form-controls/#defining-a-form-associated-custom-element
77
+ const formData: any = {};
78
+ this.template
79
+ .querySelectorAll("form [name]")
80
+ .forEach((namedElement) => {
81
+ const typedElement = namedElement as HTMLInputElement;
82
+ formData[typedElement.name] =
83
+ typeof typedElement.checked === "boolean"
84
+ ? typedElement.checked
85
+ : typedElement.value;
86
+ });
87
+ return formData;
88
+ }
89
+
90
+ @api
91
+ get recaptchaToken() {
92
+ return this._recaptchaToken;
93
+ }
94
+ set recaptchaToken(value: string) {
95
+ this._recaptchaToken = value;
96
+ if (!this._isInitialRender) {
97
+ // Treat recaptcha checkbox as a required form field even though not technically marked as such:
98
+ this.setState({
99
+ isFormValid: this.checkValidity()
100
+ });
101
+ }
102
+ }
103
+
104
+ private countriesWithReferralInput = ["IN"];
105
+ private requiredFormFields: HTMLElement[] = [];
106
+ private showSubmitFailureAlert = false;
107
+
108
+ get participatingCountryCodes() {
109
+ if (DateTime.local() >= closingTimeUSCanada) {
110
+ return ["IN"];
111
+ }
112
+ return ["US", "CA", "IN"];
113
+ }
114
+
115
+ get isNotParticipatingCountry() {
116
+ return !this.isParticipatingCountry(this.state.MailingCountry);
117
+ }
118
+
119
+ get disableCheckboxes() {
120
+ return this.isSalesforceEmployee || this.isNotParticipatingCountry;
121
+ }
122
+
123
+ get isCountryWithReferralInput() {
124
+ return this.countriesWithReferralInput.includes(
125
+ this.state.MailingCountry
126
+ );
127
+ }
128
+
129
+ get isSalesforceEmployee() {
130
+ return this.state.RelationshipToSalesforce === "Salesforce Employee";
131
+ }
132
+
133
+ get alreadyRegisteredAlertInfo() {
134
+ return this.formMetadata.alreadyRegisteredAlertInfo;
135
+ }
136
+
137
+ get notAvailableAlertInfo() {
138
+ return this.formMetadata.notAvailableAlertInfo[
139
+ this.state.MailingCountry || "default"
140
+ ];
141
+ }
142
+
143
+ get salesforceEmployeeAlertInfo() {
144
+ return this.formMetadata.salesforceEmployeeAlertInfo;
145
+ }
146
+
147
+ get formSubmitFailureAlertInfo() {
148
+ return this.formMetadata.formSubmitFailureAlertInfo;
149
+ }
150
+
151
+ get jobRoles() {
152
+ return tbidValidRoles.map((role) => ({
153
+ label: role,
154
+ value: role
155
+ }));
156
+ }
157
+
158
+ get showStateProvince(): boolean {
159
+ return this.state.MailingCountry in stateMap;
160
+ }
161
+
162
+ get states(): { id: string; label: string; value: string }[] {
163
+ return (
164
+ stateMap[this.state.MailingCountry as keyof typeof stateMap] || []
165
+ );
166
+ }
167
+
168
+ connectedCallback() {
169
+ const initialState: Partial<J2sFormState> = {
170
+ ...this.incomingUserInfo,
171
+ isFormValid: false,
172
+ showMarketingText: true
173
+ };
174
+ const initialCountry = initialState.MailingCountry;
175
+ const initialCountryData =
176
+ initialCountry && this._countriesLookup[initialCountry];
177
+ if (initialCountryData) {
178
+ initialState.showLegalCheckbox =
179
+ initialCountryData.showLegalCheckbox;
180
+ initialState.showMarketingText =
181
+ initialCountryData.showMarketingText;
182
+ initialState.legalText = initialCountryData.legalText;
183
+ initialState.marketingText = initialCountryData.marketingText;
184
+ initialState.learnMore = initialCountryData.learnMore;
185
+ }
186
+
187
+ this.state = initialState as J2sFormState;
188
+ }
189
+
190
+ renderedCallback(): void {
191
+ if (this._isInitialRender) {
192
+ this.updateInnerHtml("span.j2s-terms", this.formMetadata.j2sTerms);
193
+ this._isInitialRender = false;
194
+ }
195
+
196
+ if (
197
+ this.state.MailingCountry &&
198
+ this.state.MailingCountry !== this.prevState.MailingCountry
199
+ ) {
200
+ // Re-render new country's terms
201
+ this.updateInnerHtml(
202
+ "span.marketing-terms",
203
+ this.state.marketingText
204
+ );
205
+ this.updateInnerHtml("span.legal-terms", this.state.legalText);
206
+ if (this.state.learnMore) {
207
+ this.updateInnerHtml(
208
+ "span.legal-terms-learn-more",
209
+ this.state.learnMore
210
+ );
211
+ } else {
212
+ this.updateInnerHtml("span.legal-terms-learn-more", "");
213
+ this.template
214
+ .querySelector(".legal-terms-learn-more")
215
+ ?.classList.add("hidden");
216
+ }
217
+ }
218
+
219
+ if (this.state.isFormValid !== this.prevState.isFormValid) {
220
+ this.dispatchEvent(
221
+ new CustomEvent("formvaliditychange", {
222
+ detail: {
223
+ isValid: this.state.isFormValid
224
+ },
225
+ bubbles: true,
226
+ composed: true
227
+ })
228
+ );
229
+ }
230
+
231
+ this.requiredFormFields = Array.from(
232
+ this.template.querySelectorAll("[required]")
233
+ );
234
+
235
+ if (this.id && !this._didSetFormId) {
236
+ this._didSetFormId = true;
237
+ this.template.querySelector("form")?.setAttribute("id", this.id);
238
+ }
239
+ }
240
+
241
+ handleLearnMore() {
242
+ this.template
243
+ .querySelector(".legal-terms-learn-more")
244
+ ?.classList.toggle("hidden");
245
+ }
246
+
247
+ debouncedFormFieldChangeHandler = debounceCallback(
248
+ (targetName: string, value: any, isRequiredField = false) => {
249
+ if (targetName === "MailingCountry") {
250
+ this.handleCountryChange(value);
251
+ } else {
252
+ const nextState: Partial<J2sFormState> = {};
253
+ if (targetName) {
254
+ nextState[targetName as keyof J2sFormState] = value;
255
+ }
256
+ if (isRequiredField) {
257
+ nextState.isFormValid = this.checkValidity();
258
+ }
259
+ this.setState(nextState);
260
+ }
261
+
262
+ this.unsetSubmitFailure();
263
+ }
264
+ );
265
+
266
+ handleFormFieldChange = (evt: CustomEvent) => {
267
+ // Event target information must be read prior to debouncing; the target is gone after the debounce.
268
+ const { target = {}, detail } = evt;
269
+ const { name: targetName, required: isRequiredField } =
270
+ target as HTMLInputElement;
271
+ const value =
272
+ typeof detail === "string"
273
+ ? detail
274
+ : typeof detail.checked === "boolean"
275
+ ? detail.checked
276
+ : detail.value;
277
+
278
+ // Perform the real work after a debounce, in order to prevent unnecessary work on rapid form value changes:
279
+ this.debouncedFormFieldChangeHandler(
280
+ targetName,
281
+ value,
282
+ isRequiredField
283
+ );
284
+ };
285
+
286
+ @api
287
+ notifySubmitFailure(formSubmissionFailureState: Partial<DrmFormData>) {
288
+ this.showSubmitFailureAlert = true;
289
+ // After form submission failure, restore at most the following values to the form:
290
+ const {
291
+ FirstName,
292
+ LastName,
293
+ Email,
294
+ MailingCountry,
295
+ MailingState,
296
+ Company__c,
297
+ DRM_Role__c,
298
+ Referral_Email__c
299
+ } = formSubmissionFailureState;
300
+ this.setState({
301
+ FirstName,
302
+ LastName,
303
+ Email,
304
+ MailingCountry,
305
+ MailingState,
306
+ Company__c,
307
+ DRM_Role__c,
308
+ Referral_Email__c
309
+ });
310
+ }
311
+
312
+ private unsetSubmitFailure() {
313
+ if (this.showSubmitFailureAlert) {
314
+ this.showSubmitFailureAlert = false;
315
+ }
316
+ }
317
+
318
+ private handleCountryChange(countryCode: string) {
319
+ const countryData = this._countriesLookup[countryCode];
320
+
321
+ this.setState({
322
+ MailingCountry: countryCode,
323
+ MailingState: undefined,
324
+ learnMore: countryData.learnMore,
325
+ legalText: countryData.legalText,
326
+ marketingText: countryData.marketingText,
327
+ showLegalCheckbox: countryData.showLegalCheckbox,
328
+ showMarketingText: countryData.showMarketingText
329
+ });
330
+
331
+ this.dispatchEvent(
332
+ new CustomEvent("countrychange", {
333
+ bubbles: true,
334
+ composed: true,
335
+ detail: countryCode
336
+ })
337
+ );
338
+
339
+ // Because updating the country can update the required fields, we need to re-set form
340
+ // validity _after_ render
341
+ requestAnimationFrame(() =>
342
+ this.setState({
343
+ isFormValid: this.checkValidity()
344
+ })
345
+ );
346
+ }
347
+
348
+ private updateInnerHtml(selector: string, html: string): void {
349
+ const element = this.template.querySelector(selector);
350
+ if (element) {
351
+ element.innerHTML = html;
352
+ }
353
+ }
354
+
355
+ private isParticipatingCountry(country: string) {
356
+ return this.participatingCountryCodes.includes(country);
357
+ }
358
+
359
+ private checkValidity() {
360
+ return (
361
+ Boolean(this.recaptchaToken) &&
362
+ !this.isSalesforceEmployee &&
363
+ this.isParticipatingCountry(this.state.MailingCountry) &&
364
+ this.requiredFormFields.every(
365
+ (requiredFormField) =>
366
+ // @ts-ignore
367
+ requiredFormField.checkValidity?.() === true
368
+ )
369
+ );
370
+ }
371
+ }