@@ -3,24 +3,20 @@ import CountdownTimer from '@/components/CountdownTimer';
33import React from 'react' ;
44import { twMerge } from 'tailwind-merge' ;
55
6- type ValidationMessage = {
7- type : 'success' | 'error' | 'default' ;
8- message : string ;
9- } ;
10-
116interface InputAuthCodeProps extends React . InputHTMLAttributes < HTMLInputElement > {
127 id : string ;
138 label : string ;
149 className ?: string ;
15- messages : ValidationMessage ; // 띄울 메시지
10+ isValid : boolean ;
11+ validationMessage : string ; // 띄울 메세지
1612 emailSent : boolean ;
1713 onTimeout ?: ( ) => void ; // 시간이 만료되었을 때 실행할 함수
1814 onResendEmail ?: ( ) => void ; // 재전송 함수
1915 resendCount : number ; // 재전송 횟수
2016
2117 // ✅ 버튼 관련 속성 추가
2218 buttonText : string | React . ReactNode ;
23- variant : 'primary' | 'secondary' | ' disabled';
19+ variant : 'primary' | 'disabled' ;
2420 onClick : ( ) => void ;
2521 onButtonClick ?: ( ) => void ;
2622}
@@ -32,20 +28,23 @@ function InputAuthCode({
3228 buttonText,
3329 variant,
3430 onClick,
35- messages,
31+ isValid,
32+ disabled,
33+ value,
34+ validationMessage,
3635 emailSent,
3736 resendCount,
3837 onTimeout,
3938 onResendEmail,
4039 ...props
4140} : InputAuthCodeProps ) {
42- const colorMap = {
43- success : 'text-functional-success' ,
44- error : 'text-functional-danger' ,
45- default : 'text-gray-60' ,
41+ // 메세지 색 선택 로직
42+ const getMessageColor = ( value : string , isValid : boolean ) => {
43+ if ( ! value ) return 'text-gray-60' ;
44+ return isValid ? 'text-functional-success' : 'text-functional-danger' ;
4645 } ;
4746
48- const messageColor = colorMap [ messages . type ] ;
47+ const messageColor = getMessageColor ( value as string , isValid ) ;
4948
5049 return (
5150 < div className = "flex flex-col w-full" >
@@ -54,10 +53,15 @@ function InputAuthCode({
5453 </ label >
5554 < div className = "flex gap-2" >
5655 < div className = "w-full h-[38px] rounded-lg input-shadow outline-0 px-3 caption-m placeholder:text-gray-50 focus-within:ring-1 focus-within:ring-primary-active bg-white flex items-center" >
57- < input id = { id } type = "text" className = "w-full " { ...props } />
58- { emailSent && messages ?. type !== 'success' && (
59- < CountdownTimer key = { resendCount } onTimeout = { onTimeout } />
60- ) }
56+ < input
57+ id = { id }
58+ type = "text"
59+ className = "w-full "
60+ value = { value }
61+ disabled = { disabled }
62+ { ...props }
63+ />
64+ { emailSent && ! isValid && < CountdownTimer key = { resendCount } onTimeout = { onTimeout } /> }
6165 </ div >
6266 { buttonText && (
6367 < Button
@@ -76,11 +80,11 @@ function InputAuthCode({
7680 < p
7781 className = { twMerge ( 'text-functional-danger text-[9px]/[18px] ml-[5px]' , messageColor ) }
7882 >
79- { messages ?. message }
83+ { validationMessage }
8084 </ p >
81- { messages . type !== 'success ' && (
85+ { value === ' ' && (
8286 < div className = "flex gap-1 items-center text-gray-60 text-[9px]" >
83- < button className = "underline cursor-pointer" onClick = { onResendEmail } >
87+ < button className = "underline cursor-pointer" onClick = { onResendEmail } type = "button" >
8488 재전송
8589 </ button >
8690 < span > ({ resendCount } /3)</ span >
0 commit comments