Skip to content
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
11 changes: 9 additions & 2 deletions src/api/auth/react-query/customHooks.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
import { useMutation } from '@tanstack/react-query';
import { showToast } from '@/components/toast/toast';
import { TOAST_MESSAGES } from '@/constants/messages/toast';
import { authClientAPI } from '../authClientAPI';
import { getUserInfo } from '@/features/auth/api/auth';

Expand All @@ -9,10 +10,16 @@ export function useEditInfoMutation() {
mutationFn: (formData: FormData) => authClientAPI.editInfo(formData),
onSuccess: () => {
getUserInfo();
showToast({ message: '프로필 수정이 완료되었습니다.', type: 'success' });
showToast({
message: TOAST_MESSAGES.SUCCESS.PROFILE_EDIT,
type: 'success',
});
},
onError: (error) => {
showToast({ message: '프로필 수정을 실패하였습니다', type: 'error' });
showToast({
message: TOAST_MESSAGES.ERROR.PROFILE_EDIT_FAILED,
type: 'error',
});
console.error(error);
},
});
Expand Down
16 changes: 13 additions & 3 deletions src/api/book-club/react-query/customHooks.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
import { useMutation, useQueryClient } from '@tanstack/react-query';
import { bookClubs } from './queries';
import { showToast } from '@/components/toast/toast';
import { TOAST_MESSAGES } from '@/constants/messages/toast';
import {
bookClubLikeAPI,
bookClubMainAPI,
Expand All @@ -25,7 +26,10 @@ export function useBookClubCreateMutation() {
});
},
onError: () => {
showToast({ message: '북클럽 생성에 실패했습니다.', type: 'error' });
showToast({
message: TOAST_MESSAGES.ERROR.CLUB_CREATE_FAILED,
type: 'error',
});
},
});
}
Expand Down Expand Up @@ -74,12 +78,18 @@ export function useWriteReview() {
queryClient.invalidateQueries({
queryKey: bookClubs.my()._ctx.reviews().queryKey,
});
showToast({ message: '리뷰 작성을 완료하였습니다', type: 'success' });
showToast({
message: TOAST_MESSAGES.SUCCESS.REVIEW_CREATE,
type: 'success',
});
},
onError: (error) => {
console.error(error);

showToast({ message: '리뷰 작성을 실패하였습니다.', type: 'error' });
showToast({
message: TOAST_MESSAGES.ERROR.REVIEW_CREATE_FAILED,
type: 'error',
});
},
});
}
Expand Down
45 changes: 45 additions & 0 deletions src/constants/messages/toast.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,45 @@
export const TOAST_MESSAGES = {
SUCCESS: {
// 인증 관련
LOGIN: '로그인에 성공했습니다.',
LOGOUT: '로그아웃되었습니다.',
SIGNUP: '회원가입이 완료되었습니다.',

// 프로필 관련
PROFILE_EDIT: '프로필 수정이 완료되었습니다.',

// 북클럽 관련
CLUB_CREATE: '북클럽이 생성되었습니다.',
CLUB_JOIN: '참여 완료! 함께하게 돼서 기뻐요🥰',
CLUB_CANCEL: '모임을 취소하였습니다.',
CLUB_LEAVE: '모임 참여를 취소하였습니다.',
CLUB_DELETE: '취소된 모임을 삭제하였습니다.',
CLUB_LIKE: '찜 완료! 찜한 모임은 찜 목록 페이지에서 확인하세요',
CLUB_UNLIKE: '찜이 취소되었습니다',

// 리뷰 관련
REVIEW_CREATE: '리뷰 작성을 완료하였습니다',
},

ERROR: {
// 인증 관련
LOGIN_FAILED: '로그인에 실패했습니다.',
LOGOUT_FAILED: '로그아웃에 실패했습니다.',

// 프로필 관련
PROFILE_EDIT_FAILED: '프로필 수정을 실패하였습니다',

// 북클럽 관련
CLUB_CREATE_FAILED: '북클럽 생성에 실패했습니다.',
CLUB_JOIN_FAILED: '참여 요청 중 문제가 발생했습니다. 다시 시도해주세요.',
CLUB_CANCEL_FAILED: '모임 취소를 실패하였습니다.',
CLUB_LEAVE_FAILED: '모임 참여 취소를 실패하였습니다.',

// 리뷰 관련
REVIEW_CREATE_FAILED: '리뷰 작성을 실패하였습니다.',
REVIEW_VALIDATION: '점수와 리뷰 내용을 입력해주세요',

// 일반 에러
UNKNOWN: '알 수 없는 오류가 발생했습니다.',
},
} as const;
5 changes: 3 additions & 2 deletions src/features/club-details/hooks/useJoinClub.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
import { useJoinBookClub } from '@/api/book-club/react-query';
import { showToast } from '@/components/toast/toast';
import { TOAST_MESSAGES } from '@/constants/messages/toast';

