Created
September 22, 2016 14:09
-
-
Save timbuckley/bf695657f0fecccf7d23a42b5fa195a7 to your computer and use it in GitHub Desktop.
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
// === Action Creators === | |
export function posItemRequest(itemBody) { | |
return { | |
type: 'ITEM_POST_REQUEST', | |
payload: { | |
itemBody: itemBody | |
} | |
} | |
} | |
export function posItemSuccess(itemBody) { | |
return { | |
type: 'ITEM_POST_SUCCESS', | |
payload: { | |
itemBody: itemBody | |
} | |
} | |
} | |
export function posItemFail(errorMsg) { | |
return { | |
type: 'ITEM_POST_FAIL', | |
payload: { | |
errorMsg: errorMsg | |
} | |
} | |
} | |
// === Thunk === | |
export function postItem(itemBody, userToken) { | |
const options = { | |
method: 'POST', | |
body: JSON.stringify(itemBody) | |
headers: {'User-Token': userToken} | |
} | |
return (dispatch, getState) => { | |
return fetch('http://www.urlhere.com', options) | |
.then(response => response.json()) | |
.then(json => dispatch(posItemSuccess(itemBody))) | |
.catch(err => dispatch(posItemFail(err.message))) | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment