-
Notifications
You must be signed in to change notification settings - Fork 3
/
ForgetPasswordPage.tsx
103 lines (95 loc) · 3.4 KB
/
ForgetPasswordPage.tsx
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
import {FC, FormEvent, useState} from "react";
import {useLoginStyles} from "./Styles";
import Avatar from '@material-ui/core/Avatar';
import Button from '@material-ui/core/Button';
import TextField from '@material-ui/core/TextField';
import Grid from '@material-ui/core/Grid';
import LockOutlinedIcon from '@material-ui/icons/LockOutlined';
import Typography from '@material-ui/core/Typography';
import {Backdrop, CircularProgress, Container, Link} from "@material-ui/core";
import {Link as RouterLink} from 'react-router-dom';
import {Alert} from '@material-ui/lab';
import {API_BASE_URL} from "../../Constants";
import {http} from "../../http";
type ForgetPasswordPageProps = {}
interface ForgetPasswordResponse {
token: string;
}
export const ForgetPasswordPage: FC<ForgetPasswordPageProps> = (props) => {
const classes = useLoginStyles();
const [loading, setLoading] = useState<boolean>(false);
const [error, setError] = useState<string>("");
const [email, setEmail] = useState<string>('');
const handleFormSubmit = async (e: FormEvent) => {
e.preventDefault();
try {
setLoading(true);
const response = await http<ForgetPasswordResponse>(API_BASE_URL + "/auth/reminder", "POST", {
"email": email,
});
console.log("Response ", response.parsedBody)
} catch (ex) {
if (ex instanceof Error) setError(ex.toString());
} finally {
setLoading(false);
}
};
return (
<Container component="main" maxWidth="xs">
<div className={classes.paper}>
<Avatar className={classes.avatar}>
<LockOutlinedIcon/>
</Avatar>
<Typography component="h1" variant="h5">
Reset Password
</Typography>
<form className={classes.form} noValidate={false} onSubmit={handleFormSubmit}>
<Grid container spacing={0}>
{error.length > 0 && <Grid item xs={12}><Alert severity="error">{error}</Alert></Grid>}
<Grid item xs={12}>
<TextField
variant="outlined"
margin="normal"
required
fullWidth
id="email"
label="Email Address"
name="email"
autoComplete="email"
autoFocus
value={email}
onChange={event => setEmail(event.target.value)}
/>
</Grid>
<Grid item xs={12}>
<Button
type="submit"
fullWidth
variant="contained"
color="primary"
className={classes.submit}
onClick={handleFormSubmit}
>
Reset Password
</Button>
</Grid>
<Grid item xs={12}>
<Grid container justify="flex-end">
<Grid item>
<Link component={RouterLink} to="/login" variant="body2">
Already have an account? Sign in
</Link>
</Grid>
</Grid>
</Grid>
</Grid>
<Backdrop
className={classes.backdrop}
open={loading}>
<CircularProgress color="inherit"/>
</Backdrop>
</form>
</div>
</Container>
)
};