export const useJoinClub = () => {
const { mutate: joinClub } = useJoinBookClub();
Expand All @@ -8,7 +9,7 @@ export const useJoinClub = () => {
joinClub(clubId, {
onSuccess: () => {
showToast({
message: '참여 완료! 함께하게 돼서 기뻐요🥰',
message: TOAST_MESSAGES.SUCCESS.CLUB_JOIN,
type: 'success',
});
},
Expand All @@ -20,7 +21,7 @@ export const useJoinClub = () => {
});
} else {
showToast({
message: '참여 요청 중 문제가 발생했습니다. 다시 시도해주세요.',
message: TOAST_MESSAGES.ERROR.CLUB_JOIN_FAILED,
type: 'error',
});
}
Expand Down
12 changes: 8 additions & 4 deletions src/features/profile/container/MyJoinedClubList.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@ import {
useWriteReview,
} from '@/api/book-club/react-query';
import { showToast } from '@/components/toast/toast';
import { TOAST_MESSAGES } from '@/constants/messages/toast';
import { BookClub } from '@/types/bookclubs';
import Loading from '@/components/loading/Loading';
import { useAuthStore } from '@/store/authStore';
Expand Down Expand Up @@ -58,7 +59,7 @@ export default function MyJoinedClubList({ order }: ClubListProps) {
const res = await leaveClub(clubId);
if (res) {
showToast({
message: '취소된 모임을 삭제하였습니다.',
message: TOAST_MESSAGES.SUCCESS.CLUB_DELETE,
type: 'success',
});
}
Expand All @@ -80,7 +81,10 @@ export default function MyJoinedClubList({ order }: ClubListProps) {
const onConfirmReview = (rating: number, content: string) => {
//TODO: 토스트 메시지가 뜨더라도 모달이 열린 상태로 유지되도록 수정
if (!rating || !content) {
showToast({ message: '점수와 리뷰 내용을 입력해주세요', type: 'error' });
showToast({
message: TOAST_MESSAGES.ERROR.REVIEW_VALIDATION,
type: 'error',
});
return;
}

Expand All @@ -97,14 +101,14 @@ export default function MyJoinedClubList({ order }: ClubListProps) {
const res = await leaveClub(selectedClubId);
if (res) {
showToast({
message: '모임 참여를 취소하였습니다.',
message: TOAST_MESSAGES.SUCCESS.CLUB_LEAVE,
type: 'success',
});
}
}
} catch (error) {
showToast({
message: '모임 참여를 취소를 실패하였습니다.',
message: TOAST_MESSAGES.ERROR.CLUB_LEAVE_FAILED,
type: 'error',
});
console.error(error);
Expand Down
5 changes: 3 additions & 2 deletions src/lib/hooks/useCancelClub.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
import { useCancelBookClub } from '@/api/book-club/react-query';
import { showToast } from '@/components/toast/toast';
import { TOAST_MESSAGES } from '@/constants/messages/toast';
import { useState } from 'react';

export function useCancelClub() {
Expand Down Expand Up @@ -29,14 +30,14 @@ export function useCancelClub() {
const res = await cancelClub(popUpState.selectedClubId);
if (res) {
showToast({
message: '모임을 취소하였습니다.',
message: TOAST_MESSAGES.SUCCESS.CLUB_CANCEL,
type: 'success',
});
}
}
} catch (error) {
showToast({
message: '모임 취소를 실패하였습니다.',
message: TOAST_MESSAGES.ERROR.CLUB_CANCEL_FAILED,
type: 'error',
});
console.error(error);
Expand Down
8 changes: 6 additions & 2 deletions src/lib/hooks/useLeaveClub.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
import { useLeaveBookClub } from '@/api/book-club/react-query';
import { showToast } from '@/components/toast/toast';
import { TOAST_MESSAGES } from '@/constants/messages/toast';
import { useState } from 'react';

export const useLeaveClub = () => {
Expand All @@ -26,14 +27,17 @@ export const useLeaveClub = () => {
try {
if (popUpState.selectedClubId) {
await leaveClub(popUpState.selectedClubId);
showToast({ message: '모임 참여를 취소하였습니다.', type: 'success' });
showToast({
message: TOAST_MESSAGES.SUCCESS.CLUB_LEAVE,
type: 'success',
});
}
} catch (error) {
if (error instanceof Error) {
showToast({ message: error.message, type: 'error' });
} else {
showToast({
message: '알 수 없는 오류가 발생했습니다.',
message: TOAST_MESSAGES.ERROR.UNKNOWN,
type: 'error',
});
}
Expand Down
5 changes: 3 additions & 2 deletions src/lib/hooks/useLikeClub.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
import { useLikeBookClub } from '@/api/book-club/react-query';
import { showToast } from '@/components/toast/toast';
import { TOAST_MESSAGES } from '@/constants/messages/toast';

export const useLikeClub = () => {
const { mutate: likeClub } = useLikeBookClub();
Expand All @@ -8,7 +9,7 @@ export const useLikeClub = () => {
likeClub(selectedClubId, {
onSuccess: () => {
showToast({
message: '찜 완료! 찜한 모임은 찜 목록 페이지에서 확인하세요',
message: TOAST_MESSAGES.SUCCESS.CLUB_LIKE,
type: 'success',
});
},
Expand All @@ -23,7 +24,7 @@ export const useLikeClub = () => {
message:
error instanceof Error
? error.message
: '알 수 없는 오류가 발생했습니다. 다시 시도해주세요.',
: TOAST_MESSAGES.ERROR.UNKNOWN,
type: 'error',
});
}
Expand Down
5 changes: 3 additions & 2 deletions src/lib/hooks/useUnLikeClub.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
import { useUnLikeBookClub } from '@/api/book-club/react-query';
import { showToast } from '@/components/toast/toast';
import { TOAST_MESSAGES } from '@/constants/messages/toast';

export const useUnLikeClub = () => {
const { mutate: unLikeClub } = useUnLikeBookClub();
Expand All @@ -8,7 +9,7 @@ export const useUnLikeClub = () => {
unLikeClub(selectedClubId, {
onSuccess: () => {
showToast({
message: '찜이 취소되었습니다',
message: TOAST_MESSAGES.SUCCESS.CLUB_UNLIKE,
type: 'success',
});
},
Expand All @@ -23,7 +24,7 @@ export const useUnLikeClub = () => {
message:
error instanceof Error
? error.message
: '알 수 없는 오류가 발생했습니다. 다시 시도해주세요.',
: TOAST_MESSAGES.ERROR.UNKNOWN,
type: 'error',
});
}
Expand Down
Loading