-
Notifications
You must be signed in to change notification settings - Fork 0
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
refactor: 로그인/회원가입 폼에 react-hook-form 적용 #223
Changes from 2 commits
703a4a8
22c6bec
521d9c9
121b1fe
b90cbd9
6e00f91
8a01a72
9a706e3
58844ea
2924c05
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
This file was deleted.
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; | ||
}; |
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
폼 제출용 버튼( There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. 로그인 및 회원가입 폼 내의 모든 버튼들에 대해 |
This file was deleted.
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,12 @@ | ||
import { useCallback } from 'react'; | ||
|
||
import { EMAIL_DOMAIN } from '@/constants/email.constant'; | ||
|
||
export const useParseFullEmail = () => { | ||
const parseFullEmail = useCallback((email: string) => { | ||
if (email.endsWith(EMAIL_DOMAIN)) return email; | ||
return email + EMAIL_DOMAIN; | ||
}, []); | ||
|
||
return parseFullEmail; | ||
}; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
https://github.com/react-hook-form/resolvers RHF에 resolver를 사용할 수도 있습니다 ㅎㅎ