This repository was archived by the owner on Aug 20, 2024. It is now read-only.
forked from gothinkster/react-redux-realworld-example-app
-
Notifications
You must be signed in to change notification settings - Fork 54
Expand file tree
/
Copy pathLogin.js
More file actions
97 lines (83 loc) · 2.88 KB
/
Login.js
File metadata and controls
97 lines (83 loc) · 2.88 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
96
97
import { Link } from 'react-router-dom';
import ListErrors from './ListErrors';
import React from 'react';
import agent from '../agent';
import { connect } from 'react-redux';
import {
UPDATE_FIELD_AUTH,
LOGIN,
LOGIN_PAGE_UNLOADED
} from '../constants/actionTypes';
const mapStateToProps = state => ({ ...state.auth });
const mapDispatchToProps = dispatch => ({
onChangeEmail: value =>
dispatch({ type: UPDATE_FIELD_AUTH, key: 'email', value }),
onChangePassword: value =>
dispatch({ type: UPDATE_FIELD_AUTH, key: 'password', value }),
onSubmit: (email, password) =>
dispatch({ type: LOGIN, payload: agent.Auth.login(email, password) }),
onUnload: () =>
dispatch({ type: LOGIN_PAGE_UNLOADED })
});
class Login extends React.Component {
constructor() {
super();
this.changeEmail = ev => this.props.onChangeEmail(ev.target.value);
this.changePassword = ev => this.props.onChangePassword(ev.target.value);
this.submitForm = (email, password) => ev => {
ev.preventDefault();
this.props.onSubmit(email, password);
};
}
componentWillUnmount() {
this.props.onUnload();
}
render() {
const email = this.props.email;
const password = this.props.password;
return (
<div className="auth-page">
<div className="container page">
<div className="row">
<div className="col-md-6 offset-md-3 col-xs-12">
<h1 className="text-xs-center">Log in</h1>
<p className="text-xs-center">
<Link to="/register">
If your not signed up yet, let's make you an account!
</Link>
</p>
<ListErrors errors={this.props.errors} />
<form onSubmit={this.submitForm(email, password)}>
<fieldset>
<fieldset className="form-group">
<input
className="form-control form-control-lg"
type="email"
placeholder="Email"
value={email}
onChange={this.changeEmail} />
</fieldset>
<fieldset className="form-group">
<input
className="form-control form-control-lg"
type="password"
placeholder="Password"
value={password}
onChange={this.changePassword} />
</fieldset>
<button
className="btn btn-lg btn-primary pull-xs-right"
type="submit"
disabled={this.props.inProgress}>
Log in
</button>
</fieldset>
</form>
</div>
</div>
</div>
</div>
);
}
}
export default connect(mapStateToProps, mapDispatchToProps)(Login);