Skip to content

Commit be94aab

Browse files
committed
Merge branch 'dev' into Feat/FeedPage
2 parents f708721 + da4cb80 commit be94aab

File tree

12 files changed

+170
-175
lines changed

12 files changed

+170
-175
lines changed

components/ui/DatePicker/Date.tsx

+1-1
Original file line numberDiff line numberDiff line change
@@ -26,7 +26,7 @@ export default function Date({
2626
<div className="flex gap-1 caption1">
2727
<span>{format(selectedDate, 'MMM yyyy')}</span>
2828
<button type="button" onClick={onChangePickerType}>
29-
<CaretDownIcon />
29+
<CaretDownIcon className="w-4 h-4" />
3030
</button>
3131
</div>
3232
<div className="flex gap-2">

components/ui/DatePicker/Month.tsx

+1-1
Original file line numberDiff line numberDiff line change
@@ -27,7 +27,7 @@ export default function Month({
2727
<span className="flex gap-1 caption1">
2828
{format(selectedDate, 'yyyy')}
2929
<button type="button" onClick={onChangePickerType}>
30-
<CaretDownIcon />
30+
<CaretDownIcon className="w-4 h-4" />
3131
</button>
3232
</span>
3333
<div>

components/ui/Modal/AddChatRoomModal/index.tsx

+9-6
Original file line numberDiff line numberDiff line change
@@ -42,7 +42,7 @@ export default function AddChatRoomModal({ open, onClose }: ModalProps) {
4242
const { name, description } = data;
4343
setIsLoading(true);
4444
try {
45-
const response = await postChatRoom({
45+
const { chatroomId } = await postChatRoom({
4646
image: imageFile as File,
4747
body: {
4848
name,
@@ -52,23 +52,26 @@ export default function AddChatRoomModal({ open, onClose }: ModalProps) {
5252
locationLimit: true,
5353
},
5454
});
55-
if (response.chatroomId) {
55+
if (chatroomId) {
5656
Toast.success('채팅룸 오픈! 🦊');
57-
router.push(`/chat/${response.chatroomId}`);
58-
} else {
59-
throw new Error(response.message);
57+
router.push(`/chat/${chatroomId}`);
6058
}
6159
} catch (error) {
62-
console.error(error);
60+
if (error instanceof Error) Toast.error(error.message);
6361
} finally {
6462
setIsLoading(false);
6563
}
6664
};
6765
const onSubmit: SubmitHandler<FormData> = (data) => {
66+
const LIMIT_IMAGE_SIZE = 2097152;
6867
if (!imageFile) {
6968
Toast.error('커버이미지를 업로드 해주세요. 🐈');
7069
return;
7170
}
71+
if (imageFile.size > LIMIT_IMAGE_SIZE) {
72+
Toast.error('2MB 이상 이미지는 업로드할 수 없어요.');
73+
return;
74+
}
7275
onCreateChatRoom(data);
7376
};
7477
return (

components/ui/Modal/ImageUploadModal/index.tsx

+7-1
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@ import { uploadChatImage } from '@/service/chatRoom';
55
import { useState } from 'react';
66
import LoadingIcon from '@/public/loading.svg';
77
import prettyBytes from 'pretty-bytes';
8+
import Toast from '@/utils/notification';
89
import Modal from '..';
910
import Button from '../../Button';
1011

@@ -21,13 +22,18 @@ export default function ImageUploadModal({
2122
const [isLoading, setIsLoading] = useState(false);
2223

2324
const handleUploadImage = async () => {
25+
const LIMIT_IMAGE_SIZE = 2097152;
26+
2427
try {
2528
if (imageFile) {
2629
setIsLoading(true);
30+
if (imageFile.size > LIMIT_IMAGE_SIZE) {
31+
throw new Error('2MB 이상 이미지는 업로드할 수 없어요.');
32+
}
2733
await uploadChatImage(roomId, imageFile);
2834
}
2935
} catch (error) {
30-
console.error(error);
36+
if (error instanceof Error) Toast.error(error.message);
3137
} finally {
3238
setIsLoading(false);
3339
onClose();

hooks/mutations/useCreateSchedule.ts

-3
Original file line numberDiff line numberDiff line change
@@ -19,9 +19,6 @@ export default function useCreateSchedule(closeModal: () => void) {
1919
closeModal();
2020
return queryClient.invalidateQueries([queryKeys.SCHEDULE_LIST]);
2121
},
22-
onError: (error: Error) => {
23-
Toast.error(error.message);
24-
},
2522
});
2623
return { mutate, isLoading };
2724
}

hooks/mutations/useDelegateRoomOwner.ts

+1-3
Original file line numberDiff line numberDiff line change
@@ -18,11 +18,9 @@ export default function useDelegateRoomOwner({
1818
delegateRoomOwner(roomId, userId),
1919
onSuccess: () => {
2020
Toast.success(`${user}님에게 방장을 넘겨주었어요.🐶`);
21-
modalClose();
2221
queryClient.invalidateQueries([queryKeys.CHATROOM_USER_LIST]);
2322
},
24-
onError: (error: Error) => {
25-
Toast.error(error.message);
23+
onSettled: () => {
2624
modalClose();
2725
},
2826
});

hooks/mutations/useDeleteSchedule.ts

-3
Original file line numberDiff line numberDiff line change
@@ -13,9 +13,6 @@ export default function useDeleteSchedule() {
1313
Toast.success('스케줄을 삭제했어요. 🐹');
1414
return queryClient.invalidateQueries([queryKeys.SCHEDULE_LIST]);
1515
},
16-
onError: (error: Error) => {
17-
Toast.error(error.message);
18-
},
1916
});
2017
return { mutate };
2118
}

hooks/mutations/useInviteUserToChatroom.ts

-1
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,6 @@ export default function useInviteUserToChatroom(successCb: () => void) {
2222
refetchType: 'all',
2323
});
2424
},
25-
onError: () => Toast.error('잠시후 다시 시도해주세요.'),
2625
});
2726
return { mutate };
2827
}

hooks/mutations/useJoinSchedule.ts

-3
Original file line numberDiff line numberDiff line change
@@ -12,9 +12,6 @@ export default function useJoinSchedule() {
1212
onSuccess: () => {
1313
Toast.success('스케줄에 참여하였습니다.🐾');
1414
},
15-
onError: (error: Error) => {
16-
Toast.error(error.message);
17-
},
1815
onSettled: () => queryClient.invalidateQueries([queryKeys.SCHEDULE_LIST]),
1916
});
2017
return { mutate, isLoading };

hooks/mutations/useWithdrawSchedule.ts

-3
Original file line numberDiff line numberDiff line change
@@ -13,9 +13,6 @@ export default function useWithdrawSchedule() {
1313
Toast.success('일정을 취소했어요. 🐾');
1414
return queryClient.invalidateQueries([queryKeys.SCHEDULE_LIST]);
1515
},
16-
onError: () => {
17-
Toast.error('일정취소를 실패했어요. 🥲 잠시후 다시 시도해주세요.');
18-
},
1916
});
2017
return { mutate };
2118
}

