-
Notifications
You must be signed in to change notification settings - Fork 0
/
contactform.jsx
232 lines (216 loc) · 6.92 KB
/
contactform.jsx
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
228
229
230
231
232
import {
Button,
Card,
CardContent,
Grid,
TextField,
Typography,
} from "@mui/material";
import "../../styling/contact/contactform.css";
import { useState } from "react";
import axios from "axios";
import React, { useRef } from "react";
import emailjs from "@emailjs/browser";
import FormDialog from "../formdialog";
function ContactForm() {
/*States for the form fields*/
const [firstName, setFirstName] = useState("");
const [lastName, setLastName] = useState("");
const [email, setEmail] = useState("");
const [phoneNumber, setPhoneNumber] = useState("");
const [subject, setSubject] = useState("");
const [message, setMessage] = useState("");
/*Honeypot*/
const [name, setName] = useState(false);
/*Dialog*/
const [open, setOpen] = useState(false);
// Obtain sheetbest contact link
var SHEETBEST_CONTACT_LINK;
axios
.get(`${process.env.REACT_APP_API_URL}/form/sheetbest/contact`)
.then((response) => {
SHEETBEST_CONTACT_LINK = response.data;
});
/*Send data to spreadsheet*/
const onSubmit = () => {
axios.post(SHEETBEST_CONTACT_LINK, {
firstName,
lastName,
email,
phoneNumber,
subject,
message,
});
setOpen(true);
};
// Obtain EmailJs form data
var EmailJS_SERVICE_ID;
var EmailJS_PUBLIC_KEY;
axios
.get(`${process.env.REACT_APP_API_URL}/form/forminfo`)
.then((response) => {
EmailJS_SERVICE_ID = response.data.SERVICE_ID;
EmailJS_PUBLIC_KEY = response.data.PUBLIC_KEY;
});
// Obtain EmailJS registration template ID
var EmailJS_CONTACT_TEMPLATE_ID;
axios
.get(`${process.env.REACT_APP_API_URL}/form/emailjs/contact`)
.then((response) => {
EmailJS_CONTACT_TEMPLATE_ID = response.data;
});
/*Send data to email*/
const form = useRef();
const sendEmail = (e) => {
if (!name) {
e.preventDefault();
emailjs
.sendForm(
EmailJS_SERVICE_ID,
EmailJS_CONTACT_TEMPLATE_ID,
form.current,
EmailJS_PUBLIC_KEY
)
.then((result) => {
e.target.reset();
});
onSubmit();
}
};
return (
<>
{open && (
<FormDialog
open={open}
closeDialog={setOpen}
title="Thank you for Contacting Infokidz!"
description="We'll be in touch with you shortly"
/>
)}
<div id="contactform">
<h2 id="contactform-title">We'd love to answer your questions!</h2>
{/*Form*/}
<Card>
<CardContent>
<Typography id="contactform-title2">
{" "}
Contact us through a{" "}
<a href="tel:780-966-7700" id="contactform-link">
phone call
</a>{" "}
or by filling out this form:
</Typography>
<form ref={form} onSubmit={sendEmail}>
<TextField
label="name"
variant="outlined"
size="normal"
fullWidth
style={{
display: "none",
visibility: "hidden",
}}
name="name"
onChange={() => setName(true)}
/>
<Grid
container
spacing={1}
alignItems="center"
justifyContent="center"
>
<Grid item xs={12} sm={6}>
<TextField
label="First Name"
name="firstName"
variant="outlined"
size="normal"
fullWidth
required
inputProps={{ style: { fontSize: 24 }, maxLength: 30 }} // font size of input text and max-length of input
InputLabelProps={{ style: { fontSize: 24 } }} // font size of input label
onChange={(e) => setFirstName(e.target.value)}
/>
</Grid>
<Grid item xs={12} sm={6}>
<TextField
label="Last Name"
name="lastName"
variant="outlined"
fullWidth
required
inputProps={{ style: { fontSize: 24 }, maxLength: 30 }}
InputLabelProps={{ style: { fontSize: 24 } }}
onChange={(e) => setLastName(e.target.value)}
/>
</Grid>
<Grid item xs={12} sm={6}>
<TextField
type="email"
name="email"
label="Email"
variant="outlined"
fullWidth
required
inputProps={{ style: { fontSize: 24 }, maxLength: 50 }}
InputLabelProps={{ style: { fontSize: 24 } }}
onChange={(e) => setEmail(e.target.value)}
/>
</Grid>
<Grid item xs={12} sm={6}>
<TextField
type="number"
name="phoneNumber"
label="Phone Number"
variant="outlined"
fullWidth
inputProps={{ style: { fontSize: 24 } }}
InputLabelProps={{ style: { fontSize: 24 } }}
onChange={(e) => setPhoneNumber(e.target.value)}
/>
</Grid>
<Grid item xs={12}>
<TextField
label="Subject"
name="subject"
variant="outlined"
fullWidth
required
inputProps={{ style: { fontSize: 24 }, maxLength: 120 }}
InputLabelProps={{ style: { fontSize: 24 } }}
onChange={(e) => setSubject(e.target.value)}
/>
</Grid>
<Grid item xs={12}>
<TextField
label="Message"
name="message"
placeholder="Please type your message here"
variant="outlined"
fullWidth
multiline
rows={5}
inputProps={{ style: { fontSize: 24 }, maxLength: 1200 }}
InputLabelProps={{ style: { fontSize: 24 } }}
onChange={(e) => setMessage(e.target.value)}
/>
</Grid>
<Grid item xs={6} sm={3} md={2}>
<Button
type="submit"
variant="contained"
id="contactform-submit"
fullWidth
>
Submit
</Button>
</Grid>
</Grid>
</form>
</CardContent>
</Card>
</div>
</>
);
}
export default ContactForm;