Skip to content

Commit

Permalink
Resetting the totalPrice after Purchases
Browse files Browse the repository at this point in the history
  • Loading branch information
Ch-sriram committed Aug 28, 2020
1 parent 6b5b659 commit ddc8161
Show file tree
Hide file tree
Showing 2 changed files with 6 additions and 0 deletions.
1 change: 1 addition & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -129,3 +129,4 @@ Dependency Installation: **`npm i --save redux-thunk`**
12. Redirect in `<ContactData />` to Improve UX: [Commit Details](https://github.com/Ch-sriram/burger-builder/commit/e114f5c158cd8a4383d643137b1b91e48471ccf7)
13. Combining **`REDUCERS`** in **`[./store/reducers/order.js]`** & **`[./store/reducers/burgerBuilder.js]`**: [Commit Details](https://github.com/Ch-sriram/burger-builder/commit/f521ec42f175146b165091e670d92f187534f0e7)
14. Handling Purchases & Updating the UI: [Commit Details](https://github.com/Ch-sriram/burger-builder/commit/c42f5f9d6b1cc7c7d948028e34bd21f64eecd8c6)
15. Resetting the `totalPrice` after Purchases: [Commit Details]()
5 changes: 5 additions & 0 deletions src/store/reducers/burgerBuilder.js
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,10 @@ const reducer = (state = initialState, action) => {
};

case actionTypes.SET_INGREDIENTS:
let price = initialState.totalPrice;
for (let ingredient of Object.entries(action.ingredients)) {
price += INGREDIENT_PRICES[ingredient[0]] * ingredient[1];
}
return {
...state,
ingredients: {
Expand All @@ -44,6 +48,7 @@ const reducer = (state = initialState, action) => {
cheese: action.ingredients.cheese,
meat: action.ingredients.meat,
},
totalPrice: price,
error: false,
}

Expand Down

0 comments on commit ddc8161

Please sign in to comment.