Last active
June 26, 2019 13:30
-
-
Save hmelenok/d84f96b0cf03129fce8617198eb9d69f to your computer and use it in GitHub Desktop.
This file contains hidden or 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 const goToDecisionStep = (stepId = 'Step#1', gemId) => async (dispatch, getState) => { | |
const { | |
gemDecisionTree: {nodes} | |
} = getState(); | |
const alreadyFetchedStep = nodes[stepId]; | |
if (!isEmpty(alreadyFetchedStep)) { | |
return dispatch(setActiveDecisionStep(alreadyFetchedStep)); | |
} | |
dispatch(setStepLoading(true)); | |
try { | |
const { | |
data: {step} | |
} = await DecisionTreeApi.getStep(stepId, gemId); | |
/** | |
* In case of error step will be null | |
*/ | |
dispatch(setActiveDecisionStep(step || {})); | |
} catch (e) { | |
dispatch(setActiveDecisionStep({})); | |
} | |
}; |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment