-
Notifications
You must be signed in to change notification settings - Fork 3
/
Copy pathStandardFormWithSelect.js
227 lines (209 loc) · 6.3 KB
/
StandardFormWithSelect.js
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
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
/* eslint-disable no-undef */
/* eslint-disable react/no-unescaped-entities */
import React, { useState } from 'react';
import Box from '@mui/material/Box';
import { Form, Formik } from 'formik';
import TransitionsModal from './TransitionModal';
import { getCookie } from 'cookies-next';
import { Stack } from '@mui/material';
import { validationSchema } from 'revamp/utils/validation';
import getLastVisitedPathAndUrl from 'revamp/utils/getLastVisitedPathAndUrl';
import { MultiFieldForm } from 'revamp/ui/GetDemoSection/MultiFieldForm';
/**
* Possible field option in ZOHO https://crm.zoho.com/crm/org749642405/settings/api/modules/Leads?step=FieldsList
* Note, if a custom field need to be added speak to todd.sabo@zesty.io
* For testing new changes, please work with katie.moser@zesty.io
*/
/* validation for form component */
const getLeadObjectZOHO = (
obj,
select,
leadDetail,
businessType,
leadSource = 'Website',
lastVisitedPath,
lastVisitedURL,
) => {
// let acLeadtype = 'Marketing Website';
let acRole = 'Marketer';
// possible values
// "Phone": '+'+country.value + ' ' + document.querySelector('#ac-phone input').value,
// "Current_CMS": acCMS,
// "How_Using_Zesty_io": acHow,
// "Website": document.querySelector('#ac-url').value,
// 'Project_Timeline' : document.querySelector('#ac-timeline').value,
// zoho and google click id https://help.zoho.com/portal/en/kb/crm/integrations/google/google-ads/articles/configure-google-ads-crm-integration#Step_2_Add_hidden_element_in_your_web_forms
return {
First_Name: obj.firstName,
Last_Name: obj.lastName,
Email: obj.businessEmail || obj.email,
Phone: obj.phoneNumber,
Mobile: obj.mobile,
Company_Phone: obj.hqPhone,
Inquiry_Reason: select,
Description: obj.message,
Zesty_User_Account: obj?.user && obj.user ? true : false,
newsletter_signup: obj.newsletter_signup,
Lead_Source: getCookie('utm_source') ? getCookie('utm_source') : leadSource,
Role: getCookie('persona') ? getCookie('persona') : acRole,
Captured_URL:
window.location.href.match(/localhost/gi) == null
? window.location.href
: 'https://www.testcapurl.com',
UTM_Campaign: getCookie('utm_campaign')
? getCookie('utm_campaign')
: 'unknown',
UTM_Source: getCookie('utm_source') ? getCookie('utm_source') : 'unknown',
UTM_Term: getCookie('utm_term') ? getCookie('utm_term') : 'unknown',
UTM_Medium: getCookie('utm_medium') ? getCookie('utm_medium') : 'unknown',
$gclid: getCookie('gclid') ? getCookie('gclid') : '',
Lead_Source_Detail: getCookie('utm_medium')
? getCookie('utm_medium')
: leadDetail,
Lead_Source_Topic: getCookie('utm_campaign')
? getCookie('utm_campaign')
: 'none',
Business_Type: businessType,
Lead_Status: 'Not Contacted',
Designation: obj.jobTitle,
Company: obj.company,
LinkedIn_Profile: obj.linkedIn,
Last_Visited_Path: lastVisitedPath,
Last_Visited_URL: lastVisitedURL,
Entry_Path: getCookie('entry_path') ? getCookie('entry_path') : '',
};
};
const postToZOHO = async (payloadJSON) => {
fetch('https://us-central1-zesty-prod.cloudfunctions.net/zoho', {
method: 'POST',
body: JSON.stringify(payloadJSON),
headers: {
'Content-Type': 'application/json',
},
})
.then((res) => res.json())
.then(() => {
// google data
dataLayer.push({ event: 'formCaptureSuccess', value: '1' });
})
.catch((error) => {
throw new Error(`HTTP error: ${error}`);
});
};
const subscribeToZoho = async (payload) => {
const { Email, First_Name, Last_Name } = payload;
await fetch(
`https://us-central1-zesty-dev.cloudfunctions.net/zohoEmailSubscribe?email=${Email}&name=${First_Name}_${Last_Name}`,
{
method: 'GET',
},
)
.then((res) => res.json())
.then(() => {
dataLayer.push({ event: 'emailSubscribeSubmitted', value: '1' });
acSENT = true;
});
};
function StandardFormWithSelect({
modalTitle = 'Thank you',
modalMessage = 'Have a great day.',
cmsModel,
}) {
const [open, setOpen] = useState(false);
const { lastVisitedPath, lastVisitedURL } = getLastVisitedPathAndUrl();
let inquiryReasons = [
'General',
'Agency Sign Up',
'Request a Demo',
'Support',
'Billing',
'Press Relations',
];
const initialValues = {
firstName: '',
lastName: '',
email: '',
message: '',
company: '',
jobTitle: '',
businessEmail: '',
linkedIn: '',
phoneNumber: '',
newsletter_signup: false,
};
const onSubmit = async (values) => {
if (values.firstName === '') {
values.firstName = 'Unknown';
}
if (values.lastName === '') {
values.lastName = 'N/A in Zoominfo';
}
let payload = await getLeadObjectZOHO(
values,
'',
'Get a Talk to Us',
'',
'website', // leadsource
lastVisitedPath,
lastVisitedURL,
);
// post to leads section
await postToZOHO(payload);
//post to email marketing signup
if (payload.newsletter_signup) {
await subscribeToZoho(payload);
}
cmsModel === 'Gated Content Page'
? setOpen(true)
: (window.location = '/meet/');
return values;
};
return (
<Box>
<Formik
enableReinitialize
initialValues={initialValues}
validationSchema={validationSchema}
onSubmit={async (values) => {
await onSubmit(values);
}}
>
{({
handleSubmit,
getFieldProps,
errors,
touched,
initialValues,
isSubmitting,
setFieldValue,
values,
}) => (
<Form id="site-form" onSubmit={handleSubmit}>
<Stack sx={{ mt: 4 }}>
<MultiFieldForm
{...{
handleSubmit,
getFieldProps,
errors,
touched,
initialValues,
isSubmitting,
setFieldValue,
values,
inquiryReasons,
}}
/>
</Stack>
</Form>
)}
</Formik>
<TransitionsModal
title={modalTitle}
message={modalMessage}
open={open}
setOpen={setOpen}
/>
</Box>
);
}
export default StandardFormWithSelect;