2016-06-23 22:29:55 +00:00
|
|
|
import React from 'react';
|
|
|
|
import { bindActionCreators } from 'redux';
|
|
|
|
import * as UserActions from '../actions';
|
|
|
|
import { reduxForm } from 'redux-form';
|
|
|
|
import SignupForm from '../components/SignupForm';
|
2016-08-31 19:12:18 +00:00
|
|
|
import GithubButton from '../components/GithubButton';
|
2016-06-23 22:29:55 +00:00
|
|
|
|
2016-06-24 22:18:22 +00:00
|
|
|
function SignupView(props) {
|
|
|
|
return (
|
|
|
|
<div className="signup">
|
|
|
|
<h1>Sign Up</h1>
|
|
|
|
<SignupForm {...props} />
|
2016-08-31 19:12:18 +00:00
|
|
|
<h2 className="signup__divider">Or</h2>
|
|
|
|
<GithubButton buttonText="Sign Up with Github" />
|
2016-06-24 22:18:22 +00:00
|
|
|
</div>
|
|
|
|
);
|
2016-06-23 22:29:55 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
function mapStateToProps(state) {
|
|
|
|
return {
|
|
|
|
user: state.user
|
|
|
|
};
|
|
|
|
}
|
|
|
|
|
|
|
|
function mapDispatchToProps(dispatch) {
|
|
|
|
return bindActionCreators(UserActions, dispatch);
|
|
|
|
}
|
|
|
|
|
|
|
|
function validate(formProps) {
|
|
|
|
const errors = {};
|
2016-06-24 18:22:32 +00:00
|
|
|
|
|
|
|
if (!formProps.username) {
|
|
|
|
errors.username = 'Please enter a username';
|
|
|
|
}
|
|
|
|
if (!formProps.email) {
|
|
|
|
errors.email = 'Please enter an email';
|
|
|
|
}
|
|
|
|
if (!formProps.password) {
|
|
|
|
errors.password = 'Please enter a password';
|
|
|
|
}
|
|
|
|
if (!formProps.confirmPassword) {
|
|
|
|
errors.confirmPassword = 'Please enter a password confirmation';
|
|
|
|
}
|
|
|
|
|
2016-06-24 22:08:52 +00:00
|
|
|
if (formProps.password !== formProps.confirmPassword) {
|
2016-06-24 18:22:32 +00:00
|
|
|
errors.password = 'Passwords must match';
|
|
|
|
}
|
2016-06-24 22:08:52 +00:00
|
|
|
|
2016-06-23 22:29:55 +00:00
|
|
|
return errors;
|
|
|
|
}
|
|
|
|
|
|
|
|
// export default connect(mapStateToProps, mapDispatchToProps)(SignupView);
|
|
|
|
export default reduxForm({
|
|
|
|
form: 'signup',
|
2016-06-24 22:08:52 +00:00
|
|
|
fields: ['username', 'email', 'password', 'confirmPassword'],
|
2016-06-23 22:29:55 +00:00
|
|
|
validate
|
|
|
|
}, mapStateToProps, mapDispatchToProps)(SignupView);
|