Skip to content

Commit

Permalink
Merge pull request #855 from KEEPER31337/feature/에러_메세지_상수화_#846
Browse files Browse the repository at this point in the history
Feature/에러 메세지 상수화 #846
  • Loading branch information
mun-kyeong committed Dec 11, 2023
2 parents 343c0a4 + daab57e commit 34c3880
Show file tree
Hide file tree
Showing 9 changed files with 80 additions and 15 deletions.
9 changes: 5 additions & 4 deletions src/api/memberApi.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
import toast from 'react-hot-toast';
import { useQuery, useMutation, useQueryClient } from 'react-query';
import axios from 'axios';
import { PASSWORD } from '@constants/apiResponseMessage';
import { useApiError } from '@hooks/useGetApiError';
import { formatGeneration } from '@utils/converter';
import { ProfileInfo, MemberDetailInfo } from './dto';
Expand Down Expand Up @@ -123,7 +124,7 @@ const useEditEmailMutation = () => {
const { handleError } = useApiError({
400: {
default: () => {
toast.error('현재 비밀번호가 일치하지 않습니다.');
toast.error(PASSWORD.error.mismatch);
},
},
});
Expand All @@ -138,7 +139,7 @@ const useEditPasswordMutation = () => {
const { handleError } = useApiError({
400: {
default: () => {
toast.error('현재 비밀번호가 일치하지 않습니다.');
toast.error(PASSWORD.error.mismatch);
},
},
});
Expand All @@ -147,7 +148,7 @@ const useEditPasswordMutation = () => {

return useMutation(fetcher, {
onSuccess: () => {
toast.success('비밀번호가 변경되었습니다.');
toast.success(PASSWORD.success.changed);
},
onError: (err) => handleError(err, 400),
});
Expand All @@ -157,7 +158,7 @@ const useWithdrawalMutation = () => {
const { handleError } = useApiError({
400: {
default: () => {
toast.error('비밀번호가 일치하지 않습니다.');
toast.error(PASSWORD.error.mismatch);
},
},
});
Expand Down
7 changes: 4 additions & 3 deletions src/api/postApi.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ import toast from 'react-hot-toast';
import { useMutation, useQuery, useQueryClient } from 'react-query';
import { useLocation, useNavigate } from 'react-router-dom';
import axios, { AxiosError } from 'axios';
import { BOARD } from '@constants/apiResponseMessage';
import { useApiError } from '@hooks/useGetApiError';
import {
BoardPosts,
Expand Down Expand Up @@ -151,12 +152,12 @@ const useGetEachPostQuery = (
400: {
default: () => {
// TODO 페이지 문구로 띄워주기
toast.error('게시글 열람 조건을 충족하지 않습니다.');
toast.error(BOARD.error.readCondition);
},
},
403: {
40301: () => {
toast.error('게시글의 비밀번호가 일치하지 않습니다.');
toast.error(BOARD.error.mismatchPassword);
},
40302: () => {
// 비밀글 여부 true로 변경
Expand Down Expand Up @@ -226,7 +227,7 @@ const useDownloadFileMutation = () => {
},
onError: (error) => {
if ((error as AxiosError)?.response?.status === 400) {
toast.error('댓글 작성이 필요합니다.');
toast.error(BOARD.error.requiredComment);
}
},
});
Expand Down
3 changes: 2 additions & 1 deletion src/api/seminarApi.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
import { useQuery, useMutation, useQueryClient } from 'react-query';
import axios from 'axios';
import { DateTime } from 'luxon';
import { SEMINAR } from '@constants/apiResponseMessage';
import { useApiError } from '@hooks/useGetApiError';
import { AttendSeminarListInfo, SeminarStatus, SeminarInfo, SeminarCardInfo } from './dto';

Expand Down Expand Up @@ -143,7 +144,7 @@ const useAddSeminarMutation = ({ setHelperText }: { setHelperText: React.Dispatc
const { handleError } = useApiError({
409: {
40901: () => {
setHelperText('동일한 날짜의 세미나는 생성할 수 없습니다.');
setHelperText(SEMINAR.error.duplicateSeminarDate);
},
},
});
Expand Down
57 changes: 57 additions & 0 deletions src/constants/apiResponseMessage.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,57 @@
export const COMMON = {} as const;

export const PASSWORD = {
success: {
changed: '비밀번호가 변경되었습니다.',
},
error: {
mismatch: '현재 비밀번호가 일치하지 않습니다.',
},
} as const;

export const BOARD = {
success: {},
error: {
readCondition: '게시글 열람 조건을 충족하지 않습니다.',
mismatchPassword: '게시글의 비밀번호가 일치하지 않습니다.',
requiredComment: '댓글 작성이 필요합니다.',
},
} as const;

export const SEMINAR = {
success: {},
error: {
duplicateSeminarDate: '동일한 날짜의 세미나는 생성할 수 없습니다.',
},
} as const;

export const EMAIL = {
success: {
changed: '이메일 변경 성공하였습니다.',
},
error: {
existing: '이미 존재하는 이메일입니다.',
},
} as const;

export const MEMBER_CARD = {
success: {},
error: {
noSubmissionsLeft: '남은 제출 횟수가 없습니다.',
mismatchWithCount: (min: number) => `출석코드가 틀렸습니다. (남은 제출횟수 ${min}회)` as const,
},
} as const;

export const LOGIN_ID = {
success: {},
error: {
existing: '이미 존재하는 아이디입니다.',
},
};

export const STUDENT_ID = {
success: {},
error: {
existing: '이미 존재하는 학번입니다.',
},
};
5 changes: 3 additions & 2 deletions src/pages/Profile/Modal/EditAccountModal.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@ import {
useWithdrawalMutation,
} from '@api/memberApi';
import { useCheckEmailDuplicationQuery } from '@api/signUpApi';
import { EMAIL } from '@constants/apiResponseMessage';
import { COMMON, EMAIL_MSG, CONFIRM_PASSWORD_MSG } from '@constants/helperText';
import memberState from '@recoil/member.recoil';
import { emailRegex } from '@utils/validateEmail';
Expand Down Expand Up @@ -57,7 +58,7 @@ const EditEmailSection = () => {
{ email, auth, password },
{
onSuccess: () => {
toast.success('이메일 변경 성공하였습니다.');
toast.success(EMAIL.success.changed);
setIsEmailSent(false);
reset();
},
Expand All @@ -69,7 +70,7 @@ const EditEmailSection = () => {
if (!checkEmailDuplicationSuccess) return;

if (isEmailDuplicate.duplicate === true) {
setError('email', { message: '이미 존재하는 이메일입니다.' });
setError('email', { message: EMAIL.error.existing });
setIsEmailSent(false);
return;
}
Expand Down
3 changes: 2 additions & 1 deletion src/pages/SignUp/Section/SignUpFirstInputSection.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ import { VscCheck } from 'react-icons/vsc';
import { useSetRecoilState } from 'recoil';

import { signUpKeys, useCheckLoginIdDuplicationQuery } from '@api/signUpApi';
import { LOGIN_ID } from '@constants/apiResponseMessage';
import { COMMON, LOGIN_ID_MSG, CONFIRM_PASSWORD_MSG } from '@constants/helperText';
import FilledButton from '@components/Button/FilledButton';
import OutlinedButton from '@components/Button/OutlinedButton';
Expand Down Expand Up @@ -51,7 +52,7 @@ const SignUpFirstInputSection = ({ setCurrentStep }: SignUpFirstInputSectionProp
if (!isLoginIdDuplicate) return;

if (isLoginIdDuplicate.duplicate === true) {
setError('loginId', { message: '이미 존재하는 아이디입니다.' });
setError('loginId', { message: LOGIN_ID.error.existing });
setCheckLoginIdDuplicateEnabled(false);
}
}, [isLoginIdDuplicate]);
Expand Down
3 changes: 2 additions & 1 deletion src/pages/SignUp/Section/SignUpSecondInputSection.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ import { Stack } from '@mui/material';
import { VscCheck } from 'react-icons/vsc';
import { useSetRecoilState } from 'recoil';
import { signUpKeys, useCheckStudentIdDuplicationQuery } from '@api/signUpApi';
import { STUDENT_ID } from '@constants/apiResponseMessage';
import { COMMON, NAME_MSG } from '@constants/helperText';
import FilledButton from '@components/Button/FilledButton';
import OutlinedButton from '@components/Button/OutlinedButton';
Expand Down Expand Up @@ -57,7 +58,7 @@ const SignUpSecondInputSection = ({ setCurrentStep }: SignUpFirstInputSectionPro
if (!isStudentIdDuplicate) return;

if (isStudentIdDuplicate.duplicate === true) {
setError('studentId', { message: '이미 존재하는 학번입니다.' });
setError('studentId', { message: STUDENT_ID.error.existing });
setCheckStudentIdDuplicateEnabled(false);
}
}, [isStudentIdDuplicate]);
Expand Down
3 changes: 2 additions & 1 deletion src/pages/SignUp/Section/SignUpThirdInputSection.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ import { Stack, Typography } from '@mui/material';
import { DateTime } from 'luxon';
import { useRecoilValue } from 'recoil';
import { useCheckEmailDuplicationQuery, useEmailAuthMutation, useSignUpMutation } from '@api/signUpApi';
import { EMAIL } from '@constants/apiResponseMessage';
import { COMMON, EMAIL_MSG } from '@constants/helperText';
import { emailRegex } from '@utils/validateEmail';
import OutlinedButton from '@components/Button/OutlinedButton';
Expand Down Expand Up @@ -73,7 +74,7 @@ const SignUpThirdInputSection = () => {
if (!checkEmailDuplicationSuccess) return;

if (isEmailDuplicate.duplicate === true) {
setError('email', { message: '이미 존재하는 이메일입니다.' });
setError('email', { message: EMAIL.error.existing });
setIsEmailSent(false);
return;
}
Expand Down
5 changes: 3 additions & 2 deletions src/pages/senimarAttend/Card/MemberCardContent.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ import { DateTime } from 'luxon';
import { useRecoilState } from 'recoil';
import { SeminarStatus } from '@api/dto';
import { useAttendSeminarMutation, useGetAvailableSeminarInfoQuery, useGetSeminarInfoQuery } from '@api/seminarApi';
import { MEMBER_CARD } from '@constants/apiResponseMessage';
import FilledButton from '@components/Button/FilledButton';
import ConfirmModal from '@components/Modal/ConfirmModal';
import Countdown from '../Countdown/Countdown';
Expand Down Expand Up @@ -51,10 +52,10 @@ const MemberCardContent = ({ seminarId }: { seminarId: number }) => {

if (remainAttendCount <= 0) {
setExcessModalOpen(true);
setIncorrectCodeMsg('남은 제출 횟수가 없습니다.');
setIncorrectCodeMsg(MEMBER_CARD.error.noSubmissionsLeft);
return;
}
setIncorrectCodeMsg(`출석코드가 틀렸습니다. (남은 제출횟수 ${remainAttendCount}회)`);
setIncorrectCodeMsg(MEMBER_CARD.error.mismatchWithCount(remainAttendCount));
return;
}
const errorMessage = axiosError?.response?.data?.message;
Expand Down

0 comments on commit 34c3880

Please sign in to comment.