-
Notifications
You must be signed in to change notification settings - Fork 2
/
Copy pathSubscribeCTA.js
114 lines (106 loc) · 3.08 KB
/
SubscribeCTA.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
import { React, useState } from 'react';
import { useFormik } from 'formik';
import * as yup from 'yup';
import Button from '@mui/material/Button';
import Box from '@mui/material/Box';
import TextField from '@mui/material/TextField';
import Typography from '@mui/material/Typography';
import { useTheme } from '@mui/material/styles';
import TransitionsModal from './TransitionModal';
export default function SubscribeCTA({
text = 'Join thousands of others for our newsletter',
}) {
const theme = useTheme();
const [open, setOpen] = useState(false);
const validationSchema = yup.object({
email: yup
.string('Enter your email')
.email('Enter a valid email')
.required('Email is required'),
});
const formik = useFormik({
initialValues: {
email: '',
},
validationSchema: validationSchema,
onSubmit: () => {},
});
const handleModal = () => {
if (formik.values.email !== '' && formik.isValid) {
if (formik.values.email !== '' && formik.isValid) {
fetch(
'https://us-central1-zesty-dev.cloudfunctions.net/zohoEmailSubscribe?email=' +
formik.values.email,
{
method: 'GET',
},
)
.then((res) => res.json())
.then(() => {
dataLayer.push({ event: 'emailSubscribeSubmitted', value: '1' });
// eslint-disable-next-line no-undef
acSENT = true;
});
}
setOpen(!open);
}
};
return (
<Box display="flex" flexDirection={'column'} justifyContent={'center'}>
<TransitionsModal
open={open}
setOpen={setOpen}
title="Thank you for subscribing!"
message="Check your email to confirm."
/>
<Box marginBottom={2}>
<Typography variant="body1" component="p">
{text}
</Typography>
</Box>
<Box
onSubmit={formik.handleSubmit}
component={'form'}
noValidate
autoComplete="off"
sx={{
'& .MuiInputBase-input.MuiOutlinedInput-input': {
bgcolor: 'background.paper',
},
}}
>
<Box
display="flex"
flexDirection={{ xs: 'column', sm: 'row' }}
alignItems={{ xs: 'stretched', sm: 'flex-start' }}
>
<TextField
fullWidth
id="email"
name="email"
label="Email"
value={formik.values.email}
onChange={formik.handleChange}
error={formik.touched.email && Boolean(formik.errors.email)}
helperText={formik.touched.email && formik.errors.email}
/>
<Box
component={Button}
variant="contained"
color="primary"
backgroundColor={theme.palette.secondary.main}
size="large"
height={54}
className="subscribeButton"
marginTop={{ xs: 2, sm: 0 }}
marginLeft={{ sm: 2 }}
type="submit"
onClick={handleModal}
>
Subscribe
</Box>
</Box>
</Box>
</Box>
);
}