Created
July 20, 2017 21:31
-
-
Save sfletche/d19c8b8f2b8d442ec3b45979dfeacce6 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
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