2016-06-23 22:29:55 +00:00
|
|
|
import React from 'react';
|
|
|
|
import { reduxForm } from 'redux-form';
|
2016-10-08 22:03:39 +00:00
|
|
|
import { validateAndLoginUser } from '../../User/actions';
|
2016-06-23 22:29:55 +00:00
|
|
|
import LoginForm from '../components/LoginForm';
|
2016-09-06 20:53:37 +00:00
|
|
|
// import GithubButton from '../components/GithubButton';
|
2016-09-02 21:37:34 +00:00
|
|
|
import { Link } from 'react-router';
|
2016-08-31 16:28:06 +00:00
|
|
|
|
2016-06-23 22:29:55 +00:00
|
|
|
|
2016-10-08 22:03:39 +00:00
|
|
|
class LoginView extends React.Component {
|
|
|
|
componentDidMount() {
|
|
|
|
this.refs.login.focus();
|
|
|
|
}
|
|
|
|
|
|
|
|
render() {
|
|
|
|
return (
|
|
|
|
<div className="login" ref="login" tabIndex="0">
|
|
|
|
<h1>Login</h1>
|
|
|
|
<LoginForm {...this.props} />
|
|
|
|
{/* <h2 className="login__divider">Or</h2>
|
|
|
|
<GithubButton buttonText="Login with Github" /> */}
|
|
|
|
<Link className="form__cancel-button" to="/">Cancel</Link>
|
|
|
|
</div>
|
|
|
|
);
|
|
|
|
}
|
2016-06-23 22:29:55 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
function mapStateToProps(state) {
|
|
|
|
return {
|
|
|
|
user: state.user
|
|
|
|
};
|
|
|
|
}
|
|
|
|
|
2016-09-02 21:31:07 +00:00
|
|
|
function mapDispatchToProps() {
|
|
|
|
return {
|
|
|
|
validateAndLoginUser
|
|
|
|
};
|
2016-06-23 22:29:55 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
function validate(formProps) {
|
|
|
|
const errors = {};
|
2016-06-24 18:22:32 +00:00
|
|
|
if (!formProps.email) {
|
|
|
|
errors.email = 'Please enter a email';
|
|
|
|
}
|
|
|
|
if (!formProps.password) {
|
|
|
|
errors.password = 'Please enter a password';
|
|
|
|
}
|
2016-06-23 22:29:55 +00:00
|
|
|
return errors;
|
|
|
|
}
|
|
|
|
|
|
|
|
export default reduxForm({
|
|
|
|
form: 'login',
|
|
|
|
fields: ['email', 'password'],
|
|
|
|
validate
|
|
|
|
}, mapStateToProps, mapDispatchToProps)(LoginView);
|