Skip to content
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

Feat: create login page #45

Merged
merged 6 commits into from
Jan 8, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
28 changes: 28 additions & 0 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

3 changes: 2 additions & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@
"framer-motion": "^10.16.16",
"react": "^18.2.0",
"react-dom": "^18.2.0",
"react-hook-form": "^7.49.2",
"react-icons": "^4.12.0",
"react-router-dom": "^6.21.1",
"recoil": "^0.7.7"
Expand Down Expand Up @@ -54,7 +55,7 @@
"vite": "^5.0.8",
"vite-plugin-svgr": "^4.2.0"
},
"msw": {
"msw": {
"workerDirectory": "public"
}
}
3 changes: 3 additions & 0 deletions src/assets/icons/removeBtn.svg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added src/assets/kakao/kakao_login_large_narrow.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added src/assets/kakao/kakao_login_large_wide.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added src/assets/kakao/kakao_login_medium_narrow.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added src/assets/kakao/kakao_login_medium_wide.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
3 changes: 3 additions & 0 deletions src/assets/kakao/kakao_path.svg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
14 changes: 14 additions & 0 deletions src/assets/logo.svg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
47 changes: 47 additions & 0 deletions src/components/Auth/Input/Input.module.scss
Original file line number Diff line number Diff line change
@@ -0,0 +1,47 @@
@use "@/sass" as *;
.container {
position: relative;

label {
display: block;

@include typography(tabLabel);
color: $neutral900;
}

&:focus-within {
input {
outline: none;
border-width: 1px;
border-color: $primary300;
}

.removeBtn {
display: block;
}
}

.input {
width: 100%;
margin-top: 6px;
margin-bottom: 24px;
padding: 16px;
border: 1px solid $neutral200;
border-radius: 8px;

@include typography(bodyLarge);
color: $neutral900;

&::placeholder {
color: $neutral400;
}
}

.removeBtn {
display: none;
position: absolute;
top: 47px;
right: 14px;
cursor: default;
}
}
44 changes: 44 additions & 0 deletions src/components/Auth/Input/InputEmail.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,44 @@
import styles from "./Input.module.scss";

import RemoveBtn from "@/assets/icons/removeBtn.svg?react";

import { LoginInput } from "@/types/auth";

function InputEmail({ label, register, dirtyFields, resetField }: LoginInput) {
const resetEmail = () => {
resetField("email");
};

return (
<section className={styles.container}>
<label htmlFor="email">{label}</label>

<input
id="email"
className={styles.input}
type="text"
placeholder="이메일 주소를 입력해주세요"
{...register("email", {
pattern: {
value:
/^[0-9a-zA-Z]([-_.]?[0-9a-zA-Z])*@[0-9a-zA-Z]([-_.]?[0-9a-zA-Z])*\.[a-zA-Z]{2,3}$/,
message: "이메일 형식이 올바르지 않습니다.",
},
})}
/>

{dirtyFields.email && (
<button
type="button"
className={styles.removeBtn}
onClick={resetEmail}
tabIndex={-1}
>
<RemoveBtn className={styles.svg} />
</button>
)}
</section>
);
}

export default InputEmail;
48 changes: 48 additions & 0 deletions src/components/Auth/Input/InputPassword.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,48 @@
import styles from "./Input.module.scss";

import RemoveBtn from "@/assets/icons/removeBtn.svg?react";

import { LoginInput } from "@/types/auth";

function InputPassword({
label,
register,
dirtyFields,
resetField,
}: LoginInput) {
const resetPassword = () => {
resetField("password");
};

return (
<section className={styles.container}>
<label htmlFor="password">{label}</label>

<input
id="password"
className={styles.input}
type="password"
placeholder="비밀번호를 입력해주세요"
{...register("password", {
pattern: {
value: /^(?=.*[a-zA-Z])(?=.*[!@#$%^*+=-])(?=.*[0-9]).{8,16}$/,
message: "비밀번호 형식이 올바르지 않습니다.",
},
})}
/>

{dirtyFields.password && (
<button
type="button"
className={styles.removeBtn}
onClick={resetPassword}
tabIndex={-1}
>
<RemoveBtn className={styles.svg} />
</button>
)}
</section>
);
}

export default InputPassword;
31 changes: 31 additions & 0 deletions src/components/Auth/Login/LoginForm.module.scss
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
@use "@/sass" as *;

.container {
position: relative;

small {
width: 100%;
position: absolute;
bottom: 65px;
left: 0;
text-align: center;

@include typography(captionSmall);
color: $danger300;
}

.submitBtn {
width: 100%;
padding: 13px 0;
background: $primary300;
margin-top: 32px;
border-radius: 16px;

@include typography(button);
color: $neutral0;

&:hover {
background: $primary400;
}
}
}
76 changes: 76 additions & 0 deletions src/components/Auth/Login/LoginForm.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,76 @@
import { useState } from "react";
import { useForm } from "react-hook-form";

import styles from "./LoginForm.module.scss";

import InputEmail from "../Input/InputEmail";
import InputPassword from "../Input/InputPassword";

import { LoginForm, SubmitResult } from "@/types/auth";

function LoginForm() {
const {
register,
resetField,
formState: { errors, dirtyFields },
} = useForm<LoginForm>({
mode: "onChange",
defaultValues: {
email: "",
password: "",
},
});

const [submitResult, setSubmitResult] = useState<SubmitResult>({
try: false,
isPassed: false,
});

const clickLogin = () => {
setSubmitResult({ ...submitResult, try: true });

const isError = Object.keys(errors).length > 0;
if (isError) {
setSubmitResult({ try: true, isPassed: false });
return;
}

setSubmitResult({ try: true, isPassed: true });

// 이메일 비밀번호 validation 성공
// 로그인 api 요청
/*
*
*
*
*/
};

return (
<form className={styles.container}>
<InputEmail
label="이메일"
register={register}
resetField={resetField}
dirtyFields={dirtyFields}
/>

<InputPassword
label="비밀번호"
register={register}
resetField={resetField}
dirtyFields={dirtyFields}
/>

{submitResult.try && !submitResult.isPassed ? (
<small>이메일 또는 비밀번호를 확인해주세요.</small>
) : null}

<button className={styles.submitBtn} type="button" onClick={clickLogin}>
로그인
</button>
</form>
);
}

export default LoginForm;
Loading