Skip to content

Commit

Permalink
Merge pull request #79 from DEPthes/dev
Browse files Browse the repository at this point in the history
Dev
  • Loading branch information
jisupark123 authored Aug 28, 2023
2 parents c5ac78a + a069ac4 commit 88b17d9
Show file tree
Hide file tree
Showing 15 changed files with 190 additions and 192 deletions.
1 change: 0 additions & 1 deletion apis/patchResetPassword.ts
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,6 @@ export async function patchResetPassword({
renewPassword,
});
if (!response.data.check) {
console.log('오류');
throw new IeumError(400);
}
return response;
Expand Down
4 changes: 1 addition & 3 deletions components/appQueryClientProvider.tsx
Original file line number Diff line number Diff line change
@@ -1,7 +1,5 @@
import useApiError from '@/hooks/custom/useApiError';
import { AxiosError } from 'axios';
import React, { useState } from 'react';
import { QueryCache, QueryClient, QueryClientProvider } from 'react-query';
import { QueryClient, QueryClientProvider } from 'react-query';

export default function AppQueryClientProvider({ children }: { children: React.ReactNode }) {
// next.js는 페이지 전환마다 _app.tsx가 렌더링되므로 queryClient가 재선언되지 않게 useState로 관리
Expand Down
15 changes: 7 additions & 8 deletions components/authEmail.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -34,8 +34,9 @@ export default function AuthEmail({ title, screenType, moveNextPage, setEmail }:
'normal',
);

const { handleApiError } = useApiError();

const checkEmailDuplicatedMutation = useMutation(getEmailDuplicated);
const { handleError: handleDefaultError } = useApiError();

// 인증번호 받아오기
const newSendAuthNumberMutation = useMutation(postSendAuthNumber);
Expand Down Expand Up @@ -94,7 +95,6 @@ export default function AuthEmail({ title, screenType, moveNextPage, setEmail }:
clearInterval(timer);
setAuthNumberIsValid('timeOver');
setTimerStarted(false);
console.log('타이머가 종료되었습니다.');
}

return () => {
Expand Down Expand Up @@ -141,11 +141,6 @@ export default function AuthEmail({ title, screenType, moveNextPage, setEmail }:
}
};

//에러처리 => 인증번호가 일치하지 않을 경우
const { handleError } = useApiError({
400: () => setAuthNumberIsValid('notIsValid'),
});

//인증번호 확인
const checkAuthNumberHandler = async () => {
newCheckAuthNumberMutation.mutate(
Expand All @@ -154,7 +149,11 @@ export default function AuthEmail({ title, screenType, moveNextPage, setEmail }:
onSuccess: (response) => {
checkAuthNumberSuccessHandler(response.data.check);
},
onError: (err) => handleError(err as AxiosError),

//에러처리 => 인증번호가 일치하지 않을 경우
onError: handleApiError({
400: () => setAuthNumberIsValid('notIsValid'),
}),
},
);
};
Expand Down
9 changes: 4 additions & 5 deletions components/pages/join/join-Email.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -67,7 +67,6 @@ const JoinEmail: React.FC<JoinEmailProps> = ({ joinChangeHandler }) => {
clearInterval(timer);
setAuthNumberIsValid('timeOver');
setTimerStarted(false);
console.log('타이머가 종료되었습니다.');
}

return () => {
Expand Down Expand Up @@ -112,9 +111,7 @@ const JoinEmail: React.FC<JoinEmailProps> = ({ joinChangeHandler }) => {
};

//에러처리 => 인증번호가 일치하지 않을 경우
const { handleError } = useApiError({
400: () => setAuthNumberIsValid('notIsValid'),
});
const { handleApiError } = useApiError();

//인증번호 확인
const checkAuthNumberHandler = async () => {
Expand All @@ -126,7 +123,9 @@ const JoinEmail: React.FC<JoinEmailProps> = ({ joinChangeHandler }) => {
onSuccess: (response) => {
checkAuthNumberSuccessHandler(response.data.check);
},
onError: (err) => handleError(err as AxiosError),
onError: handleApiError({
400: () => setAuthNumberIsValid('notIsValid'),
}),
},
);
}
Expand Down
42 changes: 29 additions & 13 deletions components/pages/join/join-Password.tsx
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import React, { useEffect, useState } from 'react';
import React, { useState } from 'react';

import CheckSquare from '@/components/check-square';

Expand Down Expand Up @@ -137,15 +137,7 @@ const JoinPassword: React.FC<JoinPasswordType> = ({ email, getNicknames }) => {
};

//에러 처리
const { handleError } = useApiError({
// 닉네임 GPT오류
500: () => {
setCheckNickname('error');
setIsDuplicatedCheckAble(true);
},
// 회원가입 체크
400: () => console.log('sign-up error'),
});
const { handleApiError } = useApiError();

//GPT닉네임 바꾸는 함수
async function changeNicknameHandler() {
Expand Down Expand Up @@ -173,7 +165,15 @@ const JoinPassword: React.FC<JoinPasswordType> = ({ email, getNicknames }) => {
} catch (error) {
// 서버에서 500 오류가 발생한 경우
setIsFetch(false);
handleError(error as AxiosError);
handleApiError({
// 닉네임 GPT오류
500: () => {
setCheckNickname('error');
setIsDuplicatedCheckAble(true);
},
// 회원가입 체크
400: () => console.log('sign-up error'),
});
}
}

Expand Down Expand Up @@ -210,7 +210,15 @@ const JoinPassword: React.FC<JoinPasswordType> = ({ email, getNicknames }) => {
onSuccess: (response) => {
successHandler(response.data.check, response.data.information.accessToken);
},
onError: (err) => handleError(err as AxiosError),
onError: handleApiError({
// 닉네임 GPT오류
500: () => {
setCheckNickname('error');
setIsDuplicatedCheckAble(true);
},
// 회원가입 체크
400: () => console.log('sign-up error'),
}),
},
);
};
Expand All @@ -227,7 +235,15 @@ const JoinPassword: React.FC<JoinPasswordType> = ({ email, getNicknames }) => {
onSuccess: (response) => {
loginHandler(response.data.check, email, password);
},
onError: (err) => handleError(err as AxiosError),
onError: handleApiError({
// 닉네임 GPT오류
500: () => {
setCheckNickname('error');
setIsDuplicatedCheckAble(true);
},
// 회원가입 체크
400: () => console.log('sign-up error'),
}),
},
);
};
Expand Down
9 changes: 4 additions & 5 deletions components/pages/password/password-Email.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -77,7 +77,6 @@ const PasswordEmail: React.FC<PasswordEmailProps> = ({ moveNextPage, setEmail })
clearInterval(timer);
setAuthNumberIsValid('timeOver');
setTimerStarted(false);
console.log('타이머가 종료되었습니다.');
}

