-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathhubspot-contact-form.tsx
96 lines (87 loc) · 3.08 KB
/
hubspot-contact-form.tsx
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
"use client";
import React, { useEffect, useState } from "react";
import "~/styles/form.css";
// import { analytics } from "lib/segment";
// import { useRouter } from "next/navigation";
declare global {
interface Window {
lintrk: any;
}
}
const HubspotContactForm = ({
region,
portalId,
formId,
// segmentMsg = "AGNTCY supporter details submitted",
}: { portalId: string; formId: string; region: string; }) => {
// const router = useRouter();
const [loading, setLoading] = useState(true);
useEffect(() => {
const element = document.getElementsByClassName("hsfc-FieldLabel");
if(element)
{
setLoading(false);
}
},[])
useEffect(() => {
const script = document.createElement("script");
script.src = "https://js.hsforms.net/forms/embed/v2.js";
document.body.appendChild(script);
script.addEventListener("load", () => {
// @ts-expect-error: Third-party library
if (window.hbspt) {
// @ts-expect-error: Third-party library
window.hbspt.forms.create({
target: `#hubspotForm-${formId}`,
// onFormSubmit: () => {
// if (conversion_id) {
// window.lintrk("track", { conversion_id: conversion_id });
// }
// },
// onFormSubmitted: (_, data) => {
// if formId is 7f3330bd-39c5-4358-b56d-44b90ae62e8e, redirect to thank you page
// if (formId == "7f3330bd-39c5-4358-b56d-44b90ae62e8e") {
// router.push("/outshift-newsletter-thank-you");
// }
// const submissionValues = data.submissionValues;
// Segment Identify Call
// analytics.identify({
// firstname: submissionValues.firstname,
// lastname: submissionValues.lastname,
// email: submissionValues.email,
// jobtitle: submissionValues.jobtitle,
// agreed_to_pii:
// submissionValues.consent_marketing_emails_and_privacy_policy,
// });
// Segment Track Call
// analytics.track(segmentMsg, {
// firstname: submissionValues.firstname,
// lastname: submissionValues.lastname,
// email: submissionValues.email,
// jobtitle: submissionValues.jobtitle,
// agreed_to_pii:
// submissionValues.consent_marketing_emails_and_privacy_policy,
// });
// },
...{ region: region, portalId: portalId, formId: formId },
});
}
setTimeout(() => {
const formElement = document.querySelector(`#hubspotForm-${formId}`);
if (formElement) {
// Remove invalid role attributes
const invalidRoles =
formElement.querySelectorAll('[role="checkbox"]');
invalidRoles.forEach((el) => el.removeAttribute("role"));
}
}, 500);
});
}, [region, portalId, formId]);
return (
<div>
{loading && <div className="loader">Loading form...</div>}
<div id={`hubspotForm-${formId}`}></div>
</div>
);
};
export default HubspotContactForm;