doc: add REMOVE_FROM_BASKET case
This commit is contained in:
1 parent
135883ec9c
commit
010d9af9df
1 file changed
+19
@@ -13,6 +13,25 @@ const reducer = (state, action) => {
|
|||||||
basket: [...state.basket, action.item],
|
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:
|
default:
|
||||||
return state;
|
return state;
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in new issue
Block a user