@@ -7,11 +7,11 @@ import { useMutation } from '@tanstack/react-query';
77import { useState } from 'react' ;
88
99interface AuthCodeInputProps {
10+ tempEmail : string ;
1011 email : string ;
11- emailValidity : boolean ;
12- setValidity : ( val : boolean ) => void ; // 인증코드 유효성 바꾸는 함수
12+ onChange : ( val : string ) => void ;
1313}
14- function AuthCodeInput ( { email, emailValidity , setValidity } : AuthCodeInputProps ) {
14+ function AuthCodeInput ( { email, tempEmail , onChange } : AuthCodeInputProps ) {
1515 const { openModal, closeModal } = useModalStore ( ) ; // 모달
1616 const [ resendCount , setResendCount ] = useState ( 0 ) ; // 재전송 횟수
1717 const [ text , setText ] = useState ( '' ) ;
@@ -25,9 +25,7 @@ function AuthCodeInput({ email, emailValidity, setValidity }: AuthCodeInputProps
2525 setText ( value ) ;
2626
2727 // 유효성 검사
28- const isValid = AUTHCODE_REGEX . test ( value ) ;
29-
30- if ( isValid ) {
28+ if ( AUTHCODE_REGEX . test ( value ) ) {
3129 setValidationStatus ( { isValid : true , message : '' } ) ;
3230 } else {
3331 setValidationStatus ( { isValid : false , message : '올바른 인증번호를 입력해주세요' } ) ;
@@ -36,7 +34,7 @@ function AuthCodeInput({ email, emailValidity, setValidity }: AuthCodeInputProps
3634
3735 // 이메일 재전송
3836 const { mutate : resendEmailVerification } = useMutation ( {
39- mutationFn : ( ) => postEmailVerificationRequest ( email ) ,
37+ mutationFn : ( ) => postEmailVerificationRequest ( tempEmail ) ,
4038 onSuccess : ( { code } ) => {
4139 if ( code === 200 ) {
4240 setResendCount ( ( count ) => count + 1 ) ;
@@ -54,11 +52,11 @@ function AuthCodeInput({ email, emailValidity, setValidity }: AuthCodeInputProps
5452 } ) ;
5553 // 인증번호 확인
5654 const { mutate : verifyEmail , isPending } = useMutation ( {
57- mutationFn : ( ) => postEmailVerificationCheck ( email , text ) ,
55+ mutationFn : ( ) => postEmailVerificationCheck ( tempEmail , text ) ,
5856 onSuccess : ( { code } ) => {
5957 if ( code === 200 ) {
6058 setValidationStatus ( { isValid : true , message : '이메일 인증이 완료되었습니다' } ) ;
61- setValidity ( true ) ; // 완료 처리
59+ onChange ( tempEmail ) ; // 완료 처리
6260 } else {
6361 setValidationStatus ( { isValid : false , message : '인증 코드가 올바르지 않습니다' } ) ;
6462 }
@@ -107,13 +105,13 @@ function AuthCodeInput({ email, emailValidity, setValidity }: AuthCodeInputProps
107105 onTimeout = { onTimeout } // 시간이 만료되었을 때 실행할 함수
108106 onResendEmail = { handleResendEmail } // 재전송 요청
109107 resendCount = { resendCount } // 재전송 횟수
110- isEmailVerified = { emailValidity }
108+ isEmailVerified = { ! ! email }
111109 actionButton = {
112110 < LoadingSpinnerButton
113111 isLoading = { isPending }
114112 className = "w-[65px] flex-shrink-0"
115- text = { emailValidity ? '인증완료' : '인증확인' }
116- disabled = { ! validationStatus . isValid || emailValidity }
113+ text = { ! ! email ? '인증완료' : '인증확인' }
114+ disabled = { ! validationStatus . isValid || ! ! email }
117115 onClick = { ( ) => verifyEmail ( ) }
118116 />
119117 }
@@ -122,11 +120,3 @@ function AuthCodeInput({ email, emailValidity, setValidity }: AuthCodeInputProps
122120}
123121
124122export default AuthCodeInput ;
125-
126- // setValidationMessage({
127- // success: false,
128- // message:
129- // error.message === '최대 재전송 횟수를 초과'
130- // ? '최대 재전송 횟수를 초과했습니다.'
131- // : '이메일 재전송 중 오류가 발생했습니다. 다시 시도해주세요.',
132- // });
0 commit comments