diff --git a/client/app/components/admin/LoginForm/LoginForm.jsx b/client/app/components/admin/LoginForm/LoginForm.jsx new file mode 100644 index 0000000..ef25fdf --- /dev/null +++ b/client/app/components/admin/LoginForm/LoginForm.jsx @@ -0,0 +1,66 @@ +import React, { Component } from 'react'; +import { connect } from 'react-redux'; +import { login } from '../../redux/reducer.jsx'; + +class LoginForm extends Component { + + constructor(props) { + super(props); + this.state = {}; + this.onSubmit = this.onSubmit.bind(this); + } + + render() { + let {email, password} = this.state; + let {isLoginPending, isLoginSuccess, loginError} = this.props; + return ( +
+
+
+ + this.setState({email: e.target.value})} value={email}/> +
+ +
+ + this.setState({password: e.target.value})} value={password}/> +
+
+ + + +
+ { isLoginPending &&
Please wait...
} + { isLoginSuccess &&
Success.
} + { loginError &&
{loginError.message}
} +
+
+ ) + } + + onSubmit(e) { + e.preventDefault(); + let { email, password } = this.state; + this.props.login(email, password); + this.setState({ + email: '', + password: '' + }); + } +} + +const mapStateToProps = (state) => { + return { + isLoginPending: state.isLoginPending, + isLoginSuccess: state.isLoginSuccess, + loginError: state.loginError + }; +} + +const mapDispatchToProps = (dispatch) => { + return { + login: (email, password) => dispatch(login(email, password)) + }; +} + +export default connect(mapStateToProps, mapDispatchToProps)(LoginForm); \ No newline at end of file