@@ -11,21 +11,9 @@ function PasswordEditForm() {
1111 const navigate = useNavigate ( ) ;
1212 const { openModal, closeModal } = useModalStore ( ) ; // 모달 관리
1313
14- const [ validity , setValidity ] = useState ( {
15- currentPassword : false ,
16- password : false ,
17- } ) ;
18-
19- const buttonEnabled = Object . values ( validity ) . every ( Boolean ) ;
20-
21- // validity 업데이트 함수
22- const updateValidity = ( key : 'currentPassword' | 'password' , value : boolean ) => {
23- setValidity ( ( prev ) => {
24- if ( prev [ key ] === value ) return prev ; // 값이 동일하면 변경 X
25- return { ...prev , [ key ] : value } ;
26- } ) ;
27- } ;
28-
14+ const [ currentPassword , setCurrentPassword ] = useState ( '' ) ;
15+ const [ password , setPassword ] = useState ( '' ) ;
16+ const isButtonEnabled = currentPassword !== '' && password !== '' ;
2917 // 현재 비밀번호 확인 useMutation
3018 const {
3119 mutateAsync : checkCurrentPassword ,
@@ -60,9 +48,6 @@ function PasswordEditForm() {
6048
6149 const handleSubmit = async ( e : React . FormEvent < HTMLFormElement > ) => {
6250 e . preventDefault ( ) ;
63- const formData = new FormData ( e . currentTarget ) ;
64- const currentPassword = formData . get ( 'current-password' ) as string ;
65- const password = formData . get ( 'password' ) as string ;
6651 // 현재 비밀번호 확인
6752 try {
6853 await checkCurrentPassword ( currentPassword ) ;
@@ -103,9 +88,9 @@ function PasswordEditForm() {
10388 return (
10489 < form className = "flex flex-col justify-between h-full p-5" onSubmit = { handleSubmit } >
10590 < div className = "flex flex-col" >
106- < CurrentPasswordInput setValidity = { ( value ) => updateValidity ( 'currentPassword' , value ) } />
91+ < CurrentPasswordInput onChange = { setCurrentPassword } />
10792 < PasswordGroupSection
108- setValidity = { ( value ) => updateValidity ( 'password' , value ) }
93+ onChange = { setPassword }
10994 passwordLabel = "새 비밀번호"
11095 confirmLabel = "새 비밀번호 확인"
11196 passwordPlaceholder = "새 비밀번호를 입력해 주세요"
@@ -116,7 +101,7 @@ function PasswordEditForm() {
116101 isLoading = { isCheckingPassword || isChangingPassword }
117102 isSuccess = { isSuccess }
118103 isError = { isCheckPasswordError || isChangePasswordError }
119- disabled = { ! buttonEnabled }
104+ disabled = { ! isButtonEnabled }
120105 type = "submit"
121106 text = "저장하기"
122107 />
0 commit comments