-
Notifications
You must be signed in to change notification settings - Fork 12
Expand file tree
/
Copy pathSubscribeButton.jsx
More file actions
105 lines (95 loc) · 4.62 KB
/
SubscribeButton.jsx
File metadata and controls
105 lines (95 loc) · 4.62 KB
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
import React, { Component } from 'react';
import ReCAPTCHA from "react-google-recaptcha";
import axios from 'axios';
class SubscribeButton extends Component {
constructor(props) {
super(props);
this.state = {
subscribed: false,
};
this._reCaptchaRef = React.createRef();
}
subscribeNewsletters = async (e) => {
e.preventDefault();
const CONTACT_LIST_API = 'https://staging.testsigma.com/api/website/contacts';
const email = document.getElementById('email').value;
const emailError = document.getElementById('email_error');
let trimmedURL = window.location.href;
if (trimmedURL.length > 250)
trimmedURL = window.location.href.substr(0, 240)+"...";
const regex = /^([a-zA-Z0-9_\.\-\+])+\@(([a-zA-Z0-9\-])+\.)+([a-zA-Z0-9]{2,4})+$/;
emailError.style.display = "none";
if (!regex.test(email)) {
emailError.style.display = "block";
return false;
} else {
this._reCaptchaRef.current.executeAsync().then(value => {
if (value) {
const formData = {
'CATEGORY': 'Product Updates',
'LSOURCE': 'Tutorials',
'UPDATES': '',
'URL': trimmedURL,
'add_tags_immediately': false,
'email': email,
'g-recaptcha-response': value,
'list_id' : 'bec00ef235',
'tags': ['Product Updates']
};
axios({
method: 'POST',
url: CONTACT_LIST_API,
data: formData,
headers: { "Content-Type": "application/json; charset=UTF-8" },
})
.then(function (response) {
// handle success
this.setState({ subscribed: true });
}.bind(this))
.catch(function (response) {
// handle error
console.error("Failed: ", response);
});
}
});
}
}
render() {
return (
<>
<div className="footer_greenbox">
<div className="flex_item">
<h4 className="green_text">
Stay up to date with product updates & news
</h4>
</div>
<div className={this.state.subscribed ? "hide" : "flex_item"}>
<form>
<svg width="20" height="15" viewBox="0 0 15 11" fill="none" xmlns="http://www.w3.org/2000/svg">
<path
d="M12.75 10.4829H1.41667C1.04094 10.4829 0.680609 10.3449 0.414933 10.0991C0.149256 9.85337 0 9.52008 0 9.17255V1.25336C0.0158898 0.915807 0.172132 0.596975 0.436106 0.36343C0.70008 0.129885 1.05138 -0.00031923 1.41667 5.87777e-07H12.75C13.1257 5.87777e-07 13.4861 0.138056 13.7518 0.383797C14.0174 0.629538 14.1667 0.962834 14.1667 1.31036V9.17255C14.1667 9.52008 14.0174 9.85337 13.7518 10.0991C13.4861 10.3449 13.1257 10.4829 12.75 10.4829ZM1.41667 2.53424V9.17255H12.75V2.53424L7.08334 6.02767L1.41667 2.53424ZM1.98334 1.31036L7.08334 4.45524L12.1834 1.31036H1.98334Z"
fill="#CACACA"/>
</svg>
<input type="text" id="email" name="email" placeholder="Your Email Id"/>
</form>
<p id="email_error" className="email-error">Please fill out this field.</p>
</div>
<div className={this.state.subscribed ? "hide" : "flex_item btn_width"}>
<ReCAPTCHA
size="invisible"
ref={this._reCaptchaRef}
sitekey='6LcL08cZAAAAAAn21PBn75R1qLquLlbx1ZB0ZIFd'
/>
<button className="btn" onClick={this.subscribeNewsletters}>Subscribe</button>
</div>
<div className={this.state.subscribed ? "flex_item subscribe-success" : "hide"}>
<h4 className="green_text">
You're now subscribed to our monthly product updates.
</h4>
</div>
</div>
</>
);
}
}
export default SubscribeButton;