-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathEnterEmail.jsx
49 lines (43 loc) · 1.3 KB
/
EnterEmail.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
import { useState } from "react";
import SubmitButton from "../components/SubmitButton";
import BackButton from "../components/BackButton";
import ErrorMessage from "../components/ErrorMessage";
import Input from "../components/Input";
/**
* A view prompting the user to enter an email address,
* to send a link or code to.
*
* @param {object} props
* @param {boolean} props.allowBack - if true, show a Back button
* @param {object} error - a Userfront error to display
* @param {function} onEvent
*/
const EnterEmail = ({ onEvent, allowBack, error }) => {
const [emailError, setEmailError] = useState(false);
const handleSubmit = (event) => {
event.preventDefault();
// Enforce presence of email
const email = event.target.elements.email.value;
setEmailError(!email);
if (!email) return;
if (onEvent && !emailError) {
onEvent({
type: "submit",
email,
});
}
};
return (
<form onSubmit={handleSubmit} className="userfront-form">
<div className="userfront-form-row">
<Input.Email showError={emailError} />
</div>
<ErrorMessage error={error} />
<div className="userfront-button-row">
{allowBack && <BackButton onEvent={onEvent} />}
<SubmitButton />
</div>
</form>
);
};
export default EnterEmail;