Skip to content

Instantly share code, notes, and snippets.

@sfletche
Created July 20, 2017 21:31
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save sfletche/d19c8b8f2b8d442ec3b45979dfeacce6 to your computer and use it in GitHub Desktop.
Save sfletche/d19c8b8f2b8d442ec3b45979dfeacce6 to your computer and use it in GitHub Desktop.
const initialState = {
pricingPlans: [],
pricingPlansWithRepayment: [],
selectedOptionIdentifier: null,
selectedPreviewOptionIdentifier: null,
error: {},
};
function reducer(state = initialState, action = {}) {
switch (action.type) {
case actionTypes.RECEIVE_PRICING_PLANS: {
const { pricingPlans, selectedOptionIdentifier } = action.data;
return {
...state,
pricingPlans,
selectedOptionIdentifier: state.selectedOptionIdentifier || selectedOptionIdentifier,
selectedPreviewOptionIdentifier: state.selectedPreviewOptionIdentifier || selectedOptionIdentifier,
};
}
case actionTypes.RECEIVE_PRICING_PLANS_WITH_REPAYMENT:
return {
...state,
pricingPlansWithRepayment: action.data.pricingPlans,
};
case actionTypes.FETCH_PRICING_PLANS:
return {
...state,
pricingPlans: [],
error: {},
};
case actionTypes.SELECT_OPTION_IDENTIFIER:
return {
...state,
selectedOptionIdentifier: action.data,
};
case actionTypes.SELECT_PREVIEW_OPTION_IDENTIFIER:
return {
...state,
selectedPreviewOptionIdentifier: action.data,
};
case actionTypes.RECEIVE_PRICING_PLANS_ERROR:
return {
...state,
...action.data,
};
default:
return state;
}
}
export default reducer;
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment