@salesforcedevs/dw-components 1.3.95 → 1.3.104-alpha.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.
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@salesforcedevs/dw-components",
3
- "version": "1.3.95",
3
+ "version": "1.3.104-alpha.0",
4
4
  "description": "Lightning web components for https://developer.salesforce.com",
5
5
  "license": "MIT",
6
6
  "engines": {
@@ -24,5 +24,5 @@
24
24
  "@types/setimmediate": "^1.0.2",
25
25
  "setimmediate": "^1.0.5"
26
26
  },
27
- "gitHead": "77e4f95b4d2ca8dd7fc0b9bea5015b7c83a8f37b"
27
+ "gitHead": "e10d764cbe3b3e9956eb47572b4dd3b4bed760e3"
28
28
  }
@@ -2,6 +2,10 @@ dx-section:first-of-type {
2
2
  --dx-c-section-padding-bottom: 0;
3
3
  }
4
4
 
5
+ dx-section {
6
+ --dx-c-section-position: revert;
7
+ }
8
+
5
9
  .badge-link-container {
6
10
  padding-top: var(--dx-g-spacing-md);
7
11
  }
@@ -25,7 +25,9 @@ span {
25
25
  }
26
26
 
27
27
  dx-checkbox,
28
- .privacy-notice {
28
+ .privacy-notice,
29
+ span.privacy-terms,
30
+ span.marketing-terms {
29
31
  width: 100%;
30
32
  margin-bottom: var(--dx-g-spacing-lg);
31
33
  }
@@ -52,7 +52,7 @@
52
52
  placeholder="Select Country/Region"
53
53
  required
54
54
  value=""
55
- onchange={handleCountryChange}
55
+ onchange={handleConsent}
56
56
  ></dx-select>
57
57
  <dx-input
58
58
  label="Postal Code"
@@ -78,26 +78,39 @@
78
78
  ></dx-input>
79
79
 
80
80
  <dx-checkbox required name="eula" value="accepted">
81
- <span lwc:dom="manual" class="legal-terms"></span>
81
+ <span class="legal-terms">{legalText}</span>
82
82
  </dx-checkbox>
83
- <dx-checkbox
84
- if:true={showMarketingCheckbox}
85
- name="opt_in"
86
- value="False"
87
- >
88
- <span lwc:dom="manual" class="marketing-terms"></span>
89
- </dx-checkbox>
90
- <dx-checkbox
91
- if:true={showPrivacyCheckbox}
92
- required
93
- name="privacy"
94
- value="privacy_accepted"
95
- >
96
- <span lwc:dom="manual" class="privacy-terms"></span>
97
- </dx-checkbox>
98
- <template if:false={showPrivacyCheckbox}>
99
- <span lwc:dom="manual" class="privacy-terms privacy-notice"></span>
83
+
84
+ <template if:false={showMarketingCheckbox}>
85
+ <span class="marketing-terms">{marketingText}</span>
100
86
  </template>
87
+ <template if:true={showMarketingCheckbox}>
88
+ <dx-checkbox
89
+ name="marketingCheckbox"
90
+ class="marketing-terms"
91
+ value="false"
92
+ onchange={handleMarketingCheckbox}
93
+ >
94
+ <span>{marketingText}</span>
95
+ </dx-checkbox>
96
+ </template>
97
+
98
+ <template if:false={showLegalCheckbox}>
99
+ <span lwc:dom="manual" class="legal-checkbox privacy-terms"></span>
100
+ </template>
101
+ <template if:true={showLegalCheckbox}>
102
+ <dx-checkbox
103
+ class="legal-checkbox privacy-terms"
104
+ value={legalCheckbox}
105
+ required="true"
106
+ >
107
+ <span
108
+ lwc:dom="manual"
109
+ class="legal-checkbox privacy-terms"
110
+ ></span>
111
+ </dx-checkbox>
112
+ </template>
113
+
101
114
  <dx-button
102
115
  class="submit-button"
103
116
  disabled={disableSubmit}
@@ -2,6 +2,7 @@ import { LightningElement, api, track } from "lwc";
2
2
  import { toJson } from "dxUtils/normalizers";
3
3
  import { track as trackGtm } from "dxUtils/analytics";
4
4
  import { submitForm, ErrorCode, SignupForm, UserData } from "./submitForm";
5
+ import { CountryOptions } from "typings/custom";
5
6
 
6
7
  type SelectOption = { value: string; label: string };
7
8
  type Country = SelectOption & {
@@ -34,16 +35,21 @@ export default class DeSignupForm extends LightningElement {
34
35
  this._roles = toJson(value);
35
36
  }
36
37
 
37
- @api marketingText: string = "";
38
- @api privacyText: string = "";
39
38
  @api legalText: string = "";
39
+ @api drmDomain: string = "https://drm.my.salesforce-sites.com";
40
40
 
41
41
  private country: Country = null;
42
42
  private disableSubmit = false;
43
43
  private username = "";
44
- private updateCheckboxLabels = true;
45
- private _countries: Array<Country>;
44
+ private _countries: string = "";
46
45
  private _roles: Array<SelectOption>;
46
+ private showMarketingCheckbox: boolean = false;
47
+ private marketingCheckbox: boolean = false;
48
+ private marketingText: string = "";
49
+ private showLegalCheckbox: boolean = false;
50
+ private privacyText: string = "";
51
+ private hasRendered = false;
52
+
47
53
  @track knownDuplicateUsers = [];
48
54
 
49
55
  get usernameError(): string {
@@ -56,10 +62,6 @@ export default class DeSignupForm extends LightningElement {
56
62
  return !this.knownDuplicateUsers.includes(this.username);
57
63
  }
58
64
 
59
- get showMarketingCheckbox(): boolean {
60
- return this.country && this.country.showMarketingCheckbox;
61
- }
62
-
63
65
  get showPrivacyCheckbox(): boolean {
64
66
  return this.country && !!this.country.privacyOptIn;
65
67
  }
@@ -68,22 +70,17 @@ export default class DeSignupForm extends LightningElement {
68
70
  return this.disableSubmit ? "Beep boop processing" : SIGN_UP_LABEL;
69
71
  }
70
72
 
73
+ connectedCallback(): void {
74
+ this.getCountryList();
75
+ }
76
+
71
77
  renderedCallback(): void {
72
- if (!this.updateCheckboxLabels) {
78
+ if (!this.hasRendered) {
79
+ this.hasRendered = true;
73
80
  return;
74
81
  }
75
-
76
- this.updateCheckboxLabels =
77
- this.updateInnerHtml("span.legal-terms", this.legalText) ||
78
- this.updateInnerHtml(
79
- "span.marketing-terms",
80
- this.marketingText,
81
- this.showMarketingCheckbox
82
- ) ||
83
- this.updateInnerHtml(
84
- "span.privacy-terms",
85
- this.country?.privacyText || this.privacyText
86
- );
82
+ this.hasRendered = true;
83
+ this.updateInnerHtml("span.legal-checkbox", this.privacyText);
87
84
  }
88
85
 
89
86
  handleSubmit(event: Event): void {
@@ -141,13 +138,6 @@ export default class DeSignupForm extends LightningElement {
141
138
  this.username = event.detail;
142
139
  }
143
140
 
144
- handleCountryChange(event: CustomEvent<{ value: string }>): void {
145
- this.country = this.countries.find(
146
- ({ value }) => value === event.detail.value
147
- );
148
- this.updateCheckboxLabels = true;
149
- }
150
-
151
141
  private prepareUserData(): SignupForm | null {
152
142
  const fields = Array.from(
153
143
  this.template.querySelectorAll<HTMLFormElement>(
@@ -159,9 +149,7 @@ export default class DeSignupForm extends LightningElement {
159
149
  value: element.value
160
150
  }));
161
151
 
162
- const checkboxes = this.getCheckboxesResult();
163
-
164
- if (fields.some((field) => !field.valid) || !checkboxes.valid) {
152
+ if (fields.some((field) => !field.valid)) {
165
153
  return null;
166
154
  }
167
155
 
@@ -170,17 +158,15 @@ export default class DeSignupForm extends LightningElement {
170
158
  userData[field.name] = field.value;
171
159
  });
172
160
 
173
- (userData as UserData).consent = this.country.showMarketingCheckbox
161
+ (userData as UserData).consent = this.showMarketingCheckbox
174
162
  ? "Explicit"
175
- : "Implied ";
163
+ : "Implied";
176
164
  const InfoEmail =
177
- this.country.showMarketingCheckbox && !checkboxes.values.opt_in
165
+ this.showMarketingCheckbox && !this.marketingCheckbox
178
166
  ? "False"
179
167
  : "True";
180
-
181
168
  const formData: SignupForm = {
182
169
  user: userData as UserData,
183
- eula: checkboxes.values.eula,
184
170
  default_driver: DEFAULT_DRIVER,
185
171
  info_email: InfoEmail
186
172
  };
@@ -188,24 +174,70 @@ export default class DeSignupForm extends LightningElement {
188
174
  return formData;
189
175
  }
190
176
 
191
- private getCheckboxesResult(): {
192
- valid: boolean;
193
- values: { eula: string; opt_in: "true" | "false" };
194
- } {
195
- let valid = true;
196
- const values: { eula: string; opt_in: "true" | "false" } = {
197
- eula: "",
198
- opt_in: "false"
199
- };
177
+ handleConsent(countrySelectElement: any) {
178
+ countrySelectElement = countrySelectElement.target;
179
+ const countryOptions = countrySelectElement.options.find(
180
+ (option: any) => option.value === countrySelectElement.value
181
+ );
182
+ this.marketingCheckbox = false;
183
+ this.setLegalAndMarketingData(countryOptions);
184
+ }
200
185
 
201
- Array.from(
202
- this.template.querySelectorAll<HTMLInputElement>("dx-checkbox")
203
- ).forEach((checkbox) => {
204
- valid = valid && checkbox.reportValidity();
205
- values[checkbox.name] = checkbox.checked;
206
- });
186
+ handleMarketingCheckbox(marketingCheckbox: any) {
187
+ this.marketingCheckbox = marketingCheckbox.target.checked;
188
+ }
207
189
 
208
- return { valid, values };
190
+ setLegalAndMarketingData(countryOptions: CountryOptions) {
191
+ // Set the checkbox text
192
+ this.setCheckboxTextSet(
193
+ countryOptions.marketingText,
194
+ countryOptions.legalText
195
+ );
196
+
197
+ // Toggle visibility of legal/marketing data
198
+ this.toggleLegalAndMarketingVisibility(
199
+ countryOptions.showMarketingText,
200
+ countryOptions.showLegalCheckbox
201
+ );
202
+ }
203
+
204
+ setCheckboxTextSet(marketingText: string, privacyText: string) {
205
+ this.privacyText = privacyText;
206
+ this.marketingText = marketingText;
207
+ }
208
+
209
+ toggleLegalAndMarketingVisibility(
210
+ showMarketingCheckbox: boolean,
211
+ showLegalCheckbox: boolean
212
+ ) {
213
+ this.showMarketingCheckbox = showMarketingCheckbox;
214
+ this.showLegalCheckbox = showLegalCheckbox;
215
+ }
216
+
217
+ setInnerHtml(element: HTMLElement, value: string) {
218
+ // disable lwc warning because text received from json has HTML
219
+ // eslint-disable-next-line @lwc/lwc/no-inner-html
220
+ element.innerHTML = value;
221
+ }
222
+
223
+ async getCountryList() {
224
+ const errorMsg = "Error while getting county list";
225
+
226
+ try {
227
+ const res = await fetch(
228
+ `${this.drmDomain}/utilities/services/apexrest/countries`
229
+ );
230
+
231
+ if (!res.ok) {
232
+ throw new Error(errorMsg);
233
+ }
234
+
235
+ const data = await res.json();
236
+ // eslint-disable-next-line @lwc/lwc/no-api-reassignments
237
+ this._countries = JSON.stringify(data);
238
+ } catch (error) {
239
+ console.error(error);
240
+ }
209
241
  }
210
242
 
211
243
  private updateInnerHtml(
@@ -20,7 +20,6 @@ export type UserData = {
20
20
 
21
21
  export type SignupForm = {
22
22
  user: UserData;
23
- eula: string;
24
23
  default_driver: string;
25
24
  info_email: "True" | "False";
26
25
  };