@salesforcedevs/dw-components 1.3.89 → 1.3.93

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.89",
3
+ "version": "1.3.93",
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": "5ba430f4d6dd77bdd18336628015be892cc42e38"
27
+ "gitHead": "407d14fa2e92a0c1dadf1cf109df999537f4475d"
28
28
  }
@@ -51,16 +51,30 @@
51
51
  value={country}
52
52
  required="true"
53
53
  ></dx-select>
54
- <template if:true={checkboxTextSet}>
54
+
55
+ <template if:false={showMarketingText}>
55
56
  <p class="marketing-text">{marketingText}</p>
56
- <p class="legal-text" lwc:dom="manual"></p>
57
- <template if:true={showLegalCheckbox}>
58
- <dx-checkbox
59
- class="legal-checkbox"
60
- value={legalText}
61
- required="true"
62
- ></dx-checkbox>
63
- </template>
57
+ </template>
58
+ <template if:true={showMarketingText}>
59
+ <dx-checkbox
60
+ name="marketingCheckbox"
61
+ class="marketing-checkbox"
62
+ value="false"
63
+ onchange={handleChange}
64
+ >
65
+ <span>{marketingText}</span>
66
+ </dx-checkbox>
67
+ </template>
68
+
69
+ <template if:false={showLegalCheckbox}>
70
+ <p lwc:dom="manual" class="legal-checkbox legal-text"></p>
71
+ </template>
72
+ <template if:true={showLegalCheckbox}>
73
+ <dx-checkbox
74
+ class="legal-checkbox"
75
+ value={legalCheckbox}
76
+ required="true"
77
+ ></dx-checkbox>
64
78
  </template>
65
79
  <button class="form-submit" type="submit">Subscribe Now</button>
66
80
  </form>
@@ -1,6 +1,6 @@
1
1
  import { LightningElement, api } from "lwc";
2
2
  import { track } from "dxUtils/analytics";
3
- import { CountryOptions, CheckboxTextSet } from "typings/custom";
3
+ import { CountryOptions } from "typings/custom";
4
4
 
5
5
  const LOCAL_STORAGE_KEY = "subscriberEmail";
6
6
 
@@ -12,30 +12,32 @@ export default class Form extends LightningElement {
12
12
  private lastName: string = "";
13
13
  private email: string = "";
14
14
  private country: string = "";
15
+ private marketingCheckbox: string = "";
15
16
 
16
- private showLegalText: boolean = false;
17
+ private showLegalText: boolean = false; // This should be always true
18
+ private showMarketingText: boolean = false;
17
19
  private showLegalCheckbox: boolean = false;
18
20
  private legalText: string = "";
19
21
  private marketingText: string | null = null;
20
22
  private hasRendered: boolean = false;
21
23
 
24
+ connectedCallback() {
25
+ this.getCountryList();
26
+ }
27
+
22
28
  renderedCallback() {
23
29
  if (!this.hasRendered) {
24
30
  // Focus the first input in the form
25
31
  this.template.querySelector("dx-input")?.focus();
26
-
27
32
  this.setInitialEmail();
28
33
  this.hasRendered = true;
29
- } else if (this.hasRendered && this.showLegalCheckbox) {
34
+ } else if (this.hasRendered) {
30
35
  // Grab the legal checkbox and append the legal text as innerHTML (text has anchor links in it)
31
- const legalCheckboxElement = this.template.querySelector(
32
- "dx-checkbox.legal-checkbox"
33
- );
34
- const legalCheckboxSpan = document.createElement("span");
35
- this.setInnerHtml(legalCheckboxSpan, this.legalText);
36
+ const legalCheckboxElement =
37
+ this.template.querySelector(".legal-checkbox");
36
38
 
37
39
  if (legalCheckboxElement) {
38
- legalCheckboxElement.appendChild(legalCheckboxSpan);
40
+ this.setInnerHtml(legalCheckboxElement, this.legalText);
39
41
  }
40
42
  }
41
43
  }
@@ -61,6 +63,9 @@ export default class Form extends LightningElement {
61
63
  this.country = e.target.value;
62
64
  this.handleConsent(e.target);
63
65
  break;
66
+ case "marketingCheckbox":
67
+ this.marketingCheckbox = e.target.checked;
68
+ break;
64
69
  default:
65
70
  break;
66
71
  }
@@ -92,6 +97,31 @@ export default class Form extends LightningElement {
92
97
  this.sendFormData();
93
98
  }
94
99
  }
100
+ async getCountryList() {
101
+ const errorMsg = "Error while getting county list";
102
+
103
+ try {
104
+ const res = await fetch(
105
+ "https://drm.my.salesforce-sites.com/utilities/services/apexrest/countries",
106
+ {
107
+ method: "GET",
108
+ headers: {
109
+ "Content-Type": "application/json"
110
+ }
111
+ }
112
+ );
113
+
114
+ if (!res.ok) {
115
+ throw new Error(errorMsg);
116
+ }
117
+
118
+ const data = await res.json();
119
+ // eslint-disable-next-line @lwc/lwc/no-api-reassignments
120
+ this.countries = JSON.stringify(data);
121
+ } catch (error) {
122
+ console.error(error);
123
+ }
124
+ }
95
125
 
