@meetelise/chat 1.20.66 → 1.20.68
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 +1 -1
- package/public/dist/index.js +11 -11
- package/src/WebComponent/me-chat.ts +152 -1
|
@@ -161,6 +161,16 @@ export class MEChat extends LitElement {
|
|
|
161
161
|
await this.initializeLaunchJS();
|
|
162
162
|
this.attachOnClickToLauncher();
|
|
163
163
|
this.isLoading = false;
|
|
164
|
+
if (localStorage.getItem("overrideContactUsForm") === "true") {
|
|
165
|
+
this
|
|
166
|
+
.overrideContactUsForm
|
|
167
|
+
// {
|
|
168
|
+
// orgSlug: this.orgSlug,
|
|
169
|
+
// buildingSlug: this.buildingSlug,
|
|
170
|
+
// buildingId: this.building?.id ?? null,
|
|
171
|
+
// }
|
|
172
|
+
();
|
|
173
|
+
}
|
|
164
174
|
};
|
|
165
175
|
|
|
166
176
|
setBuildingDerivedInfo = async (): Promise<void> => {
|
|
@@ -213,7 +223,7 @@ export class MEChat extends LitElement {
|
|
|
213
223
|
);
|
|
214
224
|
}
|
|
215
225
|
|
|
216
|
-
// if the building does NOT have IVR setup, we want to use the building's phone
|
|
226
|
+
// if the building does NOT have IVR setup, we want to use the building's phone numbr
|
|
217
227
|
if (!phoneNumberForSource) {
|
|
218
228
|
this.phoneNumberForSource = {
|
|
219
229
|
number: this.building.phoneNumber,
|
|
@@ -591,6 +601,147 @@ export class MEChat extends LitElement {
|
|
|
591
601
|
this.hasMounted = true;
|
|
592
602
|
};
|
|
593
603
|
};
|
|
604
|
+
|
|
605
|
+
private overrideContactUsForm = (): // {
|
|
606
|
+
// orgSlug,
|
|
607
|
+
// buildingSlug,
|
|
608
|
+
// buildingId,
|
|
609
|
+
// }: {
|
|
610
|
+
// orgSlug: MEChat["orgSlug"];
|
|
611
|
+
// buildingSlug: MEChat["buildingSlug"];
|
|
612
|
+
// buildingId: Building["id"] | null;
|
|
613
|
+
// }
|
|
614
|
+
void => {
|
|
615
|
+
const form = document.getElementById(
|
|
616
|
+
"myContactForm"
|
|
617
|
+
) as HTMLFormElement | null;
|
|
618
|
+
let btn = undefined;
|
|
619
|
+
if (!form || !(form instanceof HTMLFormElement)) {
|
|
620
|
+
// TODO: Add log
|
|
621
|
+
// return console.log("No Contact Us Form Found");
|
|
622
|
+
return;
|
|
623
|
+
}
|
|
624
|
+
|
|
625
|
+
// Loop through the elements of the form
|
|
626
|
+
for (let i = 0; i < form.elements.length; i++) {
|
|
627
|
+
const element = form.elements[i];
|
|
628
|
+
if (
|
|
629
|
+
element.tagName.toLowerCase() === "button" &&
|
|
630
|
+
element.getAttribute("data-selenium-id") === "fakebutton"
|
|
631
|
+
) {
|
|
632
|
+
btn = element;
|
|
633
|
+
break;
|
|
634
|
+
}
|
|
635
|
+
}
|
|
636
|
+
|
|
637
|
+
if (!btn) {
|
|
638
|
+
// TODO: Add log
|
|
639
|
+
// return console.log('No button with data-selenium-id="fakebutton" found');
|
|
640
|
+
return;
|
|
641
|
+
}
|
|
642
|
+
|
|
643
|
+
// Replace the original form element with the cloned one
|
|
644
|
+
const clonedButton = btn.cloneNode(true) as HTMLButtonElement;
|
|
645
|
+
btn.parentNode?.replaceChild(clonedButton, btn);
|
|
646
|
+
//TODO: Remove textContent after testing
|
|
647
|
+
clonedButton.textContent = "Elise Submit";
|
|
648
|
+
|
|
649
|
+
const eliseUrl =
|
|
650
|
+
"https://app.meetelise.com/platformApi/state/create/contactMe";
|
|
651
|
+
|
|
652
|
+
const getFormElements = () => {
|
|
653
|
+
const firstName = document.getElementById(
|
|
654
|
+
"firstname"
|
|
655
|
+
) as HTMLInputElement | null;
|
|
656
|
+
const lastName = document.getElementById(
|
|
657
|
+
"lastname"
|
|
658
|
+
) as HTMLInputElement | null;
|
|
659
|
+
const email = document.getElementById("email") as HTMLInputElement | null;
|
|
660
|
+
const phone = document.getElementById(
|
|
661
|
+
"phonenumber"
|
|
662
|
+
) as HTMLInputElement | null;
|
|
663
|
+
const message = document.getElementById(
|
|
664
|
+
"message"
|
|
665
|
+
) as HTMLTextAreaElement | null;
|
|
666
|
+
|
|
667
|
+
const formElements = { firstName, lastName, email, phone, message };
|
|
668
|
+
|
|
669
|
+
if (Object.values(formElements).some((el) => el === null)) {
|
|
670
|
+
// console.log("Form is missing elements");
|
|
671
|
+
// TODO: Add logger to log that form scraper is boken on el.name in current route or buildingId
|
|
672
|
+
}
|
|
673
|
+
|
|
674
|
+
return formElements;
|
|
675
|
+
};
|
|
676
|
+
const getFormValues = () => {
|
|
677
|
+
const formValues: { [key: string]: string | undefined } = {};
|
|
678
|
+
Object.entries(getFormElements()).forEach(
|
|
679
|
+
([key, val]) => (formValues[key] = val?.value)
|
|
680
|
+
);
|
|
681
|
+
return formValues;
|
|
682
|
+
};
|
|
683
|
+
|
|
684
|
+
const isValid = () => {
|
|
685
|
+
return Object.values(getFormElements()).every((el) => {
|
|
686
|
+
if (el === null) return false;
|
|
687
|
+
//TODO: May need to not depend on aria-invalid
|
|
688
|
+
return el.getAttribute("aria-invalid") !== "true";
|
|
689
|
+
});
|
|
690
|
+
};
|
|
691
|
+
|
|
692
|
+
clonedButton.onclick = function (event) {
|
|
693
|
+
if (!isValid()) return;
|
|
694
|
+
event.preventDefault();
|
|
695
|
+
const formValues = getFormValues();
|
|
696
|
+
|
|
697
|
+
const data = {
|
|
698
|
+
email_address: formValues.email,
|
|
699
|
+
first_name: formValues.firstName,
|
|
700
|
+
last_name: formValues.lastName,
|
|
701
|
+
phone_number: formValues.phone,
|
|
702
|
+
first_message: formValues.message,
|
|
703
|
+
|
|
704
|
+
//TODO: Replace after testing is done
|
|
705
|
+
building_id: 3660,
|
|
706
|
+
};
|
|
707
|
+
|
|
708
|
+
// Convert the data object to a JSON string
|
|
709
|
+
const jsonData = JSON.stringify(data);
|
|
710
|
+
|
|
711
|
+
fetch(eliseUrl, {
|
|
712
|
+
method: "POST",
|
|
713
|
+
headers: {
|
|
714
|
+
"Content-Type": "application/json",
|
|
715
|
+
"building-slug": "e2e-test-yardi-building",
|
|
716
|
+
"org-slug": "test-company",
|
|
717
|
+
//TODO: Replace org and building slugs
|
|
718
|
+
},
|
|
719
|
+
body: jsonData,
|
|
720
|
+
}).then((response) => {
|
|
721
|
+
// TODO: What's needed here?
|
|
722
|
+
// console.log(response);
|
|
723
|
+
// Check if the request was successful
|
|
724
|
+
if (!response.ok) {
|
|
725
|
+
throw new Error(`HTTP error ${response.status}`);
|
|
726
|
+
}
|
|
727
|
+
|
|
728
|
+
form.reset();
|
|
729
|
+
|
|
730
|
+
// Parse the response as JSON
|
|
731
|
+
return response.json();
|
|
732
|
+
});
|
|
733
|
+
// .then((responseData) => {
|
|
734
|
+
// // Handle the JSON response data
|
|
735
|
+
// // TODO: What's needed here?
|
|
736
|
+
// // console.log("Response data:", responseData);
|
|
737
|
+
// })
|
|
738
|
+
// .catch((error) => {
|
|
739
|
+
// // Handle any errors that occurred during the request
|
|
740
|
+
// // TODO: What's needed here?
|
|
741
|
+
// // console.error("Error:", error);
|
|
742
|
+
// });
|
|
743
|
+
};
|
|
744
|
+
};
|
|
594
745
|
}
|
|
595
746
|
|
|
596
747
|
declare global {
|