-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
refactor: 로그인/회원가입 폼에 react-hook-form 적용 (#223)
* rebase: from develop * refactor: SignupForm에 rhf 적용완료 * refactor: pr #217에 맞게 수정 * refactor: import 경로 @ 적용 * refactor: 확장자명 tsx -> ts * fix: button들에 type=button 설정 * fix: button들에 type button 추가 설정 * fix: 닉네임 검사시 누락된 isBlank 함수 추가 * fix: 약관동의를 첫 페이지로 * remove: 중복되는 파일 제거
- Loading branch information
Showing
15 changed files
with
133 additions
and
108 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
56 changes: 33 additions & 23 deletions
56
src/home/components/SignupContents/SignupForm/SignupForm.tsx
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
43 changes: 0 additions & 43 deletions
43
src/home/components/SignupContents/SignupForm/useSignUpForm.ts
This file was deleted.
Oops, something went wrong.
45 changes: 45 additions & 0 deletions
45
src/home/components/SignupContents/SignupForm/useSignupFormConfirm.tsx
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,45 @@ | ||
import { AxiosError } from 'axios'; | ||
import { SubmitHandler } from 'react-hook-form'; | ||
|
||
import { STORAGE_KEYS } from '@/constants/storage.constant'; | ||
import { postAuthSignUp } from '@/home/apis/postAuthSignUp'; | ||
import { AuthErrorData } from '@/home/types/Auth.type'; | ||
|
||
import { SignupFormProps, SignupFormStates } from './SignUpForm.type'; | ||
|
||
export const useSignupFormConfirm = ({ email, onConfirm }: SignupFormProps) => { | ||
const onSignupError = (error: AxiosError) => { | ||
alert( | ||
(error as AxiosError<AuthErrorData>).response?.data.message || '회원가입에 실패했습니다.' | ||
); | ||
}; | ||
|
||
const onSignupSuccess = () => { | ||
sessionStorage.removeItem(STORAGE_KEYS.EMAIL_AUTH_SESSION_TOKEN); | ||
sessionStorage.removeItem(STORAGE_KEYS.EMAIL_AUTH_SESSION_TOKEN_EXPIRED_IN); | ||
onConfirm(); | ||
}; | ||
|
||
const onFormConfirm: SubmitHandler<SignupFormStates> = async ({ nickname, password }) => { | ||
const sessionToken = sessionStorage.getItem(STORAGE_KEYS.EMAIL_AUTH_SESSION_TOKEN); | ||
|
||
if (!sessionToken) { | ||
alert('세션 토큰이 없습니다.'); | ||
return; | ||
} | ||
|
||
const signUpParams = { | ||
nickName: nickname, | ||
password: password, | ||
sessionToken: sessionToken, | ||
email: email, | ||
}; | ||
|
||
const { data, error } = await postAuthSignUp(signUpParams); | ||
|
||
if (data) onSignupSuccess(); | ||
else if (error) onSignupError(error); | ||
}; | ||
|
||
return onFormConfirm; | ||
}; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.