Skip to content

Instantly share code, notes, and snippets.

@alexbeletsky
Last active June 7, 2016 14:15
Show Gist options
  • Star 1 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save alexbeletsky/5ca5696cea333703f00e5490e6eee562 to your computer and use it in GitHub Desktop.
Save alexbeletsky/5ca5696cea333703f00e5490e6eee562 to your computer and use it in GitHub Desktop.
Redux Thunk Async Action
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