Skip to content

Commit 707ce61

Browse files
authored
Merge pull request #218 from prgrms-web-devcourse-final-project/feat/217-signUp-resend
[feat] 재전송 횟수 로직 추가
2 parents 74d35e3 + 2021d4d commit 707ce61

File tree

2 files changed

+15
-7
lines changed

2 files changed

+15
-7
lines changed

src/hooks/useResendEmailVerification.ts

Lines changed: 13 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,15 +1,21 @@
11
import { postEmailVerificationRequest } from '@/apis/email';
2+
import { MAX_RESEND_COUNT } from '@/constants/email';
23
import { useMutation } from '@tanstack/react-query';
34

45
// 이메일 재전송 훅
56
export const useResendEmailVerification = (
67
email: string,
78
setValidationMessage: (val: { success: boolean; message: string }) => void,
8-
setButtonVariant: (val: 'primary' | 'disabled') => void,
99
setResendCount: React.Dispatch<React.SetStateAction<number>>,
10+
resendCount: number, // 재전송횟수
1011
) => {
1112
const resendEmailMutation = useMutation({
12-
mutationFn: () => postEmailVerificationRequest(email),
13+
mutationFn: () => {
14+
if (resendCount >= MAX_RESEND_COUNT) {
15+
throw new Error('최대 재전송 횟수를 초과');
16+
}
17+
return postEmailVerificationRequest(email);
18+
},
1319
onSuccess: ({ code }) => {
1420
if (code === 200) {
1521
setValidationMessage({
@@ -18,13 +24,15 @@ export const useResendEmailVerification = (
1824
});
1925

2026
setResendCount((count) => count + 1);
21-
setButtonVariant('disabled');
2227
}
2328
},
24-
onError: () => {
29+
onError: (error) => {
2530
setValidationMessage({
2631
success: false,
27-
message: '이메일 재전송 중 오류가 발생했습니다. 다시 시도해주세요.',
32+
message:
33+
error.message === '최대 재전송 횟수를 초과'
34+
? '최대 재전송 횟수를 초과했습니다.'
35+
: '이메일 재전송 중 오류가 발생했습니다. 다시 시도해주세요.',
2836
});
2937
},
3038
});

src/pages/signup/components/AuthCodeInput.tsx

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -14,9 +14,9 @@ interface AuthCodeInputProps {
1414
}
1515
function AuthCodeInput({ email, emailvalidity, validity, setValidity }: AuthCodeInputProps) {
1616
const [resendCount, setResendCount] = useState(0); // 재전송 횟수
17-
// 유효성 검사
1817
const [showLoading, setShowLoading] = useState(false); // 로딩 UI 표시 여부
1918

19+
// 유효성 검사
2020
const handleValidation = (value: string) => {
2121
if (value == '') {
2222
return { success: false, message: '인증번호가 오지 않았나요?' };
@@ -46,8 +46,8 @@ function AuthCodeInput({ email, emailvalidity, validity, setValidity }: AuthCode
4646
const { resendEmailVerification } = useResendEmailVerification(
4747
email,
4848
setValidationMessage,
49-
setButtonVariant,
5049
setResendCount,
50+
resendCount,
5151
);
5252
// 인증번호 확인 훅
5353
const { verifyEmail, isLoading } = useEmailVerificationCheck(

0 commit comments

Comments
 (0)