-
Notifications
You must be signed in to change notification settings - Fork 0
/
LoginPage.js
68 lines (60 loc) · 1.7 KB
/
LoginPage.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
import React from 'react';
import TextInput from '../../components/common/TextInput';
import { bindActionCreators } from 'redux';
import { connect } from 'react-redux';
import * as sessionActions from '../../actions/sessionActions';
class LogInPage extends React.Component {
constructor(props) {
super(props);
this.state = {
credentials:
{
email: "",
password: ""
}
}
}
onChange = (event) => {
const field = event.target.name;
const credentials = this.state.credentials;
credentials[field] = event.target.value;
return this.setState({credentials: credentials});
}
onSubmit = (event) => {
event.preventDefault();
const redirect = '/home'
const history = this.props.history
this.props.actions.loginUser(this.state.credentials, history, redirect);
}
render() {
return (
<div className="login-signup-search">
<div className="login-signup-search-form">
<form>
<TextInput
name="email"
label="email"
value={this.state.credentials.email}
onChange={this.onChange}/>
<TextInput
name="password"
label="password"
type="password"
value={this.state.credentials.password}
onChange={this.onChange}/>
<input
type="submit"
className="btn btn-primary"
onClick={this.onSubmit}/>
</form>
</div>
</div>
);
}
}
function mapDispatchToProps(dispatch) {
return {
actions: bindActionCreators(sessionActions, dispatch)
};
}
export default connect(null, mapDispatchToProps)(LogInPage);