-
Notifications
You must be signed in to change notification settings - Fork 3
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
* chore : 로그인 수정 * feat : email 체크 api 연동 * chore : 로그인 이미지 나오도록 수정 * feat : 라우팅 설정 * feat : 회원가입 api 연동 * feat : 유효성 검사 * feat : 헤더 라우팅 * chore : 로그인 수정 * feat : email 체크 api 연동 * chore : 로그인 이미지 나오도록 수정 * feat : 라우팅 설정 * feat : 회원가입 api 연동 * feat : 유효성 검사 * feat : 헤더 라우팅
- Loading branch information
Showing
13 changed files
with
239 additions
and
25 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,36 @@ | ||
import { useMutation, UseMutationResult } from '@tanstack/react-query'; | ||
import { join } from '@/shared/api/join'; | ||
import { JoinParam } from '../model/joinParams'; | ||
import { JoinType } from '../model/JoinType'; | ||
import { AxiosError } from 'axios'; | ||
import { useToastStore } from '@/features/Toast/hooks/useToastStore'; | ||
import { useNavigate } from 'react-router-dom'; | ||
import useLocalStorage from '@/shared/hooks/useLocalStorage'; | ||
|
||
/** | ||
* 회원가입 API 호출을 위한 커스텀 훅 | ||
*/ | ||
const useJoin = (): UseMutationResult<JoinType, AxiosError, JoinParam> => { | ||
const navigate = useNavigate(); | ||
const { setValue: setToken } = useLocalStorage<string>('token', ''); | ||
|
||
const { addToast } = useToastStore(); | ||
const mutation = useMutation<JoinType, AxiosError, JoinParam>({ | ||
mutationFn: (params: JoinParam) => join(params), | ||
onSuccess: (data) => { | ||
if (data.token) { | ||
addToast(data.message, 'success'); | ||
setToken(data.token); | ||
navigate('/login'); | ||
} else { | ||
addToast(data.message, 'error'); | ||
} | ||
}, | ||
onError: (error: Error) => { | ||
addToast(error.message, 'error'); | ||
} | ||
}); | ||
return mutation; | ||
}; | ||
|
||
export default useJoin; |
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,44 @@ | ||
import { Waring } from '../../Toast/ui/Toast.stories'; | ||
import { useMutation } from '@tanstack/react-query'; | ||
import { checkEmailExists } from '@/shared/api/checkEmail'; | ||
import { useToastStore } from '@/features/Toast/hooks/useToastStore'; | ||
import { useState } from 'react'; | ||
|
||
interface CheckEmailResponse { | ||
exists: boolean; | ||
message: string; | ||
} | ||
|
||
/** | ||
* 이메일 중복 여부를 확인하는 커스텀 훅 | ||
*/ | ||
const useCheckEmail = () => { | ||
const { addToast } = useToastStore(); | ||
const [isEmailAvailable, setIsEmailAvailable] = useState<boolean | null>( | ||
null | ||
); | ||
|
||
const { | ||
mutate: checkEmail, | ||
data, | ||
error | ||
} = useMutation<CheckEmailResponse, Error, string>({ | ||
mutationFn: (email: string) => checkEmailExists(email), | ||
onSuccess: (res) => { | ||
addToast(res.message, res.exists === false ? 'success' : 'warning'); | ||
setIsEmailAvailable(!res.exists); | ||
}, | ||
onError: () => { | ||
addToast('서버와 응답에 실패했습니다', 'error'); | ||
} | ||
}); | ||
|
||
return { | ||
checkEmail, | ||
isEmailAvailable, | ||
data, | ||
error | ||
}; | ||
}; | ||
|
||
export default useCheckEmail; |
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,4 @@ | ||
export interface JoinType { | ||
message: string; | ||
token: string; | ||
} |
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,7 @@ | ||
export interface JoinParam { | ||
email: string; | ||
username: string; | ||
password: string; | ||
gender: string; | ||
phoneNumber: string; | ||
} |
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,12 @@ | ||
import Sign from '@/widgets/Sign/Sign'; | ||
import React from 'react'; | ||
|
||
const SignPage = () => { | ||
return ( | ||
<div> | ||
<Sign /> | ||
</div> | ||
); | ||
}; | ||
|
||
export default SignPage; |
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,27 @@ | ||
import { AxiosError } from 'axios'; | ||
import defaultApi from '@/shared/api/api'; | ||
|
||
const api = defaultApi(); | ||
|
||
/** | ||
* 이메일 중복 여부를 확인하는 유틸리티 함수 | ||
* @param {string} email - 확인할 이메일 주소 | ||
* @returns {Promise<{ exists: boolean, message: string }>} - 이메일 중복 여부와 메시지 | ||
* @throws {Error} - 서버 에러 또는 네트워크 오류 발생 시 에러를 던짐 | ||
*/ | ||
export const checkEmailExists = async ( | ||
email: string | ||
): Promise<{ exists: boolean; message: string }> => { | ||
try { | ||
const response = await api.post('/check-username', { email }); | ||
const { exists, message } = response.data; | ||
return { exists, message }; | ||
} catch (error: unknown) { | ||
if (error instanceof AxiosError && error.response) { | ||
const serverMessage = | ||
error.response.data.message || '서버 에러가 발생했습니다.'; | ||
throw new Error(serverMessage); | ||
} | ||
throw new Error('네트워크 오류가 발생했습니다.'); | ||
} | ||
}; |
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,26 @@ | ||
import { JoinType } from '../../features/join/model/JoinType'; | ||
import { JoinParam } from '../../features/join/model/joinParams'; | ||
import defaultApi from '@/shared/api/api'; | ||
import { AxiosError } from 'axios'; | ||
|
||
const api = defaultApi(); | ||
|
||
export const join = async (params: JoinParam): Promise<JoinType> => { | ||
try { | ||
const { phoneNumber, ...restParams } = params; | ||
const modifiedParams = { | ||
...restParams, | ||
phone_number: phoneNumber | ||
}; | ||
|
||
const response = await api.post('/signup', modifiedParams); | ||
return response.data; | ||
} catch (error: unknown) { | ||
if (error instanceof AxiosError && error.response) { | ||
const serverMessage = | ||
error.response.data.message || '서버 에러가 발생했습니다.'; | ||
throw new Error(serverMessage); | ||
} | ||
throw new Error('네트워크 오류가 발생했습니다.'); | ||
} | ||
}; |
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,8 @@ | ||
export const EMAIL_REG_EXP: RegExp = | ||
/^[a-zA-Z0-9._%+-]+@[a-zA-Z0-9.-]+\.[a-zA-Z]{2,}$/; | ||
|
||
export const PHONE_NUMBER_REG_EXP: RegExp = | ||
/^(01[016789]-?\d{3,4}-?\d{4})$|^(0[2-8][0-5]?-?\d{3,4}-?\d{4})$/; | ||
|
||
export const PASSWORD_REG_EXP: RegExp = | ||
/^(?=.*[A-Za-z])(?=.*\d)(?=.*[!@#$%^&*()_+~`\-={}[\]:;"'<>,.?/]).{8,20}$/; |