Skip to content

Instantly share code, notes, and snippets.

@marr
Created March 2, 2016 00:58
Show Gist options
  • Save marr/e6f342eca2d683a87ef9 to your computer and use it in GitHub Desktop.
Save marr/e6f342eca2d683a87ef9 to your computer and use it in GitHub Desktop.
export function loadUser(personId) {
return async (dispatch, getState) => {
dispatch({ type: LOAD_USER, payload: { personId } })
try {
// Load account api
const accountResponse = await fetchAccount(personId)
dispatch(receivedAccount(personId, accountResponse))
// Load status api
const email = accountResponse.data.email
const accountStatusResponse = await fetchAccountStatus(email)
dispatch(receivedStatus(personId, accountStatusResponse))
// Load centre api
const centreId = accountResponse.data.primary_centre_id
const centreResponse = await fetchCentre(centreId)
dispatch(receivedCentre(personId, centreResponse))
// Loaded user!!
const user = getState().guests[personId]
dispatch(loadedUser(user))
} catch (e) {
console.error(e, e.stack)
throw e
}
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment