11import { postEmailVerificationCheck , postEmailVerificationRequest } from '@/apis/email' ;
2- import InputAuthCode from '@/components/InputAuthCode ' ;
3- import { AUTHCODE_REGEX } from '@/constants ' ;
4- import { MAX_RESEND_COUNT } from '@/constants/email ' ;
2+ import { LoadingSpinnerButton } from '@/components/button ' ;
3+ import { InputAuthCode } from '@/pages/signup/components/ ' ;
4+ import { AUTHCODE_REGEX , MAX_RESEND_COUNT } from '@/constants' ;
55import { useModalStore } from '@/store/modalStore' ;
66import { useMutation } from '@tanstack/react-query' ;
77import { useState } from 'react' ;
88
99interface AuthCodeInputProps {
1010 email : string ;
11- authcodeValidity : boolean ;
11+ emailValidity : boolean ;
1212 setValidity : ( val : boolean ) => void ; // 인증코드 유효성 바꾸는 함수
1313}
14- function AuthCodeInput ( { email, authcodeValidity , setValidity } : AuthCodeInputProps ) {
14+ function AuthCodeInput ( { email, emailValidity , setValidity } : AuthCodeInputProps ) {
1515 const { openModal, closeModal } = useModalStore ( ) ; // 모달
1616 const [ resendCount , setResendCount ] = useState ( 0 ) ; // 재전송 횟수
1717 const [ text , setText ] = useState ( '' ) ;
18- const [ validationMessage , setValidationMessage ] = useState ( {
19- success : false ,
18+ const [ validationStatus , setValidationStatus ] = useState ( {
19+ isValid : false , // 유효성 통과여부
2020 message : '인증번호가 오지 않았나요?' ,
2121 } ) ;
2222
@@ -28,9 +28,9 @@ function AuthCodeInput({ email, authcodeValidity, setValidity }: AuthCodeInputPr
2828 const isValid = AUTHCODE_REGEX . test ( value ) ;
2929
3030 if ( isValid ) {
31- setValidationMessage ( { success : true , message : '' } ) ;
31+ setValidationStatus ( { isValid : true , message : '' } ) ;
3232 } else {
33- setValidationMessage ( { success : false , message : '올바른 인증번호를 입력해주세요' } ) ;
33+ setValidationStatus ( { isValid : false , message : '올바른 인증번호를 입력해주세요' } ) ;
3434 }
3535 } ;
3636
@@ -57,25 +57,25 @@ function AuthCodeInput({ email, authcodeValidity, setValidity }: AuthCodeInputPr
5757 mutationFn : ( ) => postEmailVerificationCheck ( email , text ) ,
5858 onSuccess : ( { code } ) => {
5959 if ( code === 200 ) {
60- setValidationMessage ( { success : true , message : '이메일 인증이 완료되었습니다' } ) ;
60+ setValidationStatus ( { isValid : true , message : '이메일 인증이 완료되었습니다' } ) ;
6161 setValidity ( true ) ; // 완료 처리
6262 } else {
63- setValidationMessage ( { success : false , message : '인증 코드가 올바르지 않습니다' } ) ;
63+ setValidationStatus ( { isValid : false , message : '인증 코드가 올바르지 않습니다' } ) ;
6464 }
6565 } ,
6666
6767 onError : ( ) => {
68- setValidationMessage ( {
69- success : false ,
68+ setValidationStatus ( {
69+ isValid : false ,
7070 message : '오류가 발생했습니다. 잠시 후 다시 시도해 주세요.' ,
7171 } ) ;
7272 } ,
7373 } ) ;
7474
7575 // 시간 초과시 실행할 함수
7676 const onTimeout = ( ) => {
77- setValidationMessage ( {
78- success : false ,
77+ setValidationStatus ( {
78+ isValid : false ,
7979 message : '인증 시간이 만료되었습니다. 다시 요청해주세요.' ,
8080 } ) ;
8181 } ;
@@ -95,27 +95,28 @@ function AuthCodeInput({ email, authcodeValidity, setValidity }: AuthCodeInputPr
9595 resendEmailVerification ( ) ;
9696 } ;
9797
98- const buttonHandler = {
99- disable : validationMessage . success && ! authcodeValidity ,
100- text : '인증확인' ,
101- isLoading : isPending ,
102- onClick : verifyEmail ,
103- } ;
104-
10598 return (
10699 < InputAuthCode
107100 id = "emailVerificationConfrim"
108101 label = "인증번호 확인"
109102 placeholder = "인증번호 6자리를 입력해 주세요"
110- isValid = { validationMessage . success } // ✅ 유효성 검사 여부 전달
111- validationMessage = { validationMessage . message } // ✅ 메시지 전달
103+ isValid = { validationStatus . isValid } // ✅ 유효성 검사 여부 전달
104+ message = { validationStatus . message } // ✅ 메시지 전달
112105 value = { text . toUpperCase ( ) }
113106 onChange = { handleChange }
114107 onTimeout = { onTimeout } // 시간이 만료되었을 때 실행할 함수
115108 onResendEmail = { handleResendEmail } // 재전송 요청
116109 resendCount = { resendCount } // 재전송 횟수
117- authcodeValidity = { authcodeValidity } // 인증코드 유효성
118- buttonHandler = { buttonHandler }
110+ isEmailVerified = { emailValidity }
111+ actionButton = {
112+ < LoadingSpinnerButton
113+ isLoading = { isPending }
114+ className = "w-[65px] flex-shrink-0"
115+ text = { emailValidity ? '인증완료' : '인증확인' }
116+ disabled = { ! validationStatus . isValid || emailValidity }
117+ onClick = { ( ) => verifyEmail ( ) }
118+ />
119+ }
119120 />
120121 ) ;
121122}
0 commit comments