This repository was archived by the owner on Feb 26, 2020. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 27
/
Copy pathpw-forget.js
81 lines (65 loc) · 1.7 KB
/
pw-forget.js
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
import React, { Component } from "react";
import Link from "next/link";
import { AppWithAuthentication } from "../src/components/App";
import * as routes from "../src/constants/routes";
import { auth } from "../src/firebase";
const PasswordForgetPage = () => (
<AppWithAuthentication>
<h1>PasswordForget</h1>
<PasswordForgetForm />
</AppWithAuthentication>
);
const updateByPropertyName = (propertyName, value) => () => ({
[propertyName]: value
});
const INITIAL_STATE = {
email: "",
error: null
};
class PasswordForgetForm extends Component {
constructor(props) {
super(props);
this.state = { ...INITIAL_STATE };
}
onSubmit = event => {
const { email } = this.state;
auth
.doPasswordReset(email)
.then(() => {
this.setState(() => ({ ...INITIAL_STATE }));
})
.catch(error => {
this.setState(updateByPropertyName("error", error));
});
event.preventDefault();
};
render() {
const { email, error } = this.state;
const isInvalid = email === "";
return (
<form onSubmit={this.onSubmit}>
<input
value={this.state.email}
onChange={event =>
this.setState(updateByPropertyName("email", event.target.value))
}
type="text"
placeholder="Email Address"
/>
<button disabled={isInvalid} type="submit">
Reset My Password
</button>
{error && <p>{error.message}</p>}
</form>
);
}
}
const PasswordForgetLink = () => (
<p>
<Link href={routes.PASSWORD_FORGET}>
<a>Forgot Password?</a>
</Link>
</p>
);
export default PasswordForgetPage;
export { PasswordForgetForm, PasswordForgetLink };