forked from sqlpad/sqlpad
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathForgotPassword.js
More file actions
50 lines (44 loc) · 1.32 KB
/
Copy pathForgotPassword.js
File metadata and controls
50 lines (44 loc) · 1.32 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
import React, { useEffect, useState } from 'react';
import { Redirect } from 'react-router-dom';
import Button from './common/Button';
import Input from './common/Input';
import message from './common/message';
import Spacer from './common/Spacer';
import fetchJson from './utilities/fetch-json.js';
function ForgotPassword() {
const [email, setEmail] = useState('');
const [redirect, setRedirect] = useState(false);
useEffect(() => {
document.title = 'SQLPad - Forgot Password';
}, []);
const resetPassword = async e => {
e.preventDefault();
const json = await fetchJson('POST', '/api/forgot-password', { email });
if (json.error) {
return message.error(json.error);
}
setRedirect(true);
};
if (redirect) {
return <Redirect to="/password-reset" />;
}
return (
<div style={{ width: '300px', textAlign: 'center', margin: '100px auto' }}>
<form onSubmit={resetPassword}>
<h1>SQLPad</h1>
<Input
name="email"
type="email"
placeholder="Email address"
onChange={e => setEmail(e.target.value)}
required
/>
<Spacer size={2} />
<Button style={{ width: '100%' }} htmlType="submit" type="primary">
Reset Password
</Button>
</form>
</div>
);
}
export default ForgotPassword;