lbry-sec/component/email.jsx

75 lines
1.8 KiB
React
Raw Normal View History

2021-03-29 05:32:35 +02:00
import React from 'react';
export function Email() {
const [email, setEmail] = React.useState('');
const [emailLoading, setEmailLoading] = React.useState(false);
const [emailError, setEmailError] = React.useState();
const [emailSuccess, setEmailSuccess] = React.useState();
function handleEmailSubmit(e) {
e.preventDefault();
if (!email) {
return;
}
setEmailError(false);
setEmailSuccess(false);
setEmailLoading(true);
fetch('/api/email', {
method: 'POST',
headers: {
'Content-Type': 'application/json',
},
body: JSON.stringify({
email,
}),
})
.then((res) => res.json())
.then((data) => {
setEmailLoading(false);
setEmailSuccess(true);
})
.catch(() => {
setEmailLoading(false);
setEmailSuccess(false);
setEmailError(true);
});
}
return (
<div className="email">
2021-03-29 12:18:53 +02:00
<h2 className="content__section-title">Stay Informed</h2>
2021-03-29 05:32:35 +02:00
<div className="email__subtitle">
2021-03-29 13:31:17 +02:00
We will keep you up to date with the latest on this case.
2021-03-29 05:32:35 +02:00
</div>
<label htmlFor="email">Email</label>
<form className="email__group" onSubmit={handleEmailSubmit}>
<input
type="email"
name="email"
2021-03-29 12:18:53 +02:00
placeholder="savecrypto@protonmail.com"
2021-03-29 05:32:35 +02:00
value={email}
onChange={(e) => setEmail(e.target.value)}
/>
<button disabled={!email || emailLoading}>
{emailLoading ? 'Submitting' : 'Submit'}
</button>
</form>
{emailSuccess && (
<div className="email__success">
Thank you! We will keep you in the loop.
</div>
)}
{emailError && (
<div className="email__success">
Sorry, there was an error. Please try again.
</div>
)}
</div>
);
}