Last active
July 7, 2016 18:55
-
-
Save slightlytyler/1ce1d6dbca7b27e7df12f8a1e431751b to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
export class SignupControl extends React.Component { | |
constructor(props) { | |
super(props) | |
this.handleSubmit = this.handleSubmit.bind(this) | |
} | |
handleSubmit(values) { | |
return new Promise ((resolve, reject) => { | |
this.props.actions.signup(values.name, | |
values.email, | |
values.password) | |
.then(()=>{ | |
resolve() | |
}) | |
.catch(()=>{ | |
reject({email: 'Email already in use'}) | |
}) | |
}) | |
} | |
render() { | |
let formConfig = { | |
form: 'signUp' | |
fields: ['name', 'email', 'password'], | |
onSubmit: this.handleSubmit | |
} | |
let Form = reduxForm(formConfig)(this.props.children) | |
return <Form /> | |
} | |
} | |
export default function createSignupControl (Component) { | |
return connect(mapStateToProps, mapDispatchToProps)(props => ( | |
<SignupControl {...props}><Component /></SignUpControl> | |
)); | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment