Skip to content

Instantly share code, notes, and snippets.

@hmelenok
Last active June 26, 2019 13:30
Show Gist options
  • Save hmelenok/d84f96b0cf03129fce8617198eb9d69f to your computer and use it in GitHub Desktop.
Save hmelenok/d84f96b0cf03129fce8617198eb9d69f to your computer and use it in GitHub Desktop.
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