-
Notifications
You must be signed in to change notification settings - Fork 44
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
[권주현] Week14 #449
Merged
devToram
merged 18 commits into
codeit-bootcamp-frontend:part3-권주현
from
kuum97:part3-권주현-week14
May 20, 2024
The head ref may contain hidden characters: "part3-\uAD8C\uC8FC\uD604-week14"
Merged
[권주현] Week14 #449
Changes from all commits
Commits
Show all changes
18 commits
Select commit
Hold shift + click to select a range
5f6545d
Merge upstream to origin
kuum97 fb4f9fc
Modify readme
kuum97 2fbf71f
Modify readme
kuum97 2f52738
Modify readme
kuum97 d8a10f5
Refactor project structure and update naming conventions
kuum97 8b15a47
Add Layout component and implement Zustand for global user data manag…
kuum97 84cb18b
Refactor folder page for data fetch
kuum97 c46649c
Rename handle props handle to on
kuum97 d3cf4e3
Add signin page component
kuum97 9e55dca
Add global Social button
kuum97 7c7d1b6
Add signin layout
kuum97 2ec6b06
Add signup layout
kuum97 abdf5c2
Implement auth pages
kuum97 1900f09
Add social link for auth social button
kuum97 874a795
Add react query
kuum97 c1fba4c
Implement email check logic
kuum97 f227a1e
Implement signup logic
kuum97 c2c4afe
Refactor form submit handler
kuum97 File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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,120 @@ | ||
import { SampleUser, UserData } from "@/types/user"; | ||
import { FolderData, SampleFolder } from "@/types/folder"; | ||
import { Response, SampleFolderResponse } from "@/types/response"; | ||
import { LinkData } from "@/types/link"; | ||
import { CODEIT_BASE_URL } from "@/constants"; | ||
import { FormValues } from "./common/Auth/Form"; | ||
|
||
export interface Params { | ||
[key: string]: number | null; | ||
} | ||
|
||
export async function getUser(): Promise<SampleUser> { | ||
const response = await fetch(`${CODEIT_BASE_URL}/sample/user`); | ||
if (!response.ok) { | ||
throw new Error("잘못된 요청입니다."); | ||
} | ||
|
||
const user: SampleUser = await response.json(); | ||
|
||
return user; | ||
} | ||
|
||
export async function getFolder(): Promise<SampleFolder> { | ||
const response = await fetch(`${CODEIT_BASE_URL}/sample/folder`); | ||
if (!response.ok) { | ||
throw new Error("잘못된 요청입니다."); | ||
} | ||
|
||
const data: SampleFolderResponse = await response.json(); | ||
const { folder } = data; | ||
|
||
return folder; | ||
} | ||
|
||
export async function getUserById({ userId }: Params): Promise<UserData> { | ||
const response = await fetch(`${CODEIT_BASE_URL}/users/${userId}`); | ||
if (!response.ok) { | ||
throw new Error("잘못된 요청입니다."); | ||
} | ||
|
||
const user: Response<UserData> = await response.json(); | ||
const { data } = user; | ||
|
||
return data[0]; | ||
} | ||
|
||
export async function getFoldersByUserId({ | ||
userId, | ||
}: Params): Promise<FolderData[]> { | ||
const response = await fetch(`${CODEIT_BASE_URL}/users/${userId}/folders`); | ||
if (!response.ok) { | ||
throw new Error("잘못된 요청입니다."); | ||
} | ||
|
||
const folders: Response<FolderData> = await response.json(); | ||
const { data } = folders; | ||
|
||
return data; | ||
} | ||
|
||
export async function getLinksByUserIdAndFolderId({ | ||
userId, | ||
folderId, | ||
}: Params): Promise<LinkData[]> { | ||
let url = `${CODEIT_BASE_URL}/users/${userId}/links`; | ||
if (folderId) { | ||
url += `?folderId=${folderId}`; | ||
} | ||
|
||
const response = await fetch(url); | ||
if (!response.ok) { | ||
throw new Error("잘못된 요청입니다."); | ||
} | ||
|
||
const links: Response<LinkData> = await response.json(); | ||
const { data } = links; | ||
|
||
return data; | ||
} | ||
|
||
export async function postEmailCheck(email: string): Promise<void | string> { | ||
const response = await fetch(`${CODEIT_BASE_URL}/check-email`, { | ||
method: "POST", | ||
headers: { | ||
"Content-Type": "application/json", | ||
}, | ||
body: JSON.stringify({ email }), | ||
}); | ||
|
||
if (response.status === 409) { | ||
const data = await response.json(); | ||
return data.error.message; | ||
} | ||
|
||
if (!response.ok) { | ||
throw new Error("잘못된 요청입니다."); | ||
} | ||
|
||
return; | ||
} | ||
|
||
export async function postSignup({ | ||
email, | ||
password, | ||
}: FormValues): Promise<void | string> { | ||
const response = await fetch(`${CODEIT_BASE_URL}/sign-up`, { | ||
method: "POST", | ||
headers: { | ||
"Content-Type": "application/json", | ||
}, | ||
body: JSON.stringify({ email, password }), | ||
}); | ||
|
||
if (!response.ok) { | ||
const data = await response.json(); | ||
return data.error.message; | ||
} | ||
|
||
return; | ||
} |
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,18 @@ | ||
.formContainer { | ||
width: 100%; | ||
max-width: 400px; | ||
display: flex; | ||
flex-direction: column; | ||
gap: 15px; | ||
} | ||
|
||
.submitBtn { | ||
font-size: 20px; | ||
width: 100%; | ||
height: 60px; | ||
border: none; | ||
border-radius: 8px; | ||
color: var(--white); | ||
background: var(--primary-gradient); | ||
margin-bottom: 15px; | ||
} |
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,35 @@ | ||
import { SubmitHandler, UseFormHandleSubmit, useForm } from "react-hook-form"; | ||
import styles from "./index.module.css"; | ||
import { ReactNode } from "react"; | ||
|
||
export interface FormValues { | ||
email: string; | ||
password: number; | ||
passwordConfirm?: number; | ||
} | ||
|
||
export interface AuthFormProps { | ||
children?: ReactNode; | ||
onSubmit: SubmitHandler<FormValues>; | ||
handleSubmit: UseFormHandleSubmit<FormValues, undefined>; | ||
purpose: string; | ||
} | ||
|
||
function AuthForm({ | ||
children, | ||
onSubmit, | ||
handleSubmit, | ||
purpose, | ||
}: AuthFormProps) { | ||
return ( | ||
<form className={styles.formContainer} onSubmit={handleSubmit(onSubmit)}> | ||
{children} | ||
<button className={styles.submitBtn} type="submit"> | ||
{(purpose === "signin" && "로그인") || | ||
(purpose === "signup" && "회원가입")} | ||
</button> | ||
</form> | ||
); | ||
} | ||
|
||
export default AuthForm; |
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,22 @@ | ||
.header { | ||
margin-bottom: 30px; | ||
display: flex; | ||
flex-direction: column; | ||
align-items: center; | ||
} | ||
|
||
.homeLink { | ||
width: 210px; | ||
height: 40px; | ||
position: relative; | ||
} | ||
|
||
.headerSecondLine { | ||
margin-top: 20px; | ||
} | ||
|
||
.toSignupLink { | ||
margin-left: 10px; | ||
color: var(--primary); | ||
font-weight: 600; | ||
} |
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,43 @@ | ||
import Image from "next/image"; | ||
import Link from "next/link"; | ||
import styles from "./index.module.css"; | ||
|
||
interface AuthHeaderProps { | ||
purpose: string; | ||
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. purpose 가 "signin" 아니면 "signup" 등 정해진 문자라서 조금 더 좁은 타입으로 정의해주심 좋을 거 같아요! |
||
} | ||
|
||
function AuthHeader({ purpose }: AuthHeaderProps) { | ||
return ( | ||
<header className={styles.header}> | ||
<Link className={styles.homeLink} href="/"> | ||
<Image | ||
fill | ||
src="/images/Linkbrary.png" | ||
alt="logo" | ||
style={{ objectFit: "contain" }} | ||
priority | ||
/> | ||
</Link> | ||
<div className={styles.headerSecondLine}> | ||
{(purpose === "signin" && ( | ||
<> | ||
<span>회원이 아니신가요?</span> | ||
<Link className={styles.toSignupLink} href="/signup"> | ||
회원 가입하기 | ||
</Link> | ||
</> | ||
)) || | ||
(purpose === "signup" && ( | ||
<> | ||
<span>이미 회원이신가요?</span> | ||
<Link className={styles.toSignupLink} href="/signin"> | ||
로그인 하기 | ||
</Link> | ||
</> | ||
))} | ||
</div> | ||
</header> | ||
); | ||
} | ||
|
||
export default AuthHeader; |
15 changes: 10 additions & 5 deletions
15
components/Input/Input.module.css → common/Auth/Input/index.module.css
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,35 +1,40 @@ | ||
.container { | ||
width: 350px; | ||
width: 100%; | ||
position: relative; | ||
} | ||
|
||
.inputWrapper { | ||
width: 100%; | ||
height: 60px; | ||
padding: 18px 15px; | ||
border: 1px solid var(--gray-500); | ||
border-radius: 8px; | ||
margin-bottom: 10px; | ||
} | ||
|
||
.inputWrapper:focus { | ||
border: 1px solid var(--primary); | ||
} | ||
|
||
.inputLabel { | ||
display: inline-block; | ||
margin-bottom: 15px; | ||
} | ||
|
||
.eyeSlash { | ||
border: none; | ||
background: none; | ||
position: absolute; | ||
right: 16px; | ||
top: 17px; | ||
top: 53px; | ||
} | ||
|
||
.errorBorder { | ||
border: 1px solid var(--red); | ||
} | ||
|
||
.errorMessage { | ||
display: inline-block; | ||
color: var(--red); | ||
font-size: 14px; | ||
font-weight: 400; | ||
color: var(--red); | ||
margin-top: 5px; | ||
} |
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,52 @@ | ||
import { HTMLInputTypeAttribute } from "react"; | ||
import { FaEyeSlash } from "react-icons/fa"; | ||
import styles from "./index.module.css"; | ||
import { | ||
FieldError, | ||
FieldErrorsImpl, | ||
FieldValues, | ||
Merge, | ||
} from "react-hook-form"; | ||
import classNames from "classnames"; | ||
|
||
interface AuthInputProps { | ||
label: string; | ||
type: HTMLInputTypeAttribute; | ||
placeholder: string; | ||
register: FieldValues; | ||
error?: FieldError | Merge<FieldError, FieldErrorsImpl>; | ||
} | ||
|
||
function AuthInput({ | ||
label, | ||
type, | ||
placeholder, | ||
register, | ||
error, | ||
}: AuthInputProps) { | ||
return ( | ||
<div className={styles.container}> | ||
<label className={styles.inputLabel} htmlFor={type}> | ||
{label} | ||
</label> | ||
<input | ||
type={type} | ||
placeholder={placeholder} | ||
className={classNames(styles.inputWrapper, { | ||
[styles.errorBorder]: error, | ||
})} | ||
{...register} | ||
/> | ||
{error && ( | ||
<p className={styles.errorMessage}>{error.message?.toString()}</p> | ||
)} | ||
{type === "password" && ( | ||
<button className={styles.eyeSlash} type="button"> | ||
<FaEyeSlash /> | ||
</button> | ||
)} | ||
</div> | ||
); | ||
} | ||
|
||
export default AuthInput; |
File renamed without changes.
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 @@ | ||
.shareButton { | ||
background: none; | ||
border: none; | ||
border-radius: 100%; | ||
display: flex; | ||
align-items: center; | ||
justify-content: center; | ||
} |
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,19 @@ | ||
import { ReactNode } from "react"; | ||
import styles from "./index.module.css"; | ||
|
||
interface SocialButtonProp { | ||
children: ReactNode; | ||
} | ||
|
||
function SocialButton({ children }: SocialButtonProp) { | ||
return ( | ||
<button | ||
className={styles.shareButton} | ||
// onClick={() => handleShareToKakao(title)} | ||
> | ||
{children} | ||
</button> | ||
); | ||
} | ||
|
||
export default SocialButton; |
File renamed without changes.
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
File renamed without changes.
Oops, something went wrong.
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
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.
삼항연산자를 사용하면 url 을 const 로 쓸 수 있을 거 같아요!