-
Notifications
You must be signed in to change notification settings - Fork 17
Expand file tree
/
Copy pathforgot.jsx
More file actions
95 lines (82 loc) · 2.34 KB
/
Copy pathforgot.jsx
File metadata and controls
95 lines (82 loc) · 2.34 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
import React, { useContext } from 'react';
import cn from 'classnames';
import { Link, Redirect } from 'react-router-dom';
import { routes } from 'routes';
import { StoreContext } from 'resources/store/store';
import * as api from 'resources/user/user.api';
import Input from 'components/input';
import Button from 'components/button';
import Form from 'components/form';
import styles from './forgot.pcss';
const Forgot = () => {
const { state } = useContext(StoreContext);
const { user } = state;
const [values, setValues] = React.useState({});
const [pending, setPending] = React.useState(false);
const [submitted, setSubmitted] = React.useState(false);
const handleSubmit = async ({ email }) => {
setPending(true);
await api.forgot({ email });
setValues({ email });
setSubmitted(true);
setPending(false);
};
if (user) {
return <Redirect to={routes.home.url()} />;
}
return (
<div className={styles.container}>
<h1 className={styles.title}>
Forgot Password
</h1>
{submitted && (
<>
<p className={styles.description}>
We sent a reset link to your email:
</p>
<p className={cn(styles.description, styles.description_bold)}>
{values.email}
</p>
</>
)}
{!submitted && (
<>
<p className={styles.description}>
We’ll send a reset link to your email
</p>
<Form
onSubmit={handleSubmit}
className={styles.form}
>
<div className={styles.row}>
<Input
type="email"
name="email"
placeholder="Email"
disabled={pending}
/>
</div>
<div className={styles.row}>
<Button
htmlType="submit"
isLoading={pending}
>
Send reset link
</Button>
</div>
<div className={styles.links}>
<div className={styles.row}>
Remember the password?
{' '}
<Link to={routes.signIn.url()}>
Sign in
</Link>
</div>
</div>
</Form>
</>
)}
</div>
);
};
export default React.memo(Forgot);