diff --git a/src/redux/reducer.js b/src/redux/reducer.js index f9391ed..8857b2f 100644 --- a/src/redux/reducer.js +++ b/src/redux/reducer.js @@ -13,6 +13,25 @@ const reducer = (state, action) => { basket: [...state.basket, action.item], }; + case "REMOVE_FROM_BAKSET": + const index = state.basket.findIndex( + (basketItem) => basketItem.id === action.id + ); + let newBasket = [...state.basket]; + + if (index >= 0) { + newBasket.splice(index, 1); + } else { + alert( + `Can't remove product (id: ${action.id}) as is not in the basket!` + ); + } + + return { + ...state, + basket: newBasket, + }; + default: return state; }