-
-
Save marr/e6f342eca2d683a87ef9 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
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