@salesforcedevs/dw-components 1.3.109 → 1.3.120-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.109",
3
+ "version": "1.3.120-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": "bd688e3e86b4d0d9d58765892bbffeec9dce2a1a"
27
+ "gitHead": "e10d764cbe3b3e9956eb47572b4dd3b4bed760e3"
28
28
  }
@@ -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
  }
@@ -51,8 +51,8 @@
51
51
  options={countries}
52
52
  placeholder="Select Country/Region"
53
53
  required
54
- value=""
55
- onchange={handleCountryChange}
54
+ value={country}
55
+ onchange={handleConsent}
56
56
  ></dx-select>
57
57
  <dx-input
58
58
  label="Postal Code"
@@ -77,27 +77,36 @@
77
77
  onchange={handleUsernameChange}
78
78
  ></dx-input>
79
79
 
80
- <dx-checkbox required name="eula" value="accepted">
80
+ <dx-checkbox required name="eula" value="accepted" if:true={legalText}>
81
81
  <span lwc:dom="manual" class="legal-terms"></span>
82
82
  </dx-checkbox>
83
- <dx-checkbox
84
- if:true={showMarketingCheckbox}
85
- name="opt_in"
86
- value="False"
87
- >
83
+
84
+ <template if:false={showMarketingCheckbox}>
88
85
  <span lwc:dom="manual" class="marketing-terms"></span>
89
- </dx-checkbox>
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>
90
101
  <dx-checkbox
91
- if:true={showPrivacyCheckbox}
92
- required
93
- name="privacy"
94
- value="privacy_accepted"
102
+ if:true={showLegalCheckbox}
103
+ class="privacy-terms"
104
+ value={legalCheckbox}
105
+ required="true"
95
106
  >
96
- <span lwc:dom="manual" class="privacy-terms"></span>
107
+ <span lwc:dom="manual" class="legal-checkbox privacy-terms"></span>
97
108
  </dx-checkbox>
98
- <template if:false={showPrivacyCheckbox}>
99
- <span lwc:dom="manual" class="privacy-terms privacy-notice"></span>
100
- </template>
109
+
101
110
  <dx-button
102
111
  class="submit-button"