96
126
  setInitialEmail() {
97
127
  // Set email if provided in the local storage
@@ -104,17 +134,19 @@ export default class Form extends LightningElement {
104
134
 
105
135
  getFormData() {
106
136
  const date = new Date().toISOString();
107
-
108
137
  return {
109
- InfoEmail: true,
110
- "First Name": this.firstName,
111
- "Last Name": this.lastName,
112
- Consent: "Implied",
113
- "Email Status Update": date,
114
- email: this.email,
115
- Country: this.country,
116
- "Privacy Policy": true,
117
- referrer: "footer"
138
+ InfoEmail__c:
139
+ (this.showMarketingText && this.marketingCheckbox) ||
140
+ !this.showMarketingText
141
+ ? "True"
142
+ : "False", // True if the user checks the checkbox or the country is opted-out
143
+ FirstName: this.firstName,
144
+ LastName: this.lastName,
145
+ Consent__c: this.showMarketingText ? "Explicit" : "Implied", //Implied if the country is opted-out, Explicit if the country is opted-in
146
+ Email_Status_Update__c: date,
147
+ Email: this.email,
148
+ MailingCountry: this.country,
149
+ handlerName: "news_letter_form_handler"
118
150
  };
119
151
  }
120
152
 
@@ -129,13 +161,16 @@ export default class Form extends LightningElement {
129
161
  submitButtonEl.textContent = "...Processing request";
130
162
 
131
163
  try {
132
- const res = await fetch("/pages/pardot/footer_optin", {
133
- method: "POST",
134
- headers: {
135
- "Content-Type": "application/json"
136
- },
137
- body: JSON.stringify(formData)
138
- });
164
+ const res = await fetch(
165
+ "https://drm.my.salesforce-sites.com/handler/services/apexrest/handler",
166
+ {
167
+ method: "POST",
168
+ headers: {
169
+ "Content-Type": "application/json"
170
+ },
171
+ body: JSON.stringify(formData)
172
+ }
173
+ );
139
174
 
140
175
  if (!res.ok) {
141
176
  throw new Error(errorMsg);
@@ -143,7 +178,7 @@ export default class Form extends LightningElement {
143
178
 
144
179
  const data = await res.json();
145
180
 
146
- if (!data.success) {
181
+ if (data.status !== "success") {
147
182
  throw new Error(errorMsg);
148
183
  }
149
184
 
@@ -178,54 +213,37 @@ export default class Form extends LightningElement {
178
213
  }
179
214
 
180
215
  handleConsent(countrySelectElement: any) {
181
- if (this.checkboxTextSet) {
182
- const countryOptions = countrySelectElement.options.find(
183
- (option: any) => option.value === countrySelectElement.value
184
- );
216
+ const countryOptions = countrySelectElement.options.find(
217
+ (option: any) => option.value === countrySelectElement.value
218
+ );
185
219
 
186
- this.setLegalAndMarketingData(countryOptions);
187
- }
220
+ this.setLegalAndMarketingData(countryOptions);
188
221
  }
189
222
 
190
223
  setLegalAndMarketingData(countryOptions: CountryOptions) {
191
- // Parse the text sets for the checkbox info
192
- const parsedCheckboxTextSet = JSON.parse(this.checkboxTextSet);
193
-
194
- // Check for alternate text set or set to default
195
- const checkboxTextSet = countryOptions.checkboxTextSet
196
- ? parsedCheckboxTextSet[countryOptions.checkboxTextSet]
197
- : parsedCheckboxTextSet.default;
198
-
199
224
  // Set the checkbox text
200
- this.setCheckboxTextSet(checkboxTextSet);
225
+ this.setCheckboxTextSet(
226
+ countryOptions.marketingText,
227
+ countryOptions.legalText
228
+ );
201
229
 
202
230
  // Toggle visibility of legal/marketing data
203
231
  this.toggleLegalAndMarketingVisibility(
204
- countryOptions.showLegalText,
232
+ countryOptions.showMarketingText,
205
233
  countryOptions.showLegalCheckbox
206
234
  );
207
-
208
- // Grab the legal text paragraph element and set inner html (this is due to text having html elements in the string)
209
- const legalTextElement = this.template.querySelector(".legal-text");
210
-
211
- if (legalTextElement && this.showLegalText) {
212
- this.setInnerHtml(legalTextElement, this.legalText);
213
- } else if (legalTextElement && !this.showLegalText) {
214
- // Clear legal text
215
- this.setInnerHtml(legalTextElement, "");
216
- }
217
235
  }
218
236
 
219
- setCheckboxTextSet(checkboxTextSet: CheckboxTextSet) {
220
- this.legalText = checkboxTextSet.legalText;
221
- this.marketingText = checkboxTextSet.marketingText;
237
+ setCheckboxTextSet(marketingText: string, legalText: string) {
238
+ this.legalText = legalText;
239
+ this.marketingText = marketingText;
222
240
  }
223
241
 
224
242
  toggleLegalAndMarketingVisibility(
225
- showLegalText: boolean,
243
+ showMarketingText: boolean,
226
244
  showLegalCheckbox: boolean
227
245
  ) {
228
- this.showLegalText = showLegalText;
246
+ this.showMarketingText = showMarketingText;
229
247
  this.showLegalCheckbox = showLegalCheckbox;
230
248
  }
231
249