[장바구니 관련 추가]#1

- 작업 진행중
 - api로 데이터 보내도록 처리중.
This commit is contained in:
junghoon86.park
2025-11-12 19:40:55 +09:00
parent 5c8c67f666
commit 301e002985
7 changed files with 244 additions and 18 deletions

View File

@@ -1,4 +1,4 @@
import { types } from "../actions/actionTypes";
import { types } from '../actions/actionTypes';
/**
* Cart Reducer 초기 상태
@@ -18,9 +18,9 @@ const initialState = {
* Cart Reducer
* 장바구니 관련 상태를 관리합니다.
*/
export const cartReducer = (state = initialState, action) => {
export const cartReducer = (state = initialState, action) => {
switch (action.type) {
// 장바구니 조회
// 장바구니 조회 - API에서 가져온 전체 목록
case types.GET_MY_INFO_CART_SEARCH:
return {
...state,
@@ -32,6 +32,56 @@ export const cartReducer = (state = initialState, action) => {
};
// 장바구니에 상품 추가
case types.INSERT_MY_INFO_CART:
return {
...state,
getMyinfoCartSearch: {
...state.getMyinfoCartSearch,
cartList: [...state.getMyinfoCartSearch.cartList, action.payload],
totalCount: (state.getMyinfoCartSearch.totalCount || 0) + 1,
},
lastAction: {
type: "insert",
data: action.payload,
timestamp: Date.now(),
},
error: null,
};
// 장바구니에서 상품 삭제
case types.DELETE_MY_INFO_CART:
return {
...state,
getMyinfoCartSearch: {
...state.getMyinfoCartSearch,
cartList: state.getMyinfoCartSearch.cartList.filter(
item => item.prodSno !== action.payload.prodSno
),
totalCount: Math.max(0, (state.getMyinfoCartSearch.totalCount || 0) - 1),
},
lastAction: {
type: "delete",
data: action.payload,
timestamp: Date.now(),
},
error: null,
};
case types.UPDATE_MY_INFO_CART:
return {
...state,
getMyinfoCartSearch: {
...state.getMyinfoCartSearch,
cartList: state.getMyinfoCartSearch.cartList.map(item =>
item.prodSno === action.payload.prodSno
? { ...item, ...action.payload }
: item
),
},
error: null,
};
// 장바구니에 상품 추가 (addToCart - 로컬 상태용)
case types.ADD_TO_CART:
return {
...state,
@@ -43,7 +93,7 @@ export const cartReducer = (state = initialState, action) => {
error: null,
};
// 장바구니에서 상품 제거
// 장바구니에서 상품 제거 (removeFromCart)
case types.REMOVE_FROM_CART:
return {
...state,
@@ -55,19 +105,19 @@ export const cartReducer = (state = initialState, action) => {
error: null,
};
// 장바구니 상품 수량 업데이트
// 장바구니 상품 수량 업데이트 (updateCartItem)
case types.UPDATE_CART_ITEM:
return {
...state,
lastAction: {
type: "update",
type: "updateQty",
data: action.payload,
timestamp: Date.now(),
},
error: null,
};
// 장바구니 전체 비우기
// 장바구니 전체 비우기 (clearCart - 로컬 상태 전용)
case types.CLEAR_CART:
return {
...state,
@@ -85,4 +135,4 @@ export const cartReducer = (state = initialState, action) => {
default:
return state;
}
};
};