103
112
  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 & {
@@ -16,15 +17,6 @@ const DUPLICATE_USERNAME_MESSAGE =
16
17
  const SIGN_UP_LABEL = "Sign me Up";
17
18
 
18
19
  export default class DeSignupForm extends LightningElement {
19
- @api
20
- get countries() {
21
- return this._countries;
22
- }
23
-
24
- set countries(value) {
25
- this._countries = toJson(value);
26
- }
27
-
28
20
  @api
29
21
  get roles() {
30
22
  return this._roles;
@@ -33,17 +25,20 @@ export default class DeSignupForm extends LightningElement {
33
25
  set roles(value) {
34
26
  this._roles = toJson(value);
35
27
  }
36
-
37
- @api marketingText: string = "";
38
- @api privacyText: string = "";
28
+ @api countries: string = "";
29
+ @api drmDomain: string = "";
39
30
  @api legalText: string = "";
40
31
 
41
32
  private country: Country = null;
42
33
  private disableSubmit = false;
43
34
  private username = "";
44
- private updateCheckboxLabels = true;
45
- private _countries: Array<Country>;
46
35
  private _roles: Array<SelectOption>;
36
+ private showMarketingCheckbox: boolean = false;
37
+ private marketingCheckbox: boolean = false;
38
+ private marketingText: string = "";
39
+ private showLegalCheckbox: boolean = false;
40
+ private privacyText: string = "";
41
+
47
42
  @track knownDuplicateUsers = [];
48
43
 
49
44
  get usernameError(): string {
@@ -56,34 +51,18 @@ export default class DeSignupForm extends LightningElement {
56
51
  return !this.knownDuplicateUsers.includes(this.username);
57
52
  }
58
53
 
59
- get showMarketingCheckbox(): boolean {
60
- return this.country && this.country.showMarketingCheckbox;
61
- }
62
-
63
- get showPrivacyCheckbox(): boolean {
64
- return this.country && !!this.country.privacyOptIn;
65
- }
66
-
67
54
  get buttonLabel(): string {
68
55
  return this.disableSubmit ? "Beep boop processing" : SIGN_UP_LABEL;
69
56
  }
70
57
 
71
- renderedCallback(): void {
72
- if (!this.updateCheckboxLabels) {
73
- return;
74
- }
58
+ connectedCallback(): void {
59
+ this.getCountryList();
60
+ }
75
61
 
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
- );
62
+ renderedCallback(): void {
63
+ this.updateInnerHtml("span.legal-terms", this.legalText);
64
+ this.updateInnerHtml("span.marketing-terms", this.marketingText);
65
+ this.updateInnerHtml("span.legal-checkbox", this.privacyText);
87
66
  }
88
67
 
89
68
  handleSubmit(event: Event): void {
@@ -115,7 +94,8 @@ export default class DeSignupForm extends LightningElement {
115
94
  "https://developer.salesforce.com/signup/success",
116
95
  form_country: formData.user.country,
117
96
  form_name: "Dev Edition Signup",
118
- form_primary_product_interest: "Developer Edition"
97
+ form_primary_product_interest: "Developer Edition",
98
+ offer_type: "free trial"
119
99
  });
120
100
  window.location.href = "/signup/success";
121
101
  })
@@ -140,13 +120,6 @@ export default class DeSignupForm extends LightningElement {
140
120
  this.username = event.detail;
141
121
  }
142
122
 
143
- handleCountryChange(event: CustomEvent<{ value: string }>): void {
144
- this.country = this.countries.find(
145
- ({ value }) => value === event.detail.value
146
- );
147
- this.updateCheckboxLabels = true;
148
- }
149
-
150
123
  private prepareUserData(): SignupForm | null {
151
124
  const fields = Array.from(
152
125
  this.template.querySelectorAll<HTMLFormElement>(
@@ -158,9 +131,14 @@ export default class DeSignupForm extends LightningElement {
158
131
  value: element.value
159
132
  }));
160
133
 
161
- const checkboxes = this.getCheckboxesResult();
134
+ let validCheckboxes = true;
135
+ Array.from(
136
+ this.template.querySelectorAll<HTMLInputElement>("dx-checkbox")
137
+ ).forEach((checkbox) => {
138
+ validCheckboxes = validCheckboxes && checkbox.reportValidity();
139
+ });
162
140
 
163
- if (fields.some((field) => !field.valid) || !checkboxes.valid) {
141
+ if (fields.some((field) => !field.valid) || !validCheckboxes) {
164
142
  return null;
165
143
  }
166
144
 
@@ -169,17 +147,15 @@ export default class DeSignupForm extends LightningElement {
169
147
  userData[field.name] = field.value;
170
148
  });
171
149
 
172
- (userData as UserData).consent = this.country.showMarketingCheckbox
150
+ (userData as UserData).consent = this.showMarketingCheckbox
173
151
  ? "Explicit"
174
- : "Implied ";
152
+ : "Implied";
175
153
  const InfoEmail =
176
- this.country.showMarketingCheckbox && !checkboxes.values.opt_in
154
+ this.showMarketingCheckbox && !this.marketingCheckbox
177
155
  ? "False"
178
156
  : "True";
179
-
180
157
  const formData: SignupForm = {
181
158
  user: userData as UserData,
182
- eula: checkboxes.values.eula,
183
159
  default_driver: DEFAULT_DRIVER,
184
160
  info_email: InfoEmail
185
161
  };
@@ -187,24 +163,75 @@ export default class DeSignupForm extends LightningElement {
187
163
  return formData;
188
164
  }
189
165
 
190
- private getCheckboxesResult(): {
191
- valid: boolean;
192
- values: { eula: string; opt_in: "true" | "false" };
193
- } {
194
- let valid = true;
195
- const values: { eula: string; opt_in: "true" | "false" } = {
196
- eula: "",
197
- opt_in: "false"
198
- };
166
+ handleConsent(countrySelectElement: any) {
167
+ this.country = countrySelectElement.target.value;
168
+ countrySelectElement = countrySelectElement.target;
169
+ const countryOptions = countrySelectElement.options.find(
170
+ (option: any) => option.value === countrySelectElement.value
171
+ );
172
+ this.setLegalAndMarketingData(countryOptions);
173
+ this.marketingCheckbox = false;
174
+ }
199
175
 
200
- Array.from(
201
- this.template.querySelectorAll<HTMLInputElement>("dx-checkbox")
202
- ).forEach((checkbox) => {
203
- valid = valid && checkbox.reportValidity();
204
- values[checkbox.name] = checkbox.checked;
205
- });
176
+ handleMarketingCheckbox(marketingCheckbox: any) {
177
+ this.marketingCheckbox = marketingCheckbox.target.checked;
178
+ }
206
179
 
207
- return { valid, values };
180
+ setLegalAndMarketingData(countryOptions: CountryOptions) {
181
+ // Set the checkbox text
182
+ this.setCheckboxTextSet(
183
+ countryOptions.marketingText,
184
+ countryOptions.learnMore
185
+ ? `${countryOptions.legalText} </br> ${countryOptions.learnMore}`
186
+ : countryOptions.legalText
187
+ );
188
+
189
+ // Toggle visibility of legal/marketing data
190
+ this.toggleLegalAndMarketingVisibility(
191
+ countryOptions.showMarketingText,
192
+ countryOptions.showLegalCheckbox
193
+ );
194
+ }
195
+
196
+ setCheckboxTextSet(marketingText: string, privacyText: string) {
197
+ this.marketingText = marketingText;
198
+ this.privacyText = privacyText;
199
+ }
200
+
201
+ toggleLegalAndMarketingVisibility(
202
+ showMarketingCheckbox: boolean,
203
+ showLegalCheckbox: boolean
204
+ ) {
205
+ this.showMarketingCheckbox = showMarketingCheckbox;
206
+ this.showLegalCheckbox = showLegalCheckbox;
207
+ }
208
+
209
+ setInnerHtml(element: HTMLElement, value: string) {
210
+ // disable lwc warning because text received from json has HTML
211
+ // eslint-disable-next-line @lwc/lwc/no-inner-html
212
+ element.innerHTML = value;
213
+ }
214
+
215
+ async getCountryList() {
216
+ if (!this.drmDomain) {
217
+ return;
218
+ }
219
+ const errorMsg = "Error while getting county list";
220
+ try {
221
+ const res = await fetch(
222
+ `${this.drmDomain}/utilities/services/apexrest/countries`
223
+ );
224
+
225
+ if (!res.ok) {
226
+ throw new Error(errorMsg);
227
+ }
228
+
229
+ const data = await res.json();
230
+ // eslint-disable-next-line @lwc/lwc/no-api-reassignments
231
+ this.countries = JSON.stringify(data);
232
+ } catch (error) {
233
+ console.error(error);
234
+ }
208
235
  }
209
236
 
210
237
  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
  };
package/LICENSE DELETED
@@ -1,12 +0,0 @@
1
- Copyright (c) 2020, Salesforce.com, Inc.
2
- All rights reserved.
3
-
4
- Redistribution and use in source and binary forms, with or without modification, are permitted provided that the following conditions are met:
5
-
6
- * Redistributions of source code must retain the above copyright notice, this list of conditions and the following disclaimer.
7
-
8
- * Redistributions in binary form must reproduce the above copyright notice, this list of conditions and the following disclaimer in the documentation and/or other materials provided with the distribution.
9
-
10
- * Neither the name of Salesforce.com nor the names of its contributors may be used to endorse or promote products derived from this software without specific prior written permission.
11
-
12
- THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.