@@ -3,11 +3,7 @@ import InputField from "@common/InputField";
33import Input from "@common/html/Input" ;
44import BottomButton from "@common/BottomButton" ;
55import DropDown , { DropDownRef } from "@common/html/DropDown" ;
6- import {
7- availableAccount ,
8- signUpWithCredential ,
9- updateUserData ,
10- } from "@apis/firebase/auth" ;
6+ import { signUpWithCredential , updateUserData } from "@apis/firebase/auth" ;
117import { useInput } from "@hooks/useInput" ;
128import userStore from "@store/auth.store" ;
139import { auth } from "@/firebase" ;
@@ -43,6 +39,9 @@ const SignUpRequired = () => {
4339 const [ userNameRef , focusUserName , handleUserNamePress ] =
4440 useFocus < HTMLInputElement > ( ) ;
4541 const [ genderRef , focusGender ] = useFocus < DropDownRef > ( ) ;
42+ const [ birthYearRef , focusBirthYear ] = useFocus < DropDownRef > ( ) ;
43+ const [ birthMonthRef , focusBirthMonth ] = useFocus < DropDownRef > ( ) ;
44+ const [ birthDayRef , focusBirthDay ] = useFocus < DropDownRef > ( ) ;
4645
4746 const genderOptions : { value : string ; label : string } [ ] = [
4847 { value : "남성" , label : "남성" } ,
@@ -97,69 +96,74 @@ const SignUpRequired = () => {
9796 if ( name === "username" ) setnameError ( "" ) ;
9897 } ;
9998
100- const checkValidate = ( ) => {
101- let isvalid = true ;
99+ const submitHandle = ( e : React . FormEvent ) => {
100+ e . preventDefault ( ) ;
101+
102102 const validateEmail = ( email : string ) => {
103103 const emailRegex = / ^ [ ^ \s @ ] + @ [ ^ \s @ ] + \. [ ^ \s @ ] + $ / ;
104104 if ( ! emailRegex . test ( email ) ) {
105105 focusEmail ( ) ; // 이메일 필드 자동 포커스
106106 setEmailError ( "이메일 형식을 확인해주세요" ) ;
107+ isSignUpRequiredValid = false ;
108+ return false ;
109+ } else {
110+ setEmailError ( "" ) ;
111+ return true ;
107112 }
108113 } ;
109114
115+ let isSignUpRequiredValid = true ;
116+
110117 if ( ! signUpRequired . email ) {
111118 //아이디 비어있을 때
112- focusEmail ( ) ; // 이메일 필드 자동 포커스
119+ if ( isSignUpRequiredValid ) focusEmail ( ) ; // 이메일 필드 자동 포커스
120+
113121 setEmailError ( "아이디를 입력하세요" ) ;
114- isvalid = false ;
115- } else if ( emailError . length > 0 ) {
116- focusEmail ( ) ;
117- isvalid = false ;
118- } else validateEmail ( signUpRequired . email ) ;
122+ isSignUpRequiredValid = false ;
123+ } else if ( validateEmail ( signUpRequired . email ) ) {
124+ isSignUpRequiredValid = true ;
125+ }
119126
120127 if ( ! signUpRequired . password ) {
121128 //비밀번호 비어있을 때
122- if ( isvalid ) focusPassword ( ) ; // 비밀번호 필드 자동 포커스
123- isvalid = false ;
129+ if ( isSignUpRequiredValid ) focusPassword ( ) ; // 비밀번호 필드 자동 포커스
130+
124131 setPasswordError ( "비밀번호를 입력하세요" ) ;
132+ isSignUpRequiredValid = false ;
125133 }
126134
127135 if ( ! signUpRequired . username ) {
128- if ( isvalid ) focusUserName ( ) ; // 이름 필드 자동 포커스
129- isvalid = false ;
136+ if ( isSignUpRequiredValid ) focusUserName ( ) ; // 이름 필드 자동 포커스
137+
130138 setnameError ( "이름을 입력하세요" ) ;
139+ isSignUpRequiredValid = false ;
131140 }
132141
133142 if ( ! signUpRequired . gender ) {
134- if ( isvalid ) focusGender ( ) ; // 성별 필드 자동 포커스
135- isvalid = false ;
143+ if ( isSignUpRequiredValid ) focusGender ( ) ; // 성별 필드 자동 포커스
144+
136145 setGenderError ( "성별을 입력하세요" ) ;
146+ isSignUpRequiredValid = false ;
137147 }
138148
139149 if ( ! signUpRequired . birthDate ) {
140150 if ( ! birthYear ) {
141- // focusBirthYear(); // 년도 필드에 포커스
151+ focusBirthYear ( ) ; // 년도 필드에 포커스
142152 setBirthDateError ( "년도를 선택하세요" ) ;
153+ isSignUpRequiredValid = false ;
143154 } else if ( ! birthMonth ) {
144- // focusBirthMonth(); // 월 필드에 포커스
155+ focusBirthMonth ( ) ; // 월 필드에 포커스
145156 setBirthDateError ( "월을 선택하세요" ) ;
157+ isSignUpRequiredValid = false ;
146158 } else if ( ! birthDay ) {
147- // focusBirthDay(); // 일 필드에 포커스
159+ focusBirthDay ( ) ; // 일 필드에 포커스
148160 setBirthDateError ( "일을 선택하세요" ) ;
161+ isSignUpRequiredValid = false ;
149162 }
150163 }
151- } ;
152164
153- const submitHandle = ( e : React . FormEvent ) => {
154- e . preventDefault ( ) ;
155-
156- if (
157- emailError . length === 0 &&
158- passwordError . length === 0 &&
159- genderError . length === 0 &&
160- birthDateError . length === 0 &&
161- nameError . length === 0
162- ) {
165+ //값 확인용
166+ if ( isSignUpRequiredValid ) {
163167 if ( user ) {
164168 updateUserData ( "gender" , signUpRequired . gender ) ;
165169 updateUserData ( "birthDate" , signUpRequired . birthDate ) ;
@@ -173,15 +177,7 @@ const SignUpRequired = () => {
173177 gender : signUpRequired . gender === "남성" ? "male" : "female" ,
174178 username : signUpRequired . username ,
175179 birthDate : signUpRequired . birthDate ,
176- } )
177- . then ( updateUserInfo )
178- . catch ( ( data ) => {
179- if ( data . code === "auth/email-already-in-use" )
180- setEmailError ( "이미 사용중인 이메일입니다" ) ;
181- else if ( data . code === "auth/weak-password" ) {
182- setPasswordError ( "비밀번호는 6자 이상이어야합니다" ) ;
183- }
184- } ) ;
180+ } ) . then ( updateUserInfo ) ;
185181 }
186182 } ;
187183
@@ -204,19 +200,11 @@ const SignUpRequired = () => {
204200 type = "email"
205201 name = "email"
206202 placeholder = { user ?. email || "이메일을 입력해주세요" }
207- className = { `py-[14px h-[48px] w-full rounded-[4px] px-4` }
208- isErrored = { emailError }
203+ className = "h-[48px] w-full rounded-[4px] px-4 py-[14px]"
209204 value = { user ?. email ? "" : signUpRequired . email }
210205 onChange = { handleInputChange }
211206 disabled = { user ?. email ? true : false }
212207 onKeyDown = { ( e ) => handleEmailPress ( e , focusPassword ) } // 다음 패스워드 포커스
213- onBlur = { async ( e ) => {
214- const isAvailable = await availableAccount ( e . target . value ) ;
215-
216- if ( ! isAvailable ) {
217- setEmailError ( "이미 사용중인 이메일입니다" ) ;
218- }
219- } }
220208 />
221209 </ InputField >
222210 { /*패스워드 입력 필드*/ }
@@ -225,7 +213,6 @@ const SignUpRequired = () => {
225213 ref = { passwordRef }
226214 type = "password"
227215 name = "password"
228- isErrored = { passwordError }
229216 placeholder = {
230217 user ?. email
231218 ? "소셜 로그인 회원입니다."
@@ -244,7 +231,6 @@ const SignUpRequired = () => {
244231 ref = { userNameRef }
245232 type = "text"
246233 name = "username"
247- isErrored = { nameError }
248234 placeholder = { user ?. displayName || "이름을 입력해주세요" }
249235 className = "h-[48px] w-full rounded-[4px] px-4 py-[14px]"
250236 value = { user ?. displayName ? "" : signUpRequired . username }
@@ -267,16 +253,18 @@ const SignUpRequired = () => {
267253 < InputField title = "생년월일" error = { birthDateError } >
268254 < div className = "flex w-full justify-between space-x-1" >
269255 < DropDown
256+ ref = { birthYearRef }
270257 className = "h-[45px] gap-2 rounded-[6px] border-[#E4E4E7] px-[10px] py-[14px]"
271258 menuPlacement = "top"
272259 placeholder = "년"
273- options = { birthYearOptions . sort ( ( a , b ) => b . value - a . value ) }
260+ options = { birthYearOptions }
274261 onChange = { ( value ) => {
275262 setBirthYear ( value ) ;
276263 updateBirthDate ( value , birthMonth , birthDay ) ;
277264 } }
278265 />
279266 < DropDown
267+ ref = { birthMonthRef }
280268 className = "h-[45px] gap-2 rounded-[6px] border-[#E4E4E7] px-[10px] py-[14px]"
281269 menuPlacement = "top"
282270 placeholder = "월"
@@ -287,6 +275,7 @@ const SignUpRequired = () => {
287275 } }
288276 />
289277 < DropDown
278+ ref = { birthDayRef }
290279 className = "h-[45px] gap-2 rounded-[6px] border-[#E4E4E7] px-[10px] py-[14px]"
291280 menuPlacement = "top"
292281 placeholder = "일"
@@ -307,7 +296,7 @@ const SignUpRequired = () => {
307296 </ div >
308297 < div className = "mt-4 px-5" >
309298 { /*회원가입 다음 페이지로 이동 버튼*/ }
310- < BottomButton title = "다음" type = "submit" onClick = { checkValidate } />
299+ < BottomButton title = "다음" type = "submit" />
311300 </ div >
312301 </ form >
313302 </ >
0 commit comments