@salesforcedevs/dw-components 1.3.148-canary.6 → 1.3.148-canary.8

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.148-canary.6",
3
+ "version": "1.3.148-canary.8",
4
4
  "description": "Lightning web components for https://developer.salesforce.com",
5
5
  "license": "MIT",
6
6
  "engines": {
@@ -213,8 +213,8 @@ export default class J2sCardSequence extends LightningElement {
213
213
  }
214
214
  }
215
215
 
216
- handleFormSubmit(evt: Event) {
217
- if (!this.formHandler || this.isJ2sFormInvalid) {
216
+ async handleFormSubmit(evt: Event) {
217
+ if (!this.formHandler || this.isJ2sFormInvalid || !this.isLoggedIn) {
218
218
  return;
219
219
  }
220
220
 
@@ -231,10 +231,33 @@ export default class J2sCardSequence extends LightningElement {
231
231
  if (typeof formData.Privacy_Statement__c !== "boolean") {
232
232
  formData.Privacy_Statement__c = true;
233
233
  }
234
- console.log("would submit", JSON.stringify(formData, null, 2));
235
- this.jumpToStepIndex(2);
234
+
235
+ console.log("submitting", JSON.stringify(formData, null, 2));
236
+ const res = await fetch(this.formHandler, {
237
+ method: "POST",
238
+ headers: {
239
+ "Captcha-Response": this.recaptchaToken,
240
+ "Content-Type": "application/json"
241
+ },
242
+ body: JSON.stringify({
243
+ ...formData,
244
+ handlerName: "J2S Registration Page",
245
+ TBID__c: this.tbidUserInfo.user_id
246
+ })
247
+ });
248
+
249
+ if (res.ok) {
250
+ const resData = await res.json();
251
+ if (resData.status === "success") {
252
+ this.jumpToStepIndex(2);
253
+ } else {
254
+ throw new Error(
255
+ `Form submission failed. (status: ${resData.status}, message: ${resData.errorMessage})`
256
+ );
257
+ }
258
+ }
236
259
  } catch (ex) {
237
- console.log(ex); // TODO
260
+ console.error(ex); // TODO
238
261
  }
239
262
 
240
263
  this._isFormSubmitting = false;
@@ -80,13 +80,15 @@ export default class J2sForm extends LightningElementWithState<J2sFormState> {
80
80
  // but our custom form elements don't seem to implement what it is required for that currently. See:
81
81
  // https://web.dev/more-capable-form-controls/#defining-a-form-associated-custom-element
82
82
  const formData: any = {};
83
- this.template.querySelectorAll("[name]").forEach((namedElement) => {
84
- const typedElement = namedElement as HTMLInputElement;
85
- formData[typedElement.name] =
86
- typeof typedElement.checked === "boolean"
87
- ? typedElement.checked
88
- : typedElement.value;
89
- });
83
+ this.template
84
+ .querySelectorAll("form [name]")
85
+ .forEach((namedElement) => {
86
+ const typedElement = namedElement as HTMLInputElement;
87
+ formData[typedElement.name] =
88
+ typeof typedElement.checked === "boolean"
89
+ ? typedElement.checked
90
+ : typedElement.value;
91
+ });
90
92
  return formData;
91
93
  }
92
94