Skip to content

Commit 2a1ec4c

Browse files
authored
Merge pull request #211 from DevKor-github/fix/#23/pick
fix: ꡬ맀 μ‹œ 달λ ₯ 선택 μ•ˆλ˜λŠ” 버그, feat: μ—λŸ¬ 핸듀링
2 parents 2d66e1e + 730c48c commit 2a1ec4c

18 files changed

Lines changed: 114 additions & 22 deletions

File tree

β€Žsrc/common/apis/usePatchFCMToken.tsβ€Ž

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
import { useMutation } from '@tanstack/react-query';
22

33
import client from '@/common/utils/client';
4+
import { useHandleError } from '@/common/hooks/useHandleError';
45

56
const patchFCMToken = async (token: string) => {
67
const response = await client.patch('/api/v1/user/fcm-token', token, {
@@ -12,7 +13,9 @@ const patchFCMToken = async (token: string) => {
1213
};
1314

1415
export const usePatchFCMToken = () => {
16+
const handleError = useHandleError();
1517
return useMutation({
1618
mutationFn: patchFCMToken,
19+
onError: error => handleError(error, 'ν‘Έμ‹œ μ•Œλ¦Ό 섀정에 μ‹€νŒ¨ν–ˆμ–΄μš”'),
1720
});
1821
};
Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
1+
import { useToast } from '@/common/hooks/useToast';
2+
import type { ErrorResponse } from '@/libs/types';
3+
import { isAxiosError } from 'axios';
4+
5+
export const useHandleError = () => {
6+
const { openToast } = useToast();
7+
8+
const handleError = (error: Error, customMessage?: string) => {
9+
if (isAxiosError<ErrorResponse>(error)) {
10+
openToast({
11+
message: error.response?.data.message || customMessage || 'μ•Œ 수 μ—†λŠ” 였λ₯˜κ°€ λ°œμƒν–ˆμŠ΅λ‹ˆλ‹€',
12+
});
13+
}
14+
};
15+
16+
return handleError;
17+
};

β€Žsrc/features/chatList/api/usePatchExit.tsβ€Ž

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,4 @@
1+
import { useHandleError } from '@/common/hooks/useHandleError';
12
import { useToast } from '@/common/hooks/useToast';
23
import client from '@/common/utils/client';
34
import { QUERY_KEYS } from '@/libs/queryKeys';
@@ -18,6 +19,7 @@ const patchExit = async (chatRoomId: number) => {
1819

1920
export const usePatchExit = () => {
2021
const queryClient = useQueryClient();
22+
const handleError = useHandleError();
2123
const { openToast } = useToast();
2224

2325
return useMutation<ExitResponse, AxiosError<ExitResponse>, number, unknown>({
@@ -27,9 +29,6 @@ export const usePatchExit = () => {
2729
queryClient.invalidateQueries({ queryKey: [QUERY_KEYS.CHAT_LIST] });
2830
openToast({ message: 'μ±„νŒ…λ°©μ—μ„œ 퇴μž₯ν–ˆμ–΄μš”' });
2931
},
30-
onError: () => {
31-
openToast({ message: '퇴μž₯에 μ‹€νŒ¨ν–ˆμ–΄μš”. λ‹€μ‹œ μ‹œλ„ν•΄μ£Όμ„Έμš”!' });
32-
// console.error('퇴μž₯ μ‹€νŒ¨', error);
33-
},
32+
onError: error => handleError(error, '퇴μž₯에 μ‹€νŒ¨ν–ˆμ–΄μš”. λ‹€μ‹œ μ‹œλ„ν•΄μ£Όμ„Έμš”!'),
3433
});
3534
};

β€Žsrc/features/detail/apis/useDeleteItem.tsβ€Ž

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,4 @@
1+
import { useHandleError } from '@/common/hooks/useHandleError';
12
import client from '@/common/utils/client';
23
import { QUERY_KEYS } from '@/libs/queryKeys';
34
import { useMutation, useQueryClient } from '@tanstack/react-query';
@@ -9,11 +10,13 @@ const deleteItem = async (itemId: number) => {
910

1011
export const useDeleteItem = () => {
1112
const queryClient = useQueryClient();
13+
const handleError = useHandleError();
1214

1315
return useMutation({
1416
mutationFn: deleteItem,
1517
onSuccess: () => {
1618
queryClient.invalidateQueries({ queryKey: [QUERY_KEYS.ITEM_LIST] });
1719
},
20+
onError: error => handleError(error, 'μ œν’ˆ μ‚­μ œμ— μ‹€νŒ¨ν–ˆμ–΄μš”'),
1821
});
1922
};

β€Žsrc/features/myEdit/apis/usePutUser.tsβ€Ž

Lines changed: 3 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
import { s3PutImageToUrl } from '@/common/apis/s3PutImageToUrl';
2-
import { useToast } from '@/common/hooks/useToast';
2+
import { useHandleError } from '@/common/hooks/useHandleError';
33
import client from '@/common/utils/client';
44
import { QUERY_KEYS } from '@/libs/queryKeys';
55
import type { Gender, UserInterface } from '@/libs/types/user';
@@ -32,15 +32,13 @@ const putUser = async ({ userData, fileData }: { userData: UserPayload; fileData
3232

3333
export const usePutUser = () => {
3434
const queryClient = useQueryClient();
35-
const { openToast } = useToast();
35+
const handleError = useHandleError();
3636

3737
return useMutation({
3838
mutationFn: putUser,
3939
onSuccess: () => {
4040
queryClient.invalidateQueries({ queryKey: [QUERY_KEYS.USER] });
4141
},
42-
onError: () => {
43-
openToast({ message: 'μœ μ € 정보 μˆ˜μ •μ— μ‹€νŒ¨ν–ˆμ–΄μš”. λ‹€μ‹œ μ‹œλ„ν•΄μ£Όμ„Έμš”!' });
44-
},
42+
onError: error => handleError(error, 'μœ μ € 정보 μˆ˜μ •μ— μ‹€νŒ¨ν–ˆμ–΄μš”. λ‹€μ‹œ μ‹œλ„ν•΄μ£Όμ„Έμš”!'),
4543
});
4644
};
Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
1+
import client from '@/common/utils/client';
2+
import { QUERY_KEYS } from '@/libs/queryKeys';
3+
import { useQuery } from '@tanstack/react-query';
4+
5+
interface GetSaleAvailabilityResponse {
6+
message: string;
7+
data: string;
8+
}
9+
const getSaleAvailability = async (itemId: number) => {
10+
const response = await client.get<GetSaleAvailabilityResponse>(`/api/v1/item/${itemId}/sale-availability`);
11+
return response.data.data;
12+
};
13+
14+
export const useGetSaleAvailability = (itemId: number) => {
15+
return useQuery({
16+
queryKey: [QUERY_KEYS.SALE_AVAILABILITY, itemId],
17+
queryFn: () => getSaleAvailability(itemId),
18+
});
19+
};

β€Žsrc/features/pick/apis/usePatchAppointment.tsβ€Ž

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,4 @@
1+
import { useHandleError } from '@/common/hooks/useHandleError';
12
import client from '@/common/utils/client';
23
import { QUERY_KEYS } from '@/libs/queryKeys';
34
import type { TradeMethods } from '@/libs/types/item';
@@ -14,18 +15,20 @@ interface PatchAppointmentRequest {
1415
tradeMethod: TradeMethods;
1516
}
1617

17-
// TODO: url μˆ˜μ •!!!!
1818
const patchAppointment = async (data: PatchAppointmentRequest) => {
1919
const response = await client.patch('/api/v1/appointment', data);
2020
return response.data.data;
2121
};
2222

2323
export const usePatchAppointment = () => {
2424
const queryClient = useQueryClient();
25+
const handleError = useHandleError();
26+
2527
return useMutation({
2628
mutationFn: patchAppointment,
2729
onSuccess: () => {
2830
queryClient.invalidateQueries({ queryKey: [QUERY_KEYS.PICK_DETAIL] });
2931
},
32+
onError: error => handleError(error, 'PICK μˆ˜μ •μ— μ‹€νŒ¨ν–ˆμ–΄μš”'),
3033
});
3134
};

β€Žsrc/features/pick/apis/usePatchCancelPick.tsβ€Ž

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,4 @@
1+
import { useHandleError } from '@/common/hooks/useHandleError';
12
import client from '@/common/utils/client';
23
import { QUERY_KEYS } from '@/libs/queryKeys';
34
import { useMutation, useQueryClient } from '@tanstack/react-query';
@@ -8,11 +9,14 @@ const patchCancelPick = async (id: number) => {
89
};
910
export const usePatchCancelPick = () => {
1011
const queryClient = useQueryClient();
12+
const handleError = useHandleError();
13+
1114
return useMutation({
1215
mutationFn: patchCancelPick,
1316
onSuccess: () => {
1417
queryClient.invalidateQueries({ queryKey: [QUERY_KEYS.PICK_DETAIL] });
1518
queryClient.invalidateQueries({ queryKey: [QUERY_KEYS.ITEM_STATUS] });
1619
},
20+
onError: error => handleError(error, 'PICK μ·¨μ†Œμ— μ‹€νŒ¨ν–ˆμ–΄μš”'),
1721
});
1822
};

β€Žsrc/features/pick/apis/usePatchConfirmPick.tsβ€Ž

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,4 @@
1+
import { useHandleError } from '@/common/hooks/useHandleError';
12
import client from '@/common/utils/client';
23
import { QUERY_KEYS } from '@/libs/queryKeys';
34
import { useMutation, useQueryClient } from '@tanstack/react-query';
@@ -9,11 +10,14 @@ const patchConfirmPick = async (id: number) => {
910

1011
export const usePatchConfirmPick = () => {
1112
const queryClient = useQueryClient();
13+
const handleError = useHandleError();
14+
1215
return useMutation({
1316
mutationFn: patchConfirmPick,
1417
onSuccess: () => {
1518
queryClient.invalidateQueries({ queryKey: [QUERY_KEYS.PICK_DETAIL] });
1619
queryClient.invalidateQueries({ queryKey: [QUERY_KEYS.ITEM_STATUS] });
1720
},
21+
onError: error => handleError(error, 'PICK 확정에 μ‹€νŒ¨ν–ˆμ–΄μš”'),
1822
});
1923
};

β€Žsrc/features/pick/apis/usePostRentalAppointment.tsβ€Ž

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@ import { useMutation } from '@tanstack/react-query';
22
import client from '@/common/utils/client';
33
import type { PostAppointmentResponse } from '@/features/pick/apis/usePostSaleAppointment';
44
import type { TradeMethods } from '@/libs/types/item';
5+
import { useHandleError } from '@/common/hooks/useHandleError';
56

67
interface PostRentalAppointmentRequest {
78
itemId: number;
@@ -18,7 +19,10 @@ const postRentalAppointment = async (data: PostRentalAppointmentRequest) => {
1819
return response.data.data;
1920
};
2021
export const usePostRentalAppointment = () => {
22+
const handleError = useHandleError();
23+
2124
return useMutation({
2225
mutationFn: postRentalAppointment,
26+
onError: error => handleError(error, 'PICK 생성에 μ‹€νŒ¨ν–ˆμ–΄μš”'),
2327
});
2428
};

0 commit comments

Comments
Β (0)