Skip to content

Commit 2970588

Browse files
committed
fix: fix search item
1 parent 9081cab commit 2970588

File tree

3 files changed

+51
-30
lines changed

3 files changed

+51
-30
lines changed

src/pages/price/PriceCategorySearchPage.jsx

+17-10
Original file line numberDiff line numberDiff line change
@@ -63,6 +63,11 @@ function PriceCategorySearchPage() {
6363
const [searchResults, setSearchResults] = useState([]);
6464
const { token } = useUser();
6565

66+
const currentDate = new Date();
67+
const currentYear = currentDate.getFullYear();
68+
const currentMonth = String(currentDate.getMonth() + 1).padStart(2, "0"); // 현재 월 (0부터 시작하므로 +1)
69+
const currentSuffix = `_${currentYear}${currentMonth}`;
70+
6671
const handleCategorySelect = (categoryId) => {
6772
setSelectedCategoryId(categoryId);
6873
};
@@ -109,16 +114,18 @@ function PriceCategorySearchPage() {
109114
</Wrapper>
110115
<PriceWrapper>
111116
{Array.isArray(searchResults.products) &&
112-
searchResults.products.map((item) => (
113-
<PriceItem
114-
key={item.product_id}
115-
product_id={item.product_id}
116-
product_name={item.product_name}
117-
current_month_price={item.current_month_price}
118-
previous_month_price={item.previous_month_price}
119-
previous_two_months_price={item.previous_two_months_price}
120-
/>
121-
))}
117+
searchResults.products
118+
.filter((item) => item.product_id.endsWith(currentSuffix)) // 현재 달 데이터만 필터링
119+
.map((item) => (
120+
<PriceItem
121+
key={item.product_id}
122+
product_id={item.product_id} // product_id 수정 불필요
123+
product_name={item.product_name}
124+
current_month_price={item.current_month_price}
125+
previous_month_price={item.previous_month_price}
126+
previous_two_months_price={item.previous_two_months_price}
127+
/>
128+
))}
122129
</PriceWrapper>
123130
</Container>
124131
);

src/pages/price/PriceMainPage.jsx

+17-10
Original file line numberDiff line numberDiff line change
@@ -63,6 +63,11 @@ function PriceMainPage() {
6363
const navigate = useNavigate();
6464
const { user, token } = useUser();
6565

66+
const currentDate = new Date();
67+
const currentYear = currentDate.getFullYear();
68+
const currentMonth = String(currentDate.getMonth() + 1).padStart(2, "0"); // 현재 월 (0부터 시작하므로 +1)
69+
const currentSuffix = `_${currentYear}${currentMonth}`;
70+
6671
useEffect(() => {
6772
const fetchPrice = async () => {
6873
if (!user) {
@@ -120,16 +125,18 @@ function PriceMainPage() {
120125
</Wrapper>
121126
<PriceWrapper>
122127
{Array.isArray(price.products) &&
123-
price.products.map((item) => (
124-
<PriceItem
125-
key={item.product_id}
126-
product_id={item.product_id}
127-
product_name={item.product_name}
128-
current_month_price={item.current_month_price}
129-
previous_month_price={item.previous_month_price}
130-
previous_two_months_price={item.previous_two_months_price}
131-
/>
132-
))}
128+
price.products
129+
.filter((item) => item.product_id.endsWith(currentSuffix)) // 현재 달 데이터만 필터링
130+
.map((item) => (
131+
<PriceItem
132+
key={item.product_id}
133+
product_id={item.product_id} // product_id 수정 불필요
134+
product_name={item.product_name}
135+
current_month_price={item.current_month_price}
136+
previous_month_price={item.previous_month_price}
137+
previous_two_months_price={item.previous_two_months_price}
138+
/>
139+
))}
133140
</PriceWrapper>
134141
</Container>
135142
);

src/pages/price/PriceNameSearchPage.jsx

+17-10
Original file line numberDiff line numberDiff line change
@@ -61,6 +61,11 @@ function PriceNameSearchPage() {
6161
const [searchResults, setSearchResults] = useState([]);
6262
const { token } = useUser();
6363

64+
const currentDate = new Date();
65+
const currentYear = currentDate.getFullYear();
66+
const currentMonth = String(currentDate.getMonth() + 1).padStart(2, "0"); // 현재 월 (0부터 시작하므로 +1)
67+
const currentSuffix = `_${currentYear}${currentMonth}`;
68+
6469
const handleSearch = async (name) => {
6570
try {
6671
const response = await fetch(
@@ -93,16 +98,18 @@ function PriceNameSearchPage() {
9398
</Wrapper>
9499
<PriceWrapper>
95100
{Array.isArray(searchResults.products) &&
96-
searchResults.products.map((item) => (
97-
<PriceItem
98-
key={item.product_id}
99-
product_id={item.product_id}
100-
product_name={item.product_name}
101-
current_month_price={item.current_month_price}
102-
previous_month_price={item.previous_month_price}
103-
previous_two_months_price={item.previous_two_months_price}
104-
/>
105-
))}
101+
searchResults.products
102+
.filter((item) => item.product_id.endsWith(currentSuffix)) // 현재 달 데이터만 필터링
103+
.map((item) => (
104+
<PriceItem
105+
key={item.product_id}
106+
product_id={item.product_id} // product_id 수정 불필요
107+
product_name={item.product_name}
108+
current_month_price={item.current_month_price}
109+
previous_month_price={item.previous_month_price}
110+
previous_two_months_price={item.previous_two_months_price}
111+
/>
112+
))}
106113
</PriceWrapper>
107114
</Container>
108115
);

0 commit comments

Comments
 (0)