-
Notifications
You must be signed in to change notification settings - Fork 45
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #463 from SeungRyeolBaek/part3
[백승렬] Week14
- Loading branch information
Showing
134 changed files
with
3,112 additions
and
648 deletions.
There are no files selected for viewing
Large diffs are not rendered by default.
Oops, something went wrong.
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,21 @@ | ||
import { SignInForm, Oauth } from "@/src/feature"; | ||
import { SignHeader } from "@/src/ui"; | ||
import { SignLayout } from "@/src/page-layout/SignLayout"; | ||
import { ROUTE } from "@/src/util"; | ||
|
||
const SignInPage = () => { | ||
return ( | ||
<SignLayout | ||
header={ | ||
<SignHeader | ||
message="회원이 아니신가요?" | ||
link={{ text: "회원 가입하기", href: ROUTE.회원가입 }} | ||
/> | ||
} | ||
form={<SignInForm />} | ||
oauth={<Oauth description="소셜 로그인" />} | ||
/> | ||
); | ||
}; | ||
|
||
export default SignInPage; |
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,21 @@ | ||
import { Oauth, SignUpForm } from "@/src/feature"; | ||
import { SignHeader } from "@/src/ui"; | ||
import { SignLayout } from "@/src/page-layout/SignLayout"; | ||
import { ROUTE } from "@/src/util"; | ||
|
||
const SignUpPage = () => { | ||
return ( | ||
<SignLayout | ||
header={ | ||
<SignHeader | ||
message="이미 회원이신가요?" | ||
link={{ text: "로그인 하기", href: ROUTE.로그인 }} | ||
/> | ||
} | ||
form={<SignUpForm />} | ||
oauth={<Oauth description="다른 방식으로 가입하기" />} | ||
/> | ||
); | ||
}; | ||
|
||
export default SignUpPage; |
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
This file was deleted.
Oops, something went wrong.
This file was deleted.
Oops, something went wrong.
This file was deleted.
Oops, something went wrong.
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,37 @@ | ||
import { instance, useAsync } from "@/src/util"; | ||
import { useCallback } from "react"; | ||
|
||
/** | ||
* useCheckEmailDuplicate 훅은 이메일 중복 확인을 위한 비동기 요청을 처리합니다. | ||
* | ||
* @param email - 중복 확인할 이메일 주소입니다. | ||
* @returns 훅의 반환 객체입니다. | ||
* @returns return.execute - 이메일 중복 확인을 실행하는 함수입니다. | ||
* @returns return.loading - 이메일 중복 확인 요청의 로딩 상태입니다. | ||
* @returns return.error - 이메일 중복 확인 요청 중 발생한 오류입니다. | ||
* @returns return.data - 이메일 중복 확인 응답 데이터입니다. | ||
* | ||
* @example | ||
* const { execute, loading, error, data } = useCheckEmailDuplicate("[email protected]"); | ||
* | ||
* useEffect(() => { | ||
* execute(); | ||
* }, [execute]); | ||
*/ | ||
export const useCheckEmailDuplicate = (email: string) => { | ||
const checkEmailDuplicate = useCallback( | ||
() => | ||
instance.post<{ data: { isUsableNickname: boolean } }>("check-email", { | ||
email, | ||
}), | ||
[email] | ||
); | ||
const { execute, loading, error, data } = useAsync(checkEmailDuplicate, true); | ||
|
||
return { | ||
execute, | ||
loading, | ||
error, | ||
data, | ||
}; | ||
}; |
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 |
---|---|---|
@@ -1,13 +1,53 @@ | ||
import { useMemo } from "react"; | ||
import { instance, useAsync, mapFoldersData } from "@/src/util"; | ||
import { FolderRawData } from "@/src/type"; | ||
|
||
/** | ||
* useGetFolders 훅은 사용자 폴더 데이터를 가져와서 매핑된 폴더 데이터 배열을 반환합니다. | ||
* | ||
* @returns 훅의 반환 객체입니다. | ||
* @returns return.loading - 폴더 데이터를 가져오는 요청의 로딩 상태입니다. | ||
* @returns return.error - 폴더 데이터를 가져오는 요청 중 발생한 오류입니다. | ||
* @returns return.data - 매핑되고 정렬된 폴더 데이터 배열입니다. | ||
* @returns return.data[].id - 폴더의 고유 ID입니다. | ||
* @returns return.data[].createdAt - 폴더 생성 일자입니다. | ||
* @returns return.data[].name - 폴더의 이름입니다. | ||
* @returns return.data[].userId - 폴더 소유자의 사용자 ID입니다. | ||
* @returns return.data[].linkCount - 폴더에 포함된 링크의 개수입니다. | ||
* | ||
* @example | ||
* const { loading, error, data } = useGetFolders(); | ||
* | ||
* if (loading) { | ||
* return <div>Loading...</div>; | ||
* } | ||
* | ||
* if (error) { | ||
* return <div>Error occurred: {error.message}</div>; | ||
* } | ||
* | ||
* return ( | ||
* <div> | ||
* {data.map(folder => ( | ||
* <div key={folder.id}> | ||
* <h1>{folder.name}</h1> | ||
* <p>{folder.createdAt}</p> | ||
* <p>{folder.linkCount} links</p> | ||
* </div> | ||
* ))} | ||
* </div> | ||
* ); | ||
*/ | ||
export const useGetFolders = () => { | ||
const getFolders = () => | ||
instance.get<{ data: FolderRawData[] }>("users/1/folders"); | ||
const { loading, error, data } = useAsync(getFolders); | ||
|
||
const folders = mapFoldersData(data?.data); | ||
const sortedFolders = folders.sort((a, b) => a?.id - b?.id); | ||
const folders = useMemo(() => mapFoldersData(data?.data), [data?.data]); | ||
const sortedFolders = useMemo( | ||
() => folders.sort((a, b) => a?.id - b?.id), | ||
[folders] | ||
); | ||
|
||
return { loading, error, data: sortedFolders }; | ||
}; |
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,55 @@ | ||
import { instance, useAsync } from "@/src/util"; | ||
import { useCallback, useEffect } from "react"; | ||
import { Token } from "@/src/type"; | ||
|
||
type UseSignInParams = { email: string; password: string }; | ||
|
||
/** | ||
* useSignIn 훅은 사용자 인증을 처리하고, 토큰을 로컬 스토리지에 저장합니다. | ||
* | ||
* @param params - 사용자 인증에 필요한 이메일과 비밀번호입니다. | ||
* @param params.email - 사용자 이메일 주소입니다. | ||
* @param params.password - 사용자 비밀번호입니다. | ||
* @returns 훅의 반환 객체입니다. | ||
* @returns return.execute - 사용자 인증을 수동으로 실행하는 함수입니다. | ||
* @returns return.loading - 사용자 인증 요청의 로딩 상태입니다. | ||
* @returns return.error - 사용자 인증 요청 중 발생한 오류입니다. | ||
* @returns return.data - 사용자 인증 응답 데이터입니다. | ||
* | ||
* @example | ||
* const { execute, loading, error, data } = useSignIn({ email: "[email protected]", password: "password" }); | ||
* | ||
* const handleSignIn = async () => { | ||
* await execute(); | ||
* }; | ||
* | ||
* useEffect(() => { | ||
* if (data) { | ||
* console.log("로그인 성공:", data); | ||
* } | ||
* }, [data]); | ||
*/ | ||
export const useSignIn = ({ email, password }: UseSignInParams) => { | ||
const signIn = useCallback( | ||
() => | ||
instance.post<{ data: Token }>("sign-in", { | ||
email, | ||
password, | ||
}), | ||
[email, password] | ||
); | ||
const { execute, loading, error, data } = useAsync(signIn, true); | ||
|
||
useEffect(() => { | ||
if (data?.data.accessToken) { | ||
localStorage.setItem("accessToken", data.data.accessToken); | ||
} | ||
}, [data?.data.accessToken]); | ||
|
||
return { | ||
execute, | ||
loading, | ||
error, | ||
data, | ||
}; | ||
}; |
Oops, something went wrong.