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

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/lwc.config.json CHANGED
@@ -14,6 +14,8 @@
14
14
  "dw/docsGrid",
15
15
  "dw/eventsList",
16
16
  "dw/instrumentation",
17
+ "dw/j2sCardSequence",
18
+ "dw/j2sForm",
17
19
  "dw/newsletterForm",
18
20
  "dw/podcastSubscription",
19
21
  "dw/podcastsGrid",
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@salesforcedevs/dw-components",
3
- "version": "1.3.147",
3
+ "version": "1.3.148-canary.1",
4
4
  "description": "Lightning web components for https://developer.salesforce.com",
5
5
  "license": "MIT",
6
6
  "engines": {
@@ -23,6 +23,5 @@
23
23
  "@types/lodash.uniqby": "^4.7.7",
24
24
  "@types/setimmediate": "^1.0.2",
25
25
  "setimmediate": "^1.0.5"
26
- },
27
- "gitHead": "c046874452685c28208a52392b494ad791c3f305"
26
+ }
28
27
  }
@@ -0,0 +1,53 @@
1
+ @import "dxHelpers/reset";
2
+ @import "dxHelpers/text";
3
+ @import "dxHelpers/card";
4
+
5
+ :host {
6
+ --dx-c-button-custom-color: var(--dx-g-blue-vibrant-50);
7
+ --dx-c-button-custom-background: white;
8
+ --dx-c-button-custom-border: var(--dx-g-blue-vibrant-50);
9
+ --dx-c-button-custom-color-hover: var(--dx-g-blue-vibrant-50);
10
+ --dx-c-button-custom-background-hover: var(--dx-g-cloud-blue-vibrant-90);
11
+ --dx-c-button-custom-border-hover: var(--dx-g-cloud-blue-vibrant-50);
12
+ }
13
+
14
+ dx-step-sequence {
15
+ scroll-margin-top: var(--dx-g-global-header-height);
16
+ }
17
+
18
+ dx-step-sequence-step:last-child dx-card-step::part(footer-container) {
19
+ background-color: var(--dx-g-indigo-vibrant-95);
20
+ border-radius: 8px;
21
+ margin: 0 30px 30px 30px;
22
+ }
23
+
24
+ [slot="secondary-action-section"] {
25
+ color: var(--dx-g-red-vibrant-50);
26
+ position: relative;
27
+ font-size: var(--dx-g-text-xs, 12px);
28
+ font-family: var(--dx-g-font-sans);
29
+ line-height: 18px;
30
+ text-align: left;
31
+ }
32
+
33
+ .body-container li {
34
+ line-height: var(--dx-g-text-2xl);
35
+ }
36
+
37
+ .body-container p:not(:last-child) {
38
+ padding-bottom: 20px;
39
+ }
40
+
41
+ .body-markup {
42
+ display: block;
43
+ padding-bottom: var(--dx-g-spacing-md);
44
+ }
45
+
46
+ .referral-email-field {
47
+ --dx-c-input-width: 100%;
48
+ }
49
+
50
+ .spinner-container {
51
+ min-height: 200px;
52
+ position: relative;
53
+ }
@@ -0,0 +1,70 @@
1
+ <template>
2
+ <dx-step-sequence
3
+ animate-transitions={animateTransitions}
4
+ communicate-step-changes="true"
5
+ initial-step-index={initialStepIndex}
6
+ onstepsequencechange={handleStepSequenceChange}
7
+ session-storage-id={sessionStorageId}
8
+ use-history={useHistory}
9
+ >
10
+ <template for:each={stepsData} for:item="stepDatum" for:index="index">
11
+ <dx-step-sequence-step key={stepDatum.id}>
12
+ <dx-card-step
13
+ header-icon-symbol={stepDatum.headerData.iconSymbol}
14
+ header-icon-sprite={stepDatum.headerData.iconSprite}
15
+ header-icon-color={stepDatum.headerData.iconColor}
16
+ header-background-color={stepDatum.headerData.backgroundColor}
17
+ header-text-color={stepDatum.headerData.textColor}
18
+ show-step-number={stepDatum.showStepNumber}
19
+ step-count={stepsData.length}
20
+ step-index={index}
21
+ step-title={stepDatum.stepTitle}
22
+ >
23
+ <div slot="card-body" class="body-container">
24
+ <template if:true={isLoading}>
25
+ <div class="spinner-container">
26
+ <dx-spinner
27
+ size="large"
28
+ variant="brand"
29
+ ></dx-spinner>
30
+ </div>
31
+ </template>
32
+ <template if:false={isLoading}>
33
+ <span lwc:dom="manual" class="body-markup"></span>
34
+ <template if:true={stepDatum.formData}>
35
+ <dw-j2s-form
36
+ id={stepDatum.formData.formId}
37
+ countries={countries}
38
+ form-metadata={stepDatum.formMetadata}
39
+ incoming-user-info={formIncomingUserInfo}
40
+ onformvaliditychange={handleFormValidityChange}
41
+ ></dw-j2s-form>
42
+ </template>
43
+ </template>
44
+ </div>
45
+ <div slot="secondary-action-section">
46
+ <span
47
+ lwc:dom="manual"
48
+ class="secondary-action-markup"
49
+ ></span>
50
+ </div>
51
+ <div slot="primary-action-section">
52
+ <dx-button
53
+ class="primary-action"
54
+ disabled={isJ2sFormInvalid}
55
+ href={stepDatum.primaryAction.link}
56
+ icon-sprite={stepDatum.primaryAction.iconSprite}
57
+ icon-symbol={stepDatum.primaryAction.iconSymbol}
58
+ loading={isLoading}
59
+ onclick={primaryActionHandler}
60
+ size="large"
61
+ variant={primaryActionVariant}
62
+ >
63
+ {stepDatum.primaryAction.text}
64
+ </dx-button>
65
+ </div>
66
+ </dx-card-step>
67
+ </dx-step-sequence-step>
68
+ </template>
69
+ </dx-step-sequence>
70
+ </template>
@@ -0,0 +1,317 @@
1
+ import { api, LightningElement } from "lwc";
2
+ import StepSequence from "dx/stepSequence";
3
+ import { getListWithUuids } from "dxUtils/list";
4
+ 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
+
13
+ export type StepDatum = {
14
+ bodyHtml?: string;
15
+ formData?: {
16
+ countriesWithReferralInput?: string[];
17
+ countriesWithRequiredJobRole?: string[];
18
+ formId?: string;
19
+ j2sTerms?: string;
20
+ notAvailableAlertInfo?: {
21
+ title: string;
22
+ body: string;
23
+ };
24
+ participatingCountryCodes?: string[];
25
+ };
26
+ headerData?: {
27
+ backgroundColor?: string;
28
+ iconColor?: string;
29
+ iconSprite?: string;
30
+ iconSymbol?: string;
31
+ textColor?: string;
32
+ };
33
+ primaryAction: {
34
+ iconSprite?: string;
35
+ iconSymbol?: string;
36
+ link?: string;
37
+ text: string;
38
+ variant?: string;
39
+ };
40
+ secondaryActionHtml?: string;
41
+ showStepNumber?: boolean;
42
+ stepTitle: string;
43
+ };
44
+
45
+ export default class J2sCardSequence extends LightningElement {
46
+ _didRenderStaticInnerHtml = false;
47
+ _isDrmLoading = false;
48
+ _isJ2sFormInvalid = false;
49
+ _isTbidLoading = false;
50
+ _stepsData: StepDatum[] = [];
51
+ @api animateTransitions = false;
52
+ @api drmDomain: string = "https://drm.my.salesforce-sites.com";
53
+ @api tbidApiBaseUrl: string | undefined;
54
+ @api useHistory: boolean = false;
55
+
56
+ @api
57
+ get stepsData() {
58
+ return this._stepsData;
59
+ }
60
+ set stepsData(value) {
61
+ // normalize incoming value with uuid keys and non-required props (for cleaner HTML template), etc.
62
+ this._stepsData = getListWithUuids<StepDatum>(toJson(value)).map(
63
+ (stepDatum) => {
64
+ const normalizedStepDatum = {
65
+ ...stepDatum,
66
+ headerData: stepDatum.headerData || {},
67
+ primaryAction: {
68
+ ...stepDatum.primaryAction,
69
+ variant: stepDatum.primaryAction.variant || "primary",
70
+ iconSprite:
71
+ stepDatum.primaryAction.iconSprite || "general",
72
+ iconSymbol:
73
+ stepDatum.primaryAction.iconSymbol || "arrow-right"
74
+ }
75
+ };
76
+
77
+ if (normalizedStepDatum.formData) {
78
+ (normalizedStepDatum as any).formMetadata = JSON.stringify(
79
+ normalizedStepDatum.formData
80
+ );
81
+ }
82
+
83
+ return normalizedStepDatum;
84
+ }
85
+ );
86
+ }
87
+
88
+ private countries = "[]";
89
+ private currentSequenceStep = 0;
90
+ private sessionStorageId = "j2s-card-sequence";
91
+ private tbidUserInfo: any; // TODO typings?
92
+
93
+ private get isLoading() {
94
+ return this._isDrmLoading || this._isTbidLoading;
95
+ }
96
+
97
+ private get isLoggedIn() {
98
+ return Boolean(this.tbidUserInfo);
99
+ }
100
+
101
+ private get isJ2sFormInvalid() {
102
+ return this.currentSequenceStep === 1 ? this._isJ2sFormInvalid : false;
103
+ }
104
+ private set isJ2sFormInvalid(isFormInvalid: boolean) {
105
+ this._isJ2sFormInvalid = isFormInvalid;
106
+ }
107
+
108
+ private get primaryActionVariant() {
109
+ if (this.currentSequenceStep === 1 && this.isJ2sFormInvalid) {
110
+ return "custom"; // override for disabled button styling
111
+ }
112
+ return this.stepsData[this.currentSequenceStep || 0].primaryAction
113
+ .variant;
114
+ }
115
+
116
+ private get formIncomingUserInfo() {
117
+ if (!this.tbidUserInfo) {
118
+ return "{}";
119
+ }
120
+
121
+ return JSON.stringify({
122
+ firstName: this.tbidUserInfo.given_name,
123
+ lastName: this.tbidUserInfo.family_name,
124
+ email: this.tbidUserInfo.email,
125
+ jobRole: this.tbidUserInfo.custom_attributes?.Role,
126
+ companyName: this.tbidUserInfo.custom_attributes?.CompanyName,
127
+ country: this.tbidUserInfo.custom_attributes?.Country
128
+ });
129
+ }
130
+
131
+ private get initialStepIndex() {
132
+ let initialStepIndex = 0;
133
+
134
+ const storedSessionData = sessionStorage.getItem(this.sessionStorageId);
135
+ if (storedSessionData) {
136
+ try {
137
+ const { currentStepIndex } = JSON.parse(storedSessionData);
138
+ initialStepIndex = currentStepIndex;
139
+ } catch (ex) {
140
+ // noop
141
+ }
142
+ }
143
+
144
+ return initialStepIndex;
145
+ }
146
+ private set initialStepIndex(value: number) {
147
+ sessionStorage.setItem(
148
+ this.sessionStorageId,
149
+ JSON.stringify({
150
+ currentStepIndex: value
151
+ })
152
+ );
153
+ }
154
+
155
+ connectedCallback() {
156
+ this.getCountryList();
157
+ this.getTbidUserInfo();
158
+ // This has to be defined here since it depends on a variable that depends on sessionStorage.
159
+ this.currentSequenceStep = this.initialStepIndex;
160
+ this.resetCustomButtonColors();
161
+ if (isNoAnimationCookieSet()) {
162
+ /* eslint-disable-next-line @lwc/lwc/no-api-reassignments */
163
+ this.animateTransitions = false;
164
+ }
165
+ }
166
+
167
+ renderedCallback() {
168
+ if (this.isLoading) {
169
+ return;
170
+ }
171
+
172
+ if (!this._didRenderStaticInnerHtml) {
173
+ this.updateStaticInnerHtml();
174
+ this._didRenderStaticInnerHtml = true;
175
+ }
176
+ }
177
+
178
+ handleGetStarted(evt: Event) {
179
+ // If the user is not yet logged in, we need to prevent moving immediately to the next
180
+ // step, but set storage up so that they are on the second step when they return to the
181
+ // site in a logged-in state; then, we need to get them to log in.
182
+ if (!this.isLoggedIn) {
183
+ evt.preventDefault();
184
+ this.initialStepIndex = 1;
185
+ this._isTbidLoading = true;
186
+ // @ts-ignore: call out to the tbid-controller on DSC
187
+ window.__startTbidLogin();
188
+ }
189
+ }
190
+
191
+ handleFormValidityChange({ detail }: CustomEvent) {
192
+ this.isJ2sFormInvalid = !detail.isValid;
193
+ }
194
+
195
+ handleStepSequenceChange({ detail }: CustomEvent) {
196
+ this.currentSequenceStep = detail.stepIndex;
197
+ this.resetCustomButtonColors();
198
+ }
199
+
200
+ primaryActionHandler(evt: Event) {
201
+ if ((evt.target as Button)?.disabled) {
202
+ evt.preventDefault();
203
+ return;
204
+ }
205
+
206
+ if (!this.currentSequenceStep) {
207
+ this.handleGetStarted(evt);
208
+ } else if (this.currentSequenceStep === 2) {
209
+ // TODO: send data to DRM
210
+ }
211
+ }
212
+
213
+ private resetCustomButtonColors() {
214
+ let bgColor;
215
+ let textColor;
216
+
217
+ if (this.currentSequenceStep === 1) {
218
+ bgColor = "var(--dx-g-gray-80)";
219
+ textColor = "white";
220
+ } else {
221
+ bgColor = "white";
222
+ textColor = "var(--dx-g-blue-vibrant-50)";
223
+ }
224
+
225
+ this.template.host.style.setProperty(
226
+ "--dx-c-button-custom-color",
227
+ textColor
228
+ );
229
+ this.template.host.style.setProperty(
230
+ "--dx-c-button-custom-background",
231
+ bgColor
232
+ );
233
+ this.template.host.style.setProperty(
234
+ "--dx-c-button-custom-border",
235
+ bgColor
236
+ );
237
+ }
238
+
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);
246
+ }
247
+
248
+ // HTML is received via config from DSC and should be static after initial render.
249
+ private updateStaticInnerHtml() {
250
+ const bodyMarkupContainers =
251
+ this.template.querySelectorAll("span.body-markup");
252
+ const secondaryActionMarkupContainers = this.template.querySelectorAll(
253
+ "span.secondary-action-markup"
254
+ );
255
+
256
+ this.stepsData.forEach((step, stepIndex) => {
257
+ const { bodyHtml, secondaryActionHtml } = step;
258
+ const bodyMarkupContainer = bodyMarkupContainers[stepIndex];
259
+ const secondaryActionMarkupContainer =
260
+ secondaryActionMarkupContainers[stepIndex];
261
+
262
+ if (bodyMarkupContainer) {
263
+ bodyMarkupContainer.innerHTML = bodyHtml || "";
264
+ }
265
+ if (secondaryActionMarkupContainer) {
266
+ secondaryActionMarkupContainer.innerHTML =
267
+ secondaryActionHtml || "";
268
+ }
269
+ });
270
+ }
271
+
272
+ private async getCountryList() {
273
+ this._isDrmLoading = true;
274
+
275
+ const errorMsg = "Error while getting county list";
276
+ try {
277
+ const res = await fetch(
278
+ `${this.drmDomain}/utilities/services/apexrest/countries`
279
+ );
280
+ if (!res.ok) {
281
+ throw new Error(errorMsg);
282
+ }
283
+ const data = await res.json();
284
+ this.countries = JSON.stringify(data);
285
+ } catch (error) {
286
+ console.error(error);
287
+ if (this.initialStepIndex > 0) {
288
+ // Page loaded on a step higher than the first, but we can't get data for the form;
289
+ // send user back to the start for now.
290
+ this.jumpToStepOne();
291
+ }
292
+ }
293
+
294
+ this._isDrmLoading = false;
295
+ }
296
+
297
+ private async getTbidUserInfo() {
298
+ this._isTbidLoading = true;
299
+
300
+ try {
301
+ const res = await fetch(`${this.tbidApiBaseUrl}/userinfo`);
302
+ if (res.ok) {
303
+ this.tbidUserInfo = await res.json();
304
+ }
305
+ } catch (ex) {
306
+ // noop; nothing to do here
307
+ }
308
+
309
+ if (!this.tbidUserInfo && this.initialStepIndex > 0) {
310
+ // login failed and the user was previously beyond the start step; need to send them
311
+ // back to the start:
312
+ this.jumpToStepOne();
313
+ }
314
+
315
+ this._isTbidLoading = false;
316
+ }
317
+ }
@@ -0,0 +1,46 @@
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.'
18
+ },
19
+ participatingCountryCodes: ["US", "CA", "IN"]
20
+ },
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"
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
+ ];
@@ -0,0 +1,46 @@
1
+ .hidden {
2
+ display: none;
3
+ }
4
+
5
+ .form-row {
6
+ display: flex;
7
+ justify-content: space-between;
8
+ padding-bottom: var(--dx-g-spacing-md);
9
+ }
10
+
11
+ .form-row > * {
12
+ --dx-c-input-width: 100%;
13
+
14
+ font-family: var(--dx-g-font-sans);
15
+ width: calc(50% - 20px);
16
+ }
17
+
18
+ .form-row > :only-child {
19
+ max-width: 100%;
20
+ width: 100%;
21
+ }
22
+
23
+ .form-row .terms {
24
+ --dx-c-checkbox-text-line-height: 20px;
25
+ --dx-c-checkbox-font-size: 14px;
26
+
27
+ font-family: var(--dx-g-font-sans);
28
+ font-size: var(--dx-c-checkbox-font-size);
29
+ font-weight: var(--dx-g-font-normal);
30
+ }
31
+
32
+ .form-row .legal-terms-learn-more:not(.hidden) {
33
+ display: block;
34
+ padding-top: var(--dx-g-spacing-md);
35
+ }
36
+
37
+ .form-row .legal-terms.no-checkbox {
38
+ font-family: var(--dx-g-font-sans);
39
+ font-size: var(--dx-g-text-xs);
40
+ font-weight: var(--dx-g-font-normal);
41
+ margin-left: 28px;
42
+ }
43
+
44
+ .form-terms-container {
45
+ padding-top: var(--dx-g-spacing-sm);
46
+ }