@salesforcedevs/dw-components 1.3.140 → 1.3.148-canary.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.
@@ -0,0 +1,158 @@
1
+ <template>
2
+ <form class="j2s-form">
3
+ <div class="form-row">
4
+ <dx-input
5
+ class="first-name-field"
6
+ label="First Name"
7
+ missing-error-message="Enter your first name"
8
+ name="first_name"
9
+ placeholder="Your first name"
10
+ required
11
+ validity-on-blur
12
+ onblur={handleRequiredFieldUpdate}
13
+ value={state.firstName}
14
+ ></dx-input>
15
+ <dx-input
16
+ class="last-name-field"
17
+ label="Last Name"
18
+ missing-error-message="Enter your last name"
19
+ name="last_name"
20
+ placeholder="Your last name"
21
+ required
22
+ validity-on-blur
23
+ onblur={handleRequiredFieldUpdate}
24
+ value={state.lastName}
25
+ ></dx-input>
26
+ </div>
27
+ <div class="form-row">
28
+ <dx-input
29
+ class="company-name-field"
30
+ label="Company Name"
31
+ missing-error-message="Enter your company name"
32
+ name="company_name"
33
+ placeholder="Your company name"
34
+ required
35
+ validity-on-blur
36
+ onblur={handleRequiredFieldUpdate}
37
+ value={state.companyName}
38
+ ></dx-input>
39
+ <dx-select
40
+ if:false={isJobRoleRequired}
41
+ class="job-role-field"
42
+ label="Job Role"
43
+ message-when-value-missing="Select your job role"
44
+ name="job_role"
45
+ options={jobRoles}
46
+ placeholder="Select Job Role"
47
+ value={state.jobRole}
48
+ ></dx-select>
49
+ <dx-select
50
+ if:true={isJobRoleRequired}
51
+ class="job-role-field"
52
+ label="Job Role"
53
+ message-when-value-missing="Select your job role"
54
+ name="job_role"
55
+ options={jobRoles}
56
+ placeholder="Select Job Role"
57
+ required
58
+ value={state.jobRole}
59
+ onchange={handleRequiredFieldUpdate}
60
+ ></dx-select>
61
+ </div>
62
+ <div class="form-row">
63
+ <dx-input
64
+ name="email"
65
+ type="email"
66
+ placeholder="Your email address"
67
+ label="Email"
68
+ missing-error-message="Enter your email address"
69
+ validity-on-blur="true"
70
+ required
71
+ onblur={handleRequiredFieldUpdate}
72
+ value={state.email}
73
+ ></dx-input>
74
+ <dx-select
75
+ label="Country/Region"
76
+ message-when-value-missing="Select your country/region"
77
+ name="country"
78
+ options={countries}
79
+ placeholder="Select Country/Region"
80
+ required
81
+ value={state.country}
82
+ onchange={handleCountryChange}
83
+ ></dx-select>
84
+ </div>
85
+ <div class="form-row" if:true={isCountryWithReferralInput}>
86
+ <dx-input
87
+ name="referral_email"
88
+ class="referral-email-field full-width"
89
+ label="If anyone has referred you, please share their Email ID below, with their consent."
90
+ type="email"
91
+ ></dx-input>
92
+ </div>
93
+ <div class="form-row" if:true={isNotParticipatingCountry}>
94
+ <dx-alert
95
+ alert-info={notAvailableAlertInfo}
96
+ class="full-width"
97
+ type="danger"
98
+ variant="accented"
99
+ ></dx-alert>
100
+ </div>
101
+ <div class="form-terms-container">
102
+ <div class="form-row" if:true={state.showMarketingText}>
103
+ <dx-checkbox
104
+ value="marketing-terms"
105
+ name="marketing_terms"
106
+ required
107
+ class="terms"
108
+ onchange={handleRequiredFieldUpdate}
109
+ disabled={isNotParticipatingCountry}
110
+ >
111
+ <span lwc:dom="manual" class="marketing-terms"></span>
112
+ </dx-checkbox>
113
+ </div>
114
+ <div class="form-row">
115
+ <dx-checkbox
116
+ value="j2s-terms"
117
+ name="j2s_terms"
118
+ required
119
+ class="terms"
120
+ onchange={handleRequiredFieldUpdate}
121
+ disabled={isNotParticipatingCountry}
122
+ >
123
+ <span lwc:dom="manual" class="j2s-terms"></span>
124
+ </dx-checkbox>
125
+ </div>
126
+ <div class="form-row">
127
+ <dx-checkbox
128
+ if:true={state.showLegalCheckbox}
129
+ value="legal-terms"
130
+ name="legal_terms"
131
+ required
132
+ class="terms"
133
+ onchange={handleRequiredFieldUpdate}
134
+ disabled={isNotParticipatingCountry}
135
+ >
136
+ <span lwc:dom="manual" class="legal-terms"></span>
137
+ <template if:true={state.learnMore}>
138
+ <dx-button
139
+ variant="inline-inherit"
140
+ onclick={handleLearnMore}
141
+ >
142
+ Learn More
143
+ </dx-button>
144
+ <span
145
+ lwc:dom="manual"
146
+ class="legal-terms-learn-more hidden"
147
+ ></span>
148
+ </template>
149
+ </dx-checkbox>
150
+ <span
151
+ if:false={state.showLegalCheckbox}
152
+ lwc:dom="manual"
153
+ class="legal-terms no-checkbox"
154
+ ></span>
155
+ </div>
156
+ </div>
157
+ </form>
158
+ </template>
@@ -0,0 +1,225 @@
1
+ import { toJson } from "dxUtils/normalizers";
2
+ import { api } from "lwc";
3
+ import { LightningElementWithState } from "dxBaseElements/lightningElementWithState";
4
+
5
+ // Hard-coding for now because we can't get information about an endpoint for this
6
+ const tbidValidRoles = [
7
+ "Developer",
8
+ "Administrator",
9
+ "Architect",
10
+ "Sales Representative / Manager",
11
+ "Marketer",
12
+ "Service Agent / Supervisor",
13
+ "Data Analyst",
14
+ "Consultant",
15
+ "Business Operations Manager",
16
+ "Designer",
17
+ "Educator",
18
+ "Student",
19
+ "Executive",
20
+ "Product Manager"
21
+ ];
22
+
23
+ export type J2sFormState = {
24
+ country: string;
25
+ legalText: string;
26
+ marketingText: string;
27
+ learnMore: string;
28
+ showLegalCheckbox: boolean;
29
+ showMarketingText: boolean;
30
+ isFormValid: boolean;
31
+ };
32
+
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
+ private _countriesJson = "";
39
+ private _countriesLookup: any = {}; // TODO typings
40
+ @api id = "";
41
+ @api referralText = "";
42
+
43
+ @api
44
+ get countries() {
45
+ return this._countriesJson || "[]";
46
+ }
47
+ set countries(value: string) {
48
+ this._countriesJson = value;
49
+
50
+ // Store a lookup table of country data by value so that we don't have to loop all the time
51
+ const countries = toJson(value);
52
+ const countriesLookup: any = {};
53
+ countries.forEach((country: any) => {
54
+ countriesLookup[country.value] = country;
55
+ });
56
+ this._countriesLookup = countriesLookup;
57
+ }
58
+
59
+ @api
60
+ get incomingUserInfo() {
61
+ return this._incomingUserInfo;
62
+ }
63
+ set incomingUserInfo(value: string) {
64
+ this._incomingUserInfo = toJson(value);
65
+ }
66
+
67
+ @api
68
+ get formMetadata() {
69
+ return this._formMetadata;
70
+ }
71
+ set formMetadata(value: string) {
72
+ this._formMetadata = toJson(value);
73
+ }
74
+
75
+ private participatingCountryCodes = ["US", "CA", "IN"];
76
+ private countriesWithReferralInput = ["IN"];
77
+ private countriesWithRequiredJobRole = ["CA"];
78
+ private requiredFormFields: HTMLElement[] = [];
79
+
80
+ get isNotParticipatingCountry() {
81
+ return !this.isParticipatingCountry(this.state.country);
82
+ }
83
+
84
+ get isCountryWithReferralInput() {
85
+ return this.countriesWithReferralInput.includes(this.state.country);
86
+ }
87
+
88
+ get isJobRoleRequired() {
89
+ return this.countriesWithRequiredJobRole.includes(this.state.country);
90
+ }
91
+
92
+ get notAvailableAlertInfo() {
93
+ return (this.formMetadata as any).notAvailableAlertInfo;
94
+ }
95
+
96
+ get jobRoles() {
97
+ return tbidValidRoles.map((role) => ({
98
+ label: role,
99
+ value: role
100
+ }));
101
+ }
102
+
103
+ connectedCallback() {
104
+ const initialState: Partial<J2sFormState> = {
105
+ ...this._incomingUserInfo,
106
+ isFormValid: false,
107
+ showMarketingText: true
108
+ };
109
+ const initialCountry = initialState.country;
110
+ const initialCountryData =
111
+ initialCountry && this._countriesLookup[initialCountry];
112
+ if (initialCountryData) {
113
+ initialState.showLegalCheckbox =
114
+ initialCountryData.showLegalCheckbox;
115
+ initialState.legalText = initialCountryData.legalText;
116
+ initialState.marketingText = initialCountryData.marketingText;
117
+ initialState.learnMore = initialCountryData.learnMore;
118
+ }
119
+
120
+ this.state = initialState as J2sFormState;
121
+ }
122
+
123
+ renderedCallback(): void {
124
+ if (this._isInitialRender) {
125
+ this.updateInnerHtml(
126
+ "span.j2s-terms",
127
+ (this.formMetadata as any).j2sTerms
128
+ );
129
+ }
130
+
131
+ if (
132
+ this.state.country &&
133
+ this.state.country !== this.prevState.country
134
+ ) {
135
+ // Re-render new country's terms
136
+ this.updateInnerHtml(
137
+ "span.marketing-terms",
138
+ this.state.marketingText
139
+ );
140
+ this.updateInnerHtml("span.legal-terms", this.state.legalText);
141
+ if (this.state.learnMore) {
142
+ this.updateInnerHtml(
143
+ "span.legal-terms-learn-more",
144
+ this.state.learnMore
145
+ );
146
+ } else {
147
+ this.updateInnerHtml("span.legal-terms-learn-more", "");
148
+ this.template
149
+ .querySelector(".legal-terms-learn-more")
150
+ ?.classList.add("hidden");
151
+ }
152
+ }
153
+
154
+ if (this.state.isFormValid !== this.prevState.isFormValid) {
155
+ this.dispatchEvent(
156
+ new CustomEvent("formvaliditychange", {
157
+ detail: {
158
+ isValid: this.state.isFormValid
159
+ },
160
+ bubbles: true,
161
+ composed: true
162
+ })
163
+ );
164
+ }
165
+
166
+ this.requiredFormFields = Array.from(
167
+ this.template.querySelectorAll("[required]")
168
+ );
169
+
170
+ if (this.id && !this._didSetFormId) {
171
+ this._didSetFormId = true;
172
+ this.template.querySelector("form")?.setAttribute("id", this.id);
173
+ }
174
+ }
175
+
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
+ handleRequiredFieldUpdate() {
188
+ const isFormNowValid = this.checkValidity(this.state.country);
189
+ if (this.state.isFormValid !== isFormNowValid) {
190
+ this.setState({
191
+ isFormValid: isFormNowValid
192
+ });
193
+ }
194
+ }
195
+
196
+ handleCountryChange({ detail }: CustomEvent) {
197
+ const { value } = detail;
198
+ const countryData = this._countriesLookup[value];
199
+ this.setState({
200
+ country: value,
201
+ isFormValid: this.checkValidity(value),
202
+ learnMore: countryData.learnMore,
203
+ legalText: countryData.legalText,
204
+ marketingText: countryData.marketingText,
205
+ showLegalCheckbox: countryData.showLegalCheckbox
206
+ });
207
+ }
208
+
209
+ handleLearnMore() {
210
+ this.template
211
+ .querySelector(".legal-terms-learn-more")
212
+ ?.classList.toggle("hidden");
213
+ }
214
+
215
+ private checkValidity(country: string) {
216
+ return (
217
+ this.isParticipatingCountry(country) &&
218
+ this.requiredFormFields.every(
219
+ (requiredFormField) =>
220
+ // @ts-ignore
221
+ requiredFormField.checkValidity?.() === true
222
+ )
223
+ );
224
+ }
225
+ }