Skip to content

Instantly share code, notes, and snippets.

@sholden
Last active November 5, 2015 20:17
Show Gist options
  • Save sholden/92d5e188f626371f75d4 to your computer and use it in GitHub Desktop.
Save sholden/92d5e188f626371f75d4 to your computer and use it in GitHub Desktop.
api call dispatch
export const TRUECASH_OFFER_REQUEST = "TRUECASH_OFFER_REQUEST";
export const TRUECASH_OFFER_SUCCESS = "TRUECASH_OFFER_SUCCESS";
export const TRUECASH_OFFER_FAILURE = "TRUECASH_OFFER_FAILURE";
export function fetchTruecashOffer(pag, offerId) {
return {
pag,
offerId,
[CALL_API]: {
endpoint: `/my_api_endpoint`,
types: [TRUECASH_OFFER_REQUEST, TRUECASH_OFFER_SUCCESS, TRUECASH_OFFER_FAILURE]
}
}
}
export function loadTruecashOffer (offerId) {
return (dispatch, getState) => {
const state = getState();
if (state.offer.loaded) {
return Promise.resolve();
}
return dispatch(fetchTruecashOffer(pag, offerId)).then(
result => {
dispatch({type: "PROMISE_COMPLETE", result});
if (result.type == TRUECASH_OFFER_SUCCESS) {
dispatch({type: "RECEIVE_OFFER", data: result.response.data});
} else {
dispatch({type: "OFFER_ERROR", data: result.response.data});
}
}
);
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment