[250930] feat: cart관련 redux추가 , BuyOption 포커스 수정
This commit is contained in:
88
com.twin.app.shoptime/src/reducers/cartReducer.js
Normal file
88
com.twin.app.shoptime/src/reducers/cartReducer.js
Normal file
@@ -0,0 +1,88 @@
|
||||
import { types } from "../actions/actionTypes";
|
||||
|
||||
/**
|
||||
* Cart Reducer 초기 상태
|
||||
*/
|
||||
const initialState = {
|
||||
// 장바구니 조회 데이터
|
||||
getMyinfoCartSearch: {
|
||||
cartList: [],
|
||||
totalCount: 0,
|
||||
},
|
||||
// 추가/수정/삭제 결과
|
||||
lastAction: null,
|
||||
error: null,
|
||||
};
|
||||
|
||||
/**
|
||||
* Cart Reducer
|
||||
* 장바구니 관련 상태를 관리합니다.
|
||||
*/
|
||||
export const cartReducer = (state = initialState, action) => {
|
||||
switch (action.type) {
|
||||
// 장바구니 조회
|
||||
case types.GET_MY_INFO_CART_SEARCH:
|
||||
return {
|
||||
...state,
|
||||
getMyinfoCartSearch: action.payload || {
|
||||
cartList: [],
|
||||
totalCount: 0,
|
||||
},
|
||||
error: null,
|
||||
};
|
||||
|
||||
// 장바구니에 상품 추가
|
||||
case types.ADD_TO_CART:
|
||||
return {
|
||||
...state,
|
||||
lastAction: {
|
||||
type: "add",
|
||||
data: action.payload,
|
||||
timestamp: Date.now(),
|
||||
},
|
||||
error: null,
|
||||
};
|
||||
|
||||
// 장바구니에서 상품 제거
|
||||
case types.REMOVE_FROM_CART:
|
||||
return {
|
||||
...state,
|
||||
lastAction: {
|
||||
type: "remove",
|
||||
data: action.payload,
|
||||
timestamp: Date.now(),
|
||||
},
|
||||
error: null,
|
||||
};
|
||||
|
||||
// 장바구니 상품 수량 업데이트
|
||||
case types.UPDATE_CART_ITEM:
|
||||
return {
|
||||
...state,
|
||||
lastAction: {
|
||||
type: "update",
|
||||
data: action.payload,
|
||||
timestamp: Date.now(),
|
||||
},
|
||||
error: null,
|
||||
};
|
||||
|
||||
// 장바구니 전체 비우기
|
||||
case types.CLEAR_CART:
|
||||
return {
|
||||
...state,
|
||||
getMyinfoCartSearch: {
|
||||
cartList: [],
|
||||
totalCount: 0,
|
||||
},
|
||||
lastAction: {
|
||||
type: "clear",
|
||||
timestamp: Date.now(),
|
||||
},
|
||||
error: null,
|
||||
};
|
||||
|
||||
default:
|
||||
return state;
|
||||
}
|
||||
};
|
||||
Reference in New Issue
Block a user