return () => {
Expand Down Expand Up @@ -111,9 +110,7 @@ const PasswordEmail: React.FC<PasswordEmailProps> = ({ moveNextPage, setEmail })
};

//에러처리 => 인증번호가 일치하지 않을 경우
const { handleError } = useApiError({
400: () => setAuthNumberIsValid('notIsValid'),
});
const { handleApiError } = useApiError();

//인증번호 확인
const checkAuthNumberHandler = async () => {
Expand All @@ -123,7 +120,9 @@ const PasswordEmail: React.FC<PasswordEmailProps> = ({ moveNextPage, setEmail })
onSuccess: (response) => {
checkAuthNumberSuccessHandler(response.data.check);
},
onError: (err) => handleError(err as AxiosError),
onError: handleApiError({
400: () => setAuthNumberIsValid('notIsValid'),
}),
},
);
};
Expand Down
6 changes: 2 additions & 4 deletions components/pages/password/password-Password.tsx
Original file line number Diff line number Diff line change
@@ -1,11 +1,9 @@
import React, { useState } from 'react';
import EyeOpenIcon from '../../../public/icons/eye-opened.svg';
import EyeHiddenIcon from '../../../public/icons/eye-hidden.svg';
import Layout from '../../layouts/layout';
import useAlert from '../../../recoil/alert/useAlert';
import { patchResetPassword } from '@/apis/patchResetPassword';
import { useMutation } from 'react-query';
import { AxiosError } from 'axios';
import useApiError from '@/hooks/custom/useApiError';
import { useRouter } from 'next/router';
import { passwordRegex } from '@/libs/passwordRegex';
Expand All @@ -29,7 +27,7 @@ const PasswordPassword: React.FC<PasswordPasswordProps> = ({ email }) => {
});
const { showAlert } = useAlert();
const newChangePasswordMutation = useMutation(patchResetPassword);
const { handleError: handleDefaultError } = useApiError();
const { handleApiError } = useApiError();

