1 import React, { Component } from 'react'; |
1 import React, { Component } from 'react'; |
2 import { connect } from 'react-redux'; |
2 import { connect } from 'react-redux'; |
3 import { bindActionCreators } from 'redux'; |
3 import { bindActionCreators } from 'redux'; |
4 import { Grid, Row, Col, Panel, FormGroup, ControlLabel, FormControl, Button } from 'react-bootstrap'; |
4 import { Grid, Row, Col, Panel, FormGroup, ControlLabel, FormControl, Button, Alert } from 'react-bootstrap'; |
5 import '../App.css'; |
5 import '../App.css'; |
6 import Navbar from './Navbar'; |
6 import Navbar from './Navbar'; |
7 import * as sessionsActions from '../actions/sessionsActions'; |
7 import * as authActions from '../actions/authActions'; |
8 |
8 |
9 class Login extends Component { |
9 class Login extends Component { |
10 |
10 |
11 login = () => { |
11 login = () => { |
12 const username = this.username.value; |
12 const username = this.username.value; |
13 const password = this.password.value; |
13 const password = this.password.value; |
14 |
14 |
15 console.log(username, password); |
15 this.props.authActions.loginSubmit(username, password); |
|
16 } |
16 |
17 |
|
18 renderError() { |
|
19 return ( |
|
20 <Alert bsStyle="danger">Bad credentials</Alert> |
|
21 ) |
17 } |
22 } |
18 |
23 |
19 render() { |
24 render() { |
20 return ( |
25 return ( |
21 <div> |
26 <div> |
44 } |
50 } |
45 } |
51 } |
46 |
52 |
47 function mapStateToProps(state, props) { |
53 function mapStateToProps(state, props) { |
48 return { |
54 return { |
49 currentSession: state.get('currentSession'), |
55 currentUser: state.get('currentUser'), |
50 sessions: state.get('sessions') |
56 login: state.get('login') |
51 }; |
57 }; |
52 } |
58 } |
53 |
59 |
54 function mapDispatchToProps(dispatch) { |
60 function mapDispatchToProps(dispatch) { |
55 return { |
61 return { |
56 actions: bindActionCreators(sessionsActions, dispatch) |
62 authActions: bindActionCreators(authActions, dispatch) |
57 } |
63 } |
58 } |
64 } |
59 |
65 |
60 export default connect(mapStateToProps, mapDispatchToProps)(Login); |
66 export default connect(mapStateToProps, mapDispatchToProps)(Login); |