Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Hotfix: 내 예약 리스트 조회 API 추상화 수정, 초기 데이터 값이 있을 경우에만 실행되도록 조건문 추가 #222

Merged
merged 2 commits into from
Mar 28, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
9 changes: 2 additions & 7 deletions src/apis/myReservations.ts
Original file line number Diff line number Diff line change
@@ -1,15 +1,12 @@
import { MY_RESERVATIONS_API, DEFAULT_PAGE_SIZE, REVIEWS_API } from '@/constants';

import { MyReservationsStatus } from '@/types';

import instance from './axios';

export const MyReservations = {
get: (status: MyReservationsStatus) =>
get: () =>
instance.get(MY_RESERVATIONS_API, {
params: {
size: DEFAULT_PAGE_SIZE,
status,
},
}),

Expand All @@ -18,9 +15,7 @@ export const MyReservations = {
status: 'canceled',
}),

createReview: (newReview: { reservationId: number; value: object }) => {
const { reservationId } = newReview;
const { value } = newReview;
createReview: ({ reservationId, value }: { reservationId: number; value: object }) => {
return instance.post(`${MY_RESERVATIONS_API}/${reservationId}${REVIEWS_API}`, value);
},
};
22 changes: 12 additions & 10 deletions src/hooks/useFilteredDataList.ts
Original file line number Diff line number Diff line change
Expand Up @@ -20,20 +20,22 @@ const useFilteredDataList = <T>({ initialDataList, selectFilter, searchFilter }:
const [totalCount, setTotalCount] = useState(0);

useEffect(() => {
let newDataList = [...initialDataList];
if (initialDataList) {
let newDataList = [...initialDataList];

for (const selectKey in selectFilter) {
if (selectFilter[selectKey] !== 'all') {
newDataList = newDataList.filter((data) => data[selectKey] === selectFilter[selectKey]);
for (const selectKey in selectFilter) {
if (selectFilter[selectKey] !== 'all') {
newDataList = newDataList.filter((data) => data[selectKey] === selectFilter[selectKey]);
}
}
}

for (const searchKey in searchFilter) {
newDataList = newDataList.filter((data) => String(data[searchKey]).includes(String(searchFilter[searchKey])));
}
for (const searchKey in searchFilter) {
newDataList = newDataList.filter((data) => String(data[searchKey]).includes(String(searchFilter[searchKey])));
}

setFilteredDataList(newDataList);
setTotalCount(newDataList.length);
setFilteredDataList(newDataList);
setTotalCount(newDataList.length);
}
}, [initialDataList, selectFilter, searchFilter]);

return {
Expand Down