//새 비밀번호 입력 비밀번호 보이기&숨기기
const togglePasswordHandler = () => {
Expand Down Expand Up @@ -97,7 +95,7 @@ const PasswordPassword: React.FC<PasswordPasswordProps> = ({ email }) => {
{ title: '아니요', style: 'tertiary', handler: () => router.push('/') },
],
}),
onError: handleDefaultError,
onError: handleApiError(),
},
);
};
Expand Down
64 changes: 31 additions & 33 deletions components/pages/response/response-Select.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -51,37 +51,7 @@ const ResponseSelect: React.FC<SendProps> = ({ componentChangeHandler, title, co
setEnvelopType(num);
};

const { handleError: handlerSendError } = useApiError({
500: () =>
showAlert({
title: (
<div className='flex flex-col items-center'>
<span>편지 보내기에 실패했습니다.</span>
<span>편지를 다시 보낼까요?</span>
</div>
),
actions: [
{ title: '네', style: 'primary', handler: newSendHandler },
{ title: '아니요', style: 'tertiary', handler: null },
],
}),
});

const { handleError: handlerSendGptError } = useApiError({
500: () =>
showAlert({
title: (
<div className='flex flex-col items-center'>
<span>편지 보내기에 실패했습니다.</span>
<span>편지를 다시 보낼까요?</span>
</div>
),
actions: [
{ title: '네', style: 'primary', handler: newSendGptHandler },
{ title: '아니요', style: 'tertiary', handler: null },
],
}),
});
const { handleApiError } = useApiError();

//편지답장 특정인에게 발송하기
const newSendMutation = useMutation(postSend);
Expand All @@ -92,7 +62,21 @@ const ResponseSelect: React.FC<SendProps> = ({ componentChangeHandler, title, co
onSuccess: () => {
componentChangeHandler('Complete');
},
onError: (err) => handlerSendError(err as AxiosError),
onError: handleApiError({
500: () =>
showAlert({
title: (
<div className='flex flex-col items-center'>
<span>편지 보내기에 실패했습니다.</span>
<span>편지를 다시 보낼까요?</span>
</div>
),
actions: [
{ title: '네', style: 'primary', handler: newSendHandler },
{ title: '아니요', style: 'tertiary', handler: null },
],
}),
}),
},
);
};
Expand All @@ -106,7 +90,21 @@ const ResponseSelect: React.FC<SendProps> = ({ componentChangeHandler, title, co
onSuccess: () => {
componentChangeHandler('Complete');
},
onError: (err) => handlerSendGptError(err as AxiosError),
onError: handleApiError({
500: () =>
showAlert({
title: (
<div className='flex flex-col items-center'>
<span>편지 보내기에 실패했습니다.</span>
<span>편지를 다시 보낼까요?</span>
</div>
),
actions: [
{ title: '네', style: 'primary', handler: newSendGptHandler },
{ title: '아니요', style: 'tertiary', handler: null },
],
}),
}),
},
);
};
Expand Down
Loading

0 comments on commit 88b17d9

Please sign in to comment.