Last active
September 10, 2015 16:17
-
-
Save despairblue/4ae15b40bc47d8efc2af to your computer and use it in GitHub Desktop.
one off actions
This file contains hidden or 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
| function onError (field) { | |
| this.refs[field].focus() | |
| } | |
| <Button onPress={() => this.props.register(this.state, onError)}> | |
| Or Register | |
| </Button> | |
| function register ({username, password, email}, cb) { | |
| return (dispatch, getState) => { | |
| dispatch(requestRegister()) | |
| return fetch(API_REGISTER_URL}, { | |
| method: 'POST', | |
| headers, | |
| body: JSON.stringify({ | |
| username, | |
| email, | |
| password | |
| }) | |
| }) | |
| .then(response => response.json()) | |
| .catch(error => console.error(error.message)) | |
| .done(json => { | |
| if (json.success) { | |
| dispatch(receiveRegister(json)) | |
| } else if (json.data.errors.email) { | |
| dispatch(failRegister('Invalid email.')) | |
| cb('email') | |
| } else if (json.data.errors.username) { | |
| dispatch(failRegister('Invalid username.')) | |
| cb('username') | |
| } | |
| }) | |
| } | |
| } | |
| } |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment