Skip to content
Snippets Groups Projects
Commit c42741c0 authored by Minseo Lee's avatar Minseo Lee
Browse files

fix: cartItems clonedeep

parent 9c6bd793
No related branches found
No related tags found
No related merge requests found
......@@ -10,7 +10,6 @@ import S from './Wrapper.module.css';
import type { GFCWithProp } from "../../../common/types/fc";
import type { OrderedItemModel } from "../../../pages/admin-page/config/type";
import type { CartItemPostModel } from "../../../pages/cart-page/config/type";
import type { MenuPageModel } from "../../../pages/menu-page/config/type";
import type { ReactNode , MutableRefObject } from "react";
......
import { createContext, useEffect, useState } from "react";
import { cloneDeep } from "../../common/utils/jjLodash";
import logger from "../../common/utils/logger";
import type { CartItemData } from "../../pages/cart-page/config/type";
......@@ -42,11 +43,11 @@ const CartProvider: FC<Props> = ({ children }) => {
const addCartItem = (cartItem: CartItemData) => {
setItem((prevItem) => {
if (cartItem.shop !== prevItem?.shop) {
if (cartItem.shop._id !== prevItem?.shop._id) {
return cartItem;
}
else {
const _prev = { ...prevItem };
const _prev = cloneDeep(prevItem);
_prev?.menus?.push(...cartItem.menus);
return _prev;
}
......
......@@ -69,8 +69,8 @@ const MenuBSEl: FC<MenuBSElProps> = ({ _id, name, price, image, shop }) => {
const handleClickPutIn = () => {
if (!cartItem) caseCartIsEmpty();
if (cartItem?.shop && (cartItem?.shop !== shop)) caseCartIsNotSameShop();
if (cartItem?.shop && (cartItem?.shop === shop)) caseCartIsSameShop();
if (cartItem?.shop && (cartItem?.shop._id !== shop._id)) caseCartIsNotSameShop();
if (cartItem?.shop && (cartItem?.shop._id === shop._id)) caseCartIsSameShop();
// TODO:: Needs TOAST
flushBSElement();
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment