Last active
June 7, 2016 14:15
-
-
Save alexbeletsky/5ca5696cea333703f00e5490e6eee562 to your computer and use it in GitHub Desktop.
Redux Thunk Async Action
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
import { actionRequest, requestFlow } from '../utils/axios'; | |
import { push } from 'react-router-redux'; | |
import constants from '../constants'; | |
export function requestAuthUrl() { | |
return (dispatch) => { | |
const onBefore = () => { | |
dispatch({ type: constants.ACCOUNT_REQUESTING_AUTH_URL }); | |
}; | |
const onSuccess = (resp) => { | |
dispatch({ type: constants.ACCOUNT_AUTH_URL_REQUESTED, payload: resp.data }); | |
dispatch(push(resp.data.redirectUrl)); | |
}; | |
const onError = (resp) => { | |
dispatch({ type: constants.ACCOUNT_AUTH_URL_REQUEST_FAILED, payload: resp }); | |
}; | |
const request = () => { | |
return actionRequest(dispatch) | |
.get('/v1/auth/google'); | |
}; | |
return requestFlow(request, { onBefore, onSuccess, onError }); | |
}; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment