@@ -7,9 +7,10 @@ import ProfileCircle from '../../../../design-system/ui/Profile';
77import TertiaryButton from '../../../../design-system/ui/buttons/TertiaryButton' ;
88import DefaultTextField from '../../../../design-system/ui/textFields/DefaultTextField' ;
99import useAuthStore from '../../../app/provider/authStore' ;
10- import { useSendCertificationCode , useUserInfo , useUserUpdate , useVerifyCertificationCode } from '../../../features/join/hooks/useUserHook' ;
10+ import { useUserInfo , useUserUpdate } from '../../../features/join/hooks/useUserHook' ;
1111import { formatProfilName } from '../../../shared/lib/formatProfileName' ;
1212import Button from '../../../../design-system/ui/Button' ;
13+ import { usePhoneVerification } from '../../../shared/utils/phoneVerification' ;
1314
1415const ProfileInfo = ( ) => {
1516 const isLoggedIn = useAuthStore ( state => state . isLoggedIn ) ;
@@ -18,9 +19,17 @@ const ProfileInfo = () => {
1819 const { mutate : updateUser } = useUserUpdate ( ) ;
1920 const [ isEditing , setIsEditing ] = useState ( false ) ;
2021
21- const { mutate : sendCode } = useSendCertificationCode ( ) ;
22- const { mutate : verifyCode } = useVerifyCertificationCode ( ) ;
23- const [ isVerified , setIsVerified ] = useState ( false ) ;
22+ const {
23+ isVerified,
24+ isVerifyVisible,
25+ verificationCode,
26+ setVerificationCode,
27+ timer,
28+ formatTime,
29+ requestVerificationCode,
30+ submitVerificationCode,
31+ resetVerification,
32+ } = usePhoneVerification ( ) ;
2433
2534 const {
2635 register,
@@ -66,7 +75,6 @@ const ProfileInfo = () => {
6675 setName ( name ) ;
6776 refetch ( ) ;
6877 setIsEditing ( false ) ;
69- setIsVerified ( false ) ;
7078 alert ( '정보가 성공적으로 업데이트 되었습니다.' )
7179 } ,
7280 onError : ( ) => {
@@ -75,48 +83,7 @@ const ProfileInfo = () => {
7583 } ) ;
7684 } ;
7785
78- // 전화번호 인증
79- const [ isVerifyVisible , setIsVerifyVisible ] = useState ( true ) ;
80- const [ verificationCode , setVerificationCode ] = useState ( '' ) ;
81- const [ timer , setTimer ] = useState ( 0 ) ;
82- //인증번호 발급
83- const handlePhoneVerifyClick = ( ) => {
84- if ( ! phoneValue ) {
85- alert ( '연락처를 입력해주세요.' ) ;
86- return ;
87- }
88- // //인증api호출
89- sendCode ( { phoneNumber : phoneValue } , {
90- onSuccess : ( ) => {
91- setIsVerifyVisible ( true ) ;
92- setTimer ( 180 ) ;
93- }
94- } ) ;
95- } ;
96- // 인증번호 확인
97- const handleVerifySubmit = ( ) => {
98- if ( ! verificationCode || verificationCode . length !== 6 ) {
99- alert ( '6자리 인증번호를 입력해주세요.' ) ;
100- return ;
101- }
102- verifyCode ( { phoneNumber : phoneValue , certificationCode : verificationCode } , {
103- onSuccess : ( ) => {
104- setIsVerifyVisible ( false ) ;
105- setIsVerified ( true ) ;
106- }
107- } ) ;
108- } ;
109- useEffect ( ( ) => {
110- if ( isVerifyVisible && timer > 0 ) {
111- const interval = setInterval ( ( ) => setTimer ( ( prev ) => prev - 1 ) , 1000 ) ;
112- return ( ) => clearInterval ( interval ) ;
113- }
114- } , [ timer , isVerifyVisible ] ) ;
115- const formatTime = ( seconds : number ) => {
116- const m = String ( Math . floor ( seconds / 60 ) ) . padStart ( 2 , '0' ) ;
117- const s = String ( seconds % 60 ) . padStart ( 2 , '0' ) ;
118- return `${ m } :${ s } ` ;
119- } ;
86+
12087
12188 if ( isLoading ) {
12289 return < div > 로딩 중...</ div > ;
@@ -175,7 +142,7 @@ const ProfileInfo = () => {
175142 < Button
176143 type = "button"
177144 label = "인증하기"
178- onClick = { handlePhoneVerifyClick }
145+ onClick = { ( ) => requestVerificationCode ( phoneValue ) }
179146 className = "h-9 sm:h-8 rounded-md w-24"
180147 />
181148 </ div >
@@ -192,7 +159,7 @@ const ProfileInfo = () => {
192159 < Button
193160 type = "button"
194161 label = "확인"
195- onClick = { handleVerifySubmit }
162+ onClick = { ( ) => submitVerificationCode ( phoneValue ) }
196163 className = "h-9 px-3 rounded-md"
197164 />
198165 </ div >
@@ -208,8 +175,7 @@ const ProfileInfo = () => {
208175 setIsEditing ( false ) ;
209176 setValue ( 'name' , data ?. name || '' ) ;
210177 setValue ( 'phone' , data ?. phoneNumber || '' ) ;
211- setIsVerified ( false ) ;
212- setIsVerifyVisible ( false ) ;
178+ resetVerification ( ) ;
213179 setVerificationCode ( '' ) ;
214180 } }
215181 />
@@ -227,7 +193,7 @@ const ProfileInfo = () => {
227193 setIsEditing ( false ) ;
228194 setValue ( 'name' , data ?. name || '' ) ;
229195 setValue ( 'phone' , data ?. phoneNumber || '' ) ;
230- setIsVerified ( false ) ;
196+ resetVerification ( ) ;
231197 setVerificationCode ( '' ) ;
232198 } }
233199 />
0 commit comments