Detail Notes : 1. features/onsaleController/onSaleSlice.js 생성 및 logic 추가 (store 추가완료) 2. OnSalePanel.jsx, CategoryNav.jsx logic 및 props 변경 3. api/apiConfig.js brand-controller URLS 추가 P.S : api/onSaleApi.js 파일은 현재 다른 곳에서 사용중이라 해당 commit에서는 삭제하지 않았습니다.
68 lines
2.0 KiB
JavaScript
68 lines
2.0 KiB
JavaScript
import React, { useEffect, useState } from "react";
|
|
|
|
import { useDispatch, useSelector } from "react-redux";
|
|
|
|
import TPanel from "../../components/TPanel/TPanel";
|
|
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";
|
|
|
|
export default function OnSalePanel() {
|
|
const dispatch = useDispatch();
|
|
|
|
const categoryInfos = useSelector((state) => state.onSale.onSaleData.categoryInfos);
|
|
const saleInfos = useSelector((state) => state.onSale.onSaleData.saleInfos);
|
|
|
|
const [currentLgCatCd, setCurrentLgCatCd] = useState();
|
|
|
|
const handleCategoryNav = (lgCatCd) => {
|
|
if (currentLgCatCd === lgCatCd) {
|
|
return;
|
|
}
|
|
|
|
setCurrentLgCatCd(lgCatCd);
|
|
};
|
|
|
|
useEffect(() => {
|
|
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 (
|
|
<TPanel className={css.container}>
|
|
<CategoryNav
|
|
categoryInfos={categoryInfos}
|
|
currentLgCatCd={currentLgCatCd}
|
|
onCategoryNavClick={handleCategoryNav}
|
|
/>
|
|
<div className={css.onSaleProducts}>
|
|
{saleInfos &&
|
|
saleInfos.map(({ saleNm, saleProductInfos }) => {
|
|
return (
|
|
<OnSaleProductsGrid key={saleNm} saleNm={saleNm}>
|
|
{saleProductInfos.map((saleProduct) => {
|
|
return <OnSaleProductCard key={saleProduct.prdtId} saleProduct={saleProduct} />;
|
|
})}
|
|
</OnSaleProductsGrid>
|
|
);
|
|
})}
|
|
</div>
|
|
</TPanel>
|
|
);
|
|
}
|