Skip to content
Open
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
Binary file added .DS_Store
Binary file not shown.
24 changes: 24 additions & 0 deletions Login-FE/.gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
# Logs
logs
*.log
npm-debug.log*
yarn-debug.log*
yarn-error.log*
pnpm-debug.log*
lerna-debug.log*

node_modules
dist
dist-ssr
*.local

# Editor directories and files
.vscode/*
!.vscode/extensions.json
.idea
.DS_Store
*.suo
*.ntvs*
*.njsproj
*.sln
*.sw?
54 changes: 54 additions & 0 deletions Login-FE/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,54 @@
# React + TypeScript + Vite

This template provides a minimal setup to get React working in Vite with HMR and some ESLint rules.

Currently, two official plugins are available:

- [@vitejs/plugin-react](https://github.com/vitejs/vite-plugin-react/blob/main/packages/plugin-react/README.md) uses [Babel](https://babeljs.io/) for Fast Refresh
- [@vitejs/plugin-react-swc](https://github.com/vitejs/vite-plugin-react-swc) uses [SWC](https://swc.rs/) for Fast Refresh

## Expanding the ESLint configuration

If you are developing a production application, we recommend updating the configuration to enable type-aware lint rules:

```js
export default tseslint.config({
extends: [
// Remove ...tseslint.configs.recommended and replace with this
...tseslint.configs.recommendedTypeChecked,
// Alternatively, use this for stricter rules
...tseslint.configs.strictTypeChecked,
// Optionally, add this for stylistic rules
...tseslint.configs.stylisticTypeChecked,
],
languageOptions: {
// other options...
parserOptions: {
project: ['./tsconfig.node.json', './tsconfig.app.json'],
tsconfigRootDir: import.meta.dirname,
},
},
})
```

You can also install [eslint-plugin-react-x](https://github.com/Rel1cx/eslint-react/tree/main/packages/plugins/eslint-plugin-react-x) and [eslint-plugin-react-dom](https://github.com/Rel1cx/eslint-react/tree/main/packages/plugins/eslint-plugin-react-dom) for React-specific lint rules:

```js
// eslint.config.js
import reactX from 'eslint-plugin-react-x'
import reactDom from 'eslint-plugin-react-dom'

export default tseslint.config({
plugins: {
// Add the react-x and react-dom plugins
'react-x': reactX,
'react-dom': reactDom,
},
rules: {
// other rules...
// Enable its recommended typescript rules
...reactX.configs['recommended-typescript'].rules,
...reactDom.configs.recommended.rules,
},
})
```
28 changes: 28 additions & 0 deletions Login-FE/eslint.config.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
import js from '@eslint/js'
import globals from 'globals'
import reactHooks from 'eslint-plugin-react-hooks'
import reactRefresh from 'eslint-plugin-react-refresh'
import tseslint from 'typescript-eslint'

export default tseslint.config(
{ ignores: ['dist'] },
{
extends: [js.configs.recommended, ...tseslint.configs.recommended],
files: ['**/*.{ts,tsx}'],
languageOptions: {
ecmaVersion: 2020,
globals: globals.browser,
},
plugins: {
'react-hooks': reactHooks,
'react-refresh': reactRefresh,
},
rules: {
...reactHooks.configs.recommended.rules,
'react-refresh/only-export-components': [
'warn',
{ allowConstantExport: true },
],
},
},
)
13 changes: 13 additions & 0 deletions Login-FE/index.html
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
<!doctype html>
<html lang="en">
<head>
<meta charset="UTF-8" />
<link rel="icon" type="image/svg+xml" href="/vite.svg" />
<meta name="viewport" content="width=device-width, initial-scale=1.0" />
<title>Vite + React + TS</title>
</head>
<body>
<div id="root"></div>
<script type="module" src="/src/main.tsx"></script>
</body>
</html>
32 changes: 32 additions & 0 deletions Login-FE/package.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
{
"name": "login-fe",
"private": true,
"version": "0.0.0",
"type": "module",
"scripts": {
"dev": "vite",
"build": "tsc -b && vite build",
"lint": "eslint .",
"preview": "vite preview"
},
"dependencies": {
"@tailwindcss/vite": "^4.1.3",
"react": "^19.0.0",
"react-dom": "^19.0.0",
"react-router-dom": "^7.5.0",
"tailwindcss": "^4.1.3"
},
"devDependencies": {
"@eslint/js": "^9.21.0",
"@types/react": "^19.0.10",
"@types/react-dom": "^19.0.4",
"@vitejs/plugin-react-swc": "^3.8.0",
"eslint": "^9.21.0",
"eslint-plugin-react-hooks": "^5.1.0",
"eslint-plugin-react-refresh": "^0.4.19",
"globals": "^15.15.0",
"typescript": "~5.7.2",
"typescript-eslint": "^8.24.1",
"vite": "^6.2.0"
}
}
1 change: 1 addition & 0 deletions Login-FE/public/vite.svg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Empty file added Login-FE/src/App.css
Empty file.
30 changes: 30 additions & 0 deletions Login-FE/src/App.tsx

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

고생하셨습니다~!

Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@

import "./App.css"
import { createBrowserRouter, RouterProvider } from 'react-router'

import NotFoundPage from './pages/NotFoundPage'
import LoginPage from './pages/LoginPage'
import HomeLayout from './layouts/HomeLayouts'
import HomePage from './pages/HomePage'
import SignupPage from './pages/SignupPage'


const router = createBrowserRouter([
{
path: "/",
element: <HomeLayout />,
errorElement: <NotFoundPage />,
children: [
{index: true, element: <HomePage />},
{path: 'login', element: <LoginPage />},
{path: 'signup', element: <SignupPage />},
],
}
])