hooks/queries/ReactQueryProvider.tsx

+37-5
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,41 @@
1-
"use client";
1+
'use client';
22

3-
import { QueryClient, QueryClientProvider } from "@tanstack/react-query";
3+
import { AuthError } from '@/lib/error';
4+
import Toast from '@/utils/notification';
45

5-
const queryClient = new QueryClient();
6+
import {
7+
MutationCache,
8+
QueryCache,
9+
QueryClient,
10+
QueryClientProvider,
11+
} from '@tanstack/react-query';
612

7-
export default function ReactQueryProvider({ children }: { children: React.ReactNode }) {
8-
return <QueryClientProvider client={queryClient}>{children}</QueryClientProvider>;
13+
// 에러핸들링 함수 만약 에러클래스를 여러개 정의한다면 에러별로 공통된 에러핸들링을 정의할 수 있음.
14+
const handleError = (error: unknown) => {
15+
if (error instanceof Error) Toast.error(error.message);
16+
if (error instanceof AuthError) {
17+
Toast.error(error.message);
18+
window.location.assign(`/auth/login`);
19+
}
20+
};
21+
22+
const queryClient = new QueryClient({
23+
// useMutation 과 useQuery 훅의 에러를 한곳에서 공통적으로 처리할수 있도록 하였습니다.
24+
mutationCache: new MutationCache({
25+
onError: (error) => handleError(error),
26+
}),
27+
// useQuery의 onError callback 이 deprecated(더 이상 사용되지않음) 되었기 때문에 추가하였습니다. useQuery 훅이 작동할때 에러가 발생한다면 에러 토스트알림을 띄웁니다.
28+
queryCache: new QueryCache({
29+
onError: (error) => handleError(error),
30+
}),
31+
});
32+
33+
export default function ReactQueryProvider({
34+
children,
35+
}: {
36+
children: React.ReactNode;
37+
}) {
38+
return (
39+
<QueryClientProvider client={queryClient}>{children}</QueryClientProvider>
40+
);
941
}

0 commit comments

Comments
 (0)