diff --git a/com.twin.app.shoptime/src/App/App.js b/com.twin.app.shoptime/src/App/App.js
index e11c6094..b999aa47 100644
--- a/com.twin.app.shoptime/src/App/App.js
+++ b/com.twin.app.shoptime/src/App/App.js
@@ -7,6 +7,7 @@ import MainView from "../views/MainView/MainView";
import { useDispatch } from "react-redux";
import { getAuthenticationCode } from "../features/device/deviceSlice";
import { getHomeMenu } from "../features/home/homeSlice";
+import { getOnSaleInfo } from "../features/onSale/onSaleSlice";
function AppBase(props) {
const dispatch = useDispatch();
@@ -14,6 +15,7 @@ function AppBase(props) {
useEffect(() => {
dispatch(getAuthenticationCode());
dispatch(getHomeMenu());
+ dispatch(getOnSaleInfo({ categoryIncFlag: "Y", lgCatCd: "" }));
}, [dispatch]);
return ;
diff --git a/com.twin.app.shoptime/src/features/onSale/onSaleSlice.js b/com.twin.app.shoptime/src/features/onSale/onSaleSlice.js
new file mode 100644
index 00000000..060b88ed
--- /dev/null
+++ b/com.twin.app.shoptime/src/features/onSale/onSaleSlice.js
@@ -0,0 +1,51 @@
+import { createAsyncThunk, createSlice } from "@reduxjs/toolkit";
+
+import { URLS } from "../../api/apiConfig";
+import { TAxios } from "../../api/TAxios";
+
+// On Sale 조회 IF-LGSP-086
+export const getOnSaleInfo = createAsyncThunk(
+ "onSale/getOnSaleInfo",
+
+ async (props, thunkAPI) => {
+ const { categoryIncFlag, lgCatCd } = props;
+ const onSuccess = (response) => {
+ console.log("getOnSaleInfo onSuccess ", response.data);
+
+ thunkAPI.dispatch(onSaleSlice.actions.updateOnSaleData(response.data.data));
+ };
+
+ const onFail = (error) => {
+ console.log("getOnSaleInfo onFail", error);
+ };
+
+ TAxios(
+ thunkAPI.dispatch,
+ thunkAPI.getState,
+ "get",
+ URLS.GET_ON_SALE_INFO,
+ { categoryIncFlag, lgCatCd },
+ {},
+ onSuccess,
+ onFail
+ );
+ }
+);
+
+const initialState = {
+ onSaleData: {},
+};
+
+export const onSaleSlice = createSlice({
+ name: "onSale",
+ initialState,
+ reducers: {
+ updateOnSaleData: (state, action) => {
+ state.onSaleData = action.payload;
+ },
+ },
+});
+
+export const { updateOnSaleData } = onSaleSlice.actions;
+
+export default onSaleSlice.reducer;
diff --git a/com.twin.app.shoptime/src/store/store.js b/com.twin.app.shoptime/src/store/store.js
index 25e0d76f..0b987def 100644
--- a/com.twin.app.shoptime/src/store/store.js
+++ b/com.twin.app.shoptime/src/store/store.js
@@ -5,6 +5,7 @@ import deviceReducer from "../features/device/deviceSlice";
import commonReducer from "../features/common/commonSlice";
import panelsReducer from "../features/panels/panelsSlice";
import homeReducer from "../features/home/homeSlice";
+import onSaleReducer from "../features/onSale/onSaleSlice";
export const store = configureStore({
reducer: {
@@ -13,5 +14,6 @@ export const store = configureStore({
appData: appDataReducer,
common: commonReducer,
home: homeReducer,
+ onSale: onSaleReducer,
},
});
diff --git a/com.twin.app.shoptime/src/views/OnSalePanel/CategoryNav/CategoryNav.jsx b/com.twin.app.shoptime/src/views/OnSalePanel/CategoryNav/CategoryNav.jsx
index 84316bdb..f9a12398 100644
--- a/com.twin.app.shoptime/src/views/OnSalePanel/CategoryNav/CategoryNav.jsx
+++ b/com.twin.app.shoptime/src/views/OnSalePanel/CategoryNav/CategoryNav.jsx
@@ -17,7 +17,7 @@ const SpottableComponent = Spottable("li");
export default function CategoryNav({
categoryInfos,
- currentLgCatCdIndex,
+ currentLgCatCd,
onCategoryNavClick,
...rest
}) {
@@ -31,15 +31,12 @@ export default function CategoryNav({
>
{categoryInfos &&
- categoryInfos.map(({ lgCatNm, lgCatCd }, index) => {
+ categoryInfos.map(({ lgCatNm, lgCatCd }) => {
return (
onCategoryNavClick(lgCatCd, index)}
+ onClick={() => onCategoryNavClick(lgCatCd)}
>
diff --git a/com.twin.app.shoptime/src/views/OnSalePanel/OnSalePanel.jsx b/com.twin.app.shoptime/src/views/OnSalePanel/OnSalePanel.jsx
index 702e7a51..098a6140 100644
--- a/com.twin.app.shoptime/src/views/OnSalePanel/OnSalePanel.jsx
+++ b/com.twin.app.shoptime/src/views/OnSalePanel/OnSalePanel.jsx
@@ -1,87 +1,67 @@
import React, { useEffect, useState } from "react";
-import { useDispatch } from "react-redux";
+import { useDispatch, useSelector } from "react-redux";
-import { getOnSaleInfo } from "../../api/onSaleApi";
import TPanel from "../../components/TPanel/TPanel";
-import CategoryNav from "./CategoryNav/CategoryNav";
+import { getOnSaleInfo } from "../../features/onSale/onSaleSlice";
+import CategoryNav from "../OnSalePanel/CategoryNav/CategoryNav";
+import OnSaleProductCard from "../OnSalePanel/OnSaleProductCard/OnSaleProductCard";
+import OnSaleProductsGrid from "../OnSalePanel/OnSaleProductsGrid/OnSaleProductsGrid";
import css from "./OnSalePanel.module.less";
-import OnSaleProductCard from "./OnSaleProductCard/OnSaleProductCard";
-import OnSaleProductsGrid from "./OnSaleProductsGrid/OnSaleProductsGrid";
export default function OnSalePanel() {
const dispatch = useDispatch();
- const [currentLgCatCdIndex, setCurrentLgCatCdIndex] = useState(0);
- const [lgCatCd, setLgCatCd] = useState("");
- const [categoryInfos, setCategoryInfos] = useState([]);
- const [saleInfos, setSaleInfos] = useState([]);
- const [saleProductInfos, setSaleProductInfos] = useState([]);
+ const categoryInfos = useSelector((state) => state.onSale.onSaleData.categoryInfos);
+ const saleInfos = useSelector((state) => state.onSale.onSaleData.saleInfos);
- const handleCategoryNav = (lgCatCd, index) => {
- if (currentLgCatCdIndex === index) {
+ const [currentLgCatCd, setCurrentLgCatCd] = useState();
+
+ const handleCategoryNav = (lgCatCd) => {
+ if (currentLgCatCd === lgCatCd) {
return;
}
- setCurrentLgCatCdIndex(index);
- setLgCatCd(lgCatCd);
- };
- const getOnSaleInfoData = async (lgCatCd) => {
- try {
- const onSaleInfoData = await getOnSaleInfo({
- lgCatCd,
- categoryIncFlag: "Y",
- });
- console.log("On Sale Data:", onSaleInfoData);
-
- if (onSaleInfoData) {
- if (lgCatCd === "") {
- setCategoryInfos(onSaleInfoData.categoryInfos);
- }
-
- setSaleInfos(onSaleInfoData.saleInfos);
-
- let saleProducts = [];
-
- for (let index = 0; index < onSaleInfoData.saleInfos.length; index++) {
- saleProducts.push(onSaleInfoData.saleInfos[index].saleProductInfos);
- }
-
- setSaleProductInfos(saleProducts);
- }
- } catch (error) {
- console.error("Error fetching on sale:", error);
- }
+ setCurrentLgCatCd(lgCatCd);
};
useEffect(() => {
- getOnSaleInfoData(lgCatCd);
- }, [lgCatCd, currentLgCatCdIndex]);
+ if (categoryInfos && !currentLgCatCd) {
+ const initialLgCatCd = categoryInfos[0].lgCatCd;
+ setCurrentLgCatCd(initialLgCatCd);
+ }
+ }, []);
+
+ useEffect(() => {
+ if (currentLgCatCd) {
+ dispatch(getOnSaleInfo({ categoryIncFlag: "Y", lgCatCd: currentLgCatCd }));
+ }
+ }, [currentLgCatCd]);
+
+ useEffect(() => {
+ console.log(categoryInfos);
+ console.log(saleInfos);
+ }, []);
return (
-
-
- {saleInfos.map(({ saleNm }, index) => {
- return (
-
- {saleProductInfos[index].map((saleProduct) => {
- return (
-
- );
- })}
-
- );
- })}
-
+
+ {saleInfos &&
+ saleInfos.map(({ saleNm, saleProductInfos }) => {
+ return (
+
+ {saleProductInfos.map((saleProduct) => {
+ return ;
+ })}
+
+ );
+ })}
+
);
}
diff --git a/com.twin.app.shoptime/src/views/OnSalePanel/OnSalePanel.module.less b/com.twin.app.shoptime/src/views/OnSalePanel/OnSalePanel.module.less
index 2f20d531..b7d3b2e5 100644
--- a/com.twin.app.shoptime/src/views/OnSalePanel/OnSalePanel.module.less
+++ b/com.twin.app.shoptime/src/views/OnSalePanel/OnSalePanel.module.less
@@ -2,8 +2,6 @@
@import "../../style/utils.module.less";
.container {
- font-family: @baseFont;
-
.onSaleProducts {
margin-top: 236px;
}