function App() {

return <RouterProvider router={router} />
}

export default App
1 change: 1 addition & 0 deletions Login-FE/src/assets/react.svg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
4 changes: 4 additions & 0 deletions Login-FE/src/global.d.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
declare module '*.css' {
const content: { [className: string]: string };
export default content;
}
55 changes: 55 additions & 0 deletions Login-FE/src/hooks/useForm.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,55 @@
import { ChangeEvent, useEffect, useState } from 'react';

interface UseFormProps<T> {
initialValues: T; // {email: '', password: ''}
validate: (values: T) => Record<keyof T, string> //값이 올마른지 검증하는 함수
}

function useForm<T>({initialValues, validate}: UseFormProps<T>) {

const [values, setValues] = useState(initialValues);

const [touched, setTouched] = useState<Record<string, boolean>>() // 아직입력 안했는데 에러뜨면 기분 나쁨

const [errors, setErrors] = useState<Record<string, string>>()

//사용자가 입력값 바꿀 때 실행되는 함수
const handleChange = (name: keyof T, text: string) => {
setValues({
...values, //기존 입력값 유지
[name]: text,
})
}

const handleBlur = (name: keyof T) => {
setTouched({
...touched,
[name]: true,
})
}


//이메일 인풋, 패스워드 인풋, 속성들을 가져오는 것
const getInputProps = (name: keyof T) => {
const value: T[keyof T] = values[name]
const onChange = (
e: ChangeEvent<HTMLInputElement | HTMLTextAreaElement>,
) => handleChange(name, e.target.value)
const onBlur = () => handleBlur(name)

return {value, onChange, onBlur}
}

//values가 변경될 때마다 에러 검증 로직
// {email: ''}
useEffect(() => {
if (validate) {
const newErrors = validate(values)
setErrors(newErrors) // update errors message
}
},[validate, values])

return {values, errors, touched, getInputProps}
}

export default useForm
1 change: 1 addition & 0 deletions Login-FE/src/index.css
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
@import "tailwindcss"
15 changes: 15 additions & 0 deletions Login-FE/src/layouts/HomeLayouts.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
import { Outlet } from 'react-router-dom';


const HomeLayout = () => {
return (
<div className = "h-dvh flex flex-col">
<nav>navigation bar</nav>
<main className='flex-1'>
<Outlet />
</main>
<footer>footer</footer>
</div>
);
}
export default HomeLayout;
12 changes: 12 additions & 0 deletions Login-FE/src/main.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@

import { StrictMode } from 'react'
import { createRoot } from 'react-dom/client'
import './index.css'
import App from './App.tsx'

createRoot(document.getElementById('root')!).render(
<StrictMode>
<App />
</StrictMode>,
)

8 changes: 8 additions & 0 deletions Login-FE/src/pages/HomePage.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
const HomePage = () => {
return (
<div>
home page
</div>
);
}
export default HomePage;
46 changes: 46 additions & 0 deletions Login-FE/src/pages/LoginPage.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,46 @@
import useForm from '../hooks/useForm';
import { UserSigninInformation, validateSignin } from '../utils/validate';

const LoginPage = () => {

const {values, errors,touched, getInputProps} = useForm<UserSigninInformation>({
initialValues: {
email: '',
password: '',
},
validate: validateSignin,
})


const handleSubmit = () => {}

return (
<div className="flex flex-col items-center justify-center h-full gap-4">
<div className='flex flex-col gap-3'>
<input
{...getInputProps('email')}
type={"email"}
className={`border border-[#ccc] w-[300px] p-[10px] focus:border-[#807bff] rounded-sm
${errors?.email &&touched?.email ? "border-red-500 bg-red-200" : "border-gray-300"}`}
placeholder={"이메일"}
/>
{errors?.email &&touched?.email &&(<div className='text-red-500 text-sm'>{errors.email}</div>)}
<input
{...getInputProps('password')}
type={"password"}
className={'border border-[#ccc] w-[300px] p-[10px] focus:border-[#807bff] rounded-sm'}
placeholder={"비밀번호"}
/>
<button
type='button'
onClick={handleSubmit}
disabled={false}
className='w-full bg-[#807bff] text-white p-[10px] rounded-sm hover:bg-[#807bff]/80 active:bg-[#807bff]/90 disabled:bg-[#807bff]/50'
>
로그인
</button>
</div>
</div>
);
}
export default LoginPage;
8 changes: 8 additions & 0 deletions Login-FE/src/pages/NotFoundPage.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
const NotFoundPage = () => {
return (
<div>
Not found
</div>
);
}
export default NotFoundPage;
8 changes: 8 additions & 0 deletions Login-FE/src/pages/SignupPage.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@


const SignupPage = () => {
return (
<div>SignupPage</div>
)
}
export default SignupPage
28 changes: 28 additions & 0 deletions Login-FE/src/utils/validate.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
export type UserSigninInformation = {
email: string;
password: string;
}

function validateUser(values: UserSigninInformation) {
const errors = {
email: '',
password: '',
}

if(!/^[0-9a-zA-Z]([-_.]?[0-9a-zA-Z])*@[0-9a-zA-Z]([-_.]?[0-9a-zA-Z])*\.[a-zA-Z]{2,3}$/i.test(values.email)) {
errors.email = '올바른 이메일 형식이 아닙니다.'
}

// 비밀번호는 8자 이상 20자 이하
if (values.password.length < 8 || values.password.length > 20) {
errors.password = '비밀번호는 8자 이상 20자 이하로 입력해주세요.'
}
return errors
}

//로그인 유효성 검사
function validateSignin(values: UserSigninInformation) {
return validateUser(values)
}

export {validateSignin}
Empty file added Login-FE/src/vite-env.d.ts
Empty file.
Loading