Skip to content

Instantly share code, notes, and snippets.

@slightlytyler
Last active July 7, 2016 18:55
Show Gist options
  • Save slightlytyler/1ce1d6dbca7b27e7df12f8a1e431751b to your computer and use it in GitHub Desktop.
Save slightlytyler/1ce1d6dbca7b27e7df12f8a1e431751b to your computer and use it in GitHub Desktop.
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