Skip to content

Commit

Permalink
fix(cart): set item state meta reducer mutates action (#2666)
Browse files Browse the repository at this point in the history
  • Loading branch information
griest024 committed Dec 18, 2023
1 parent f5836a1 commit 0aa35b0
Showing 1 changed file with 22 additions and 12 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -25,25 +25,35 @@ export function daffCartSetItemStateMetaReducer<T extends DaffStatefulCartItem =
return (state, action) => {
switch (action.type) {
case DaffCartItemActionTypes.CartItemAddSuccessAction:
action.payload.items = updateAddedCartItemState<T>(state.cartItems.entities, (<T[]>action.payload.items).map((item) => ({
...item,
daffErrors: [],
})));
return reducer(
state,
action,
{
...action,
payload: {
...action.payload,
items: updateAddedCartItemState<T>(state.cartItems.entities, (<T[]>action.payload.items).map((item) => ({
...item,
daffErrors: [],
}))),
},
},
);

case DaffCartItemActionTypes.CartItemUpdateSuccessAction:
action.payload.items = updateMutatedCartItemState<T>((<T[]>action.payload.items).map((item) => item.id === action.itemId
? {
...item,
daffErrors: [],
}
: item), state.cartItems.entities, action.itemId);
return reducer(
state,
action,
{
...action,
payload: {
...action.payload,
items: updateMutatedCartItemState<T>((<T[]>action.payload.items).map((item) => item.id === action.itemId
? {
...item,
daffErrors: [],
}
: item), state.cartItems.entities, action.itemId),
},
},
);

default:
Expand Down

0 comments on commit 0aa35b0

Please sign in to comment.