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

[ 4주차 기본/생각 과제 ] 로그인/회원가입 🍁 #7

Open
wants to merge 14 commits into
base: main
Choose a base branch
from
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
25 changes: 25 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
.env
# 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?
File renamed without changes.
20 changes: 20 additions & 0 deletions assignment/week04/login-project/.eslintrc.cjs
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
module.exports = {
root: true,
env: { browser: true, es2020: true },
extends: [
'eslint:recommended',
'plugin:react/recommended',
'plugin:react/jsx-runtime',
'plugin:react-hooks/recommended',
],
ignorePatterns: ['dist', '.eslintrc.cjs'],
parserOptions: { ecmaVersion: 'latest', sourceType: 'module' },
settings: { react: { version: '18.2' } },
plugins: ['react-refresh'],
rules: {
'react-refresh/only-export-components': [
'warn',
{ allowConstantExport: true },
],
},
}
25 changes: 25 additions & 0 deletions assignment/week04/login-project/.gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
.env
# 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?
8 changes: 8 additions & 0 deletions assignment/week04/login-project/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
# React + 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
13 changes: 13 additions & 0 deletions assignment/week04/login-project/index.html
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
<!DOCTYPE html>
<html lang="ko">
<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>week04 과제</title>
</head>
<body>
<div id="root"></div>
<script type="module" src="/src/main.jsx"></script>
</body>
</html>
26 changes: 26 additions & 0 deletions assignment/week04/login-project/package.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
{
"name": "login-project",
"private": true,
"version": "0.0.0",
"type": "module",
"scripts": {
"dev": "vite",
"build": "vite build",
"lint": "eslint . --ext js,jsx --report-unused-disable-directives --max-warnings 0",
"preview": "vite preview"
},
"dependencies": {
"react": "^18.2.0",
"react-dom": "^18.2.0"
},
Comment on lines +12 to +15

Choose a reason for hiding this comment

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

오잉 axios가 설치가 안되어 있나용 ?! 확인 해보면 좋을것 같습니댜

"devDependencies": {
"@types/react": "^18.2.37",
"@types/react-dom": "^18.2.15",
"@vitejs/plugin-react": "^4.2.0",
"eslint": "^8.53.0",
"eslint-plugin-react": "^7.33.2",
"eslint-plugin-react-hooks": "^4.6.0",
"eslint-plugin-react-refresh": "^0.4.4",
"vite": "^5.0.0"
}
}
1 change: 1 addition & 0 deletions assignment/week04/login-project/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.
17 changes: 17 additions & 0 deletions assignment/week04/login-project/src/App.jsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
import GlobalStyle from "./styles/GlobalStyle";
import Router from "./components/Router";
import { ThemeProvider } from "styled-components";
import theme from "./styles/theme";

function App() {
return (
<>
<ThemeProvider theme={theme}>
<GlobalStyle />
<Router />
</ThemeProvider>
</>
);
}

export default App;
Binary file added assignment/week04/login-project/src/assets/5.jpg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
1 change: 1 addition & 0 deletions assignment/week04/login-project/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.
19 changes: 19 additions & 0 deletions assignment/week04/login-project/src/components/Router.jsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
import React from "react";
import { BrowserRouter, Route, Routes } from "react-router-dom";
import Login from "../pages/Login";
import Signup from "../pages/Signup";
import Mypage from "../pages/Mypage";

const Router = () => {
return (
<BrowserRouter>
<Routes>
<Route path="/login" element={<Login />} />
<Route path="/signup" element={<Signup />} />
<Route path="/mypage/:userId" element={<Mypage />} />
</Routes>
</BrowserRouter>
);
};

export default Router;
9 changes: 9 additions & 0 deletions assignment/week04/login-project/src/main.jsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
import React from "react";
import ReactDOM from "react-dom/client";
import App from "./App";

ReactDOM.createRoot(document.getElementById("root")).render(
<React.StrictMode>
<App />
</React.StrictMode>
);
69 changes: 69 additions & 0 deletions assignment/week04/login-project/src/pages/Login.jsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,69 @@
import axios from "axios";
import React, { useState } from "react";
import { Link, useNavigate } from "react-router-dom";
import { St } from "../styles/Design";

Choose a reason for hiding this comment

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

혹시 스타일 파일을 따로 만든 이유가 이쓸까요 ?!
궁금합니댜 💭!!

Copy link
Member Author

Choose a reason for hiding this comment

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

저는, , ,, 여러파일에서 동일한 styled component가 반복해서 쓰이면 그걸 매 파일마다 작성하기 귀찮아증후군이 있기 때문에 ,, 분리해서 import해서 사용하곤합니당 ,,


const Login = () => {
const navigate = useNavigate();
const [id, setId] = useState("");
const [password, setPassword] = useState("");
const onIdChange = (e) => {
setId(e.target.value.toString());
};
const onPasswordChange = (e) => {
setPassword(e.target.value.toString());
};
const onRegisterBtnClick = () => {
navigate("/signup");
};
const onLoginBtnClick = () => {
try {
axios
.post(`${import.meta.env.VITE_BASE_URL}/api/v1/members/sign-in`, {
username: id,
password: password,
})
.then((res) => {
navigate(`/mypage/${res.data.id}`);
});
} catch (err) {
console.log(err);
}
};
return (
<St.ModalContainer>
<St.ModalBox>
<St.ModalTitle>Login</St.ModalTitle>
<St.InputContainer>
<St.InputCategory>ID</St.InputCategory>
<St.InputBox
required
placeholder="아이디를 입력해주세요"
onChange={onIdChange}
></St.InputBox>
</St.InputContainer>
<St.InputContainer>
<St.InputCategory>PASSWORD</St.InputCategory>
<St.InputBox
placeholder="비밀번호를 입력해주세요"
required
onChange={onPasswordChange}
></St.InputBox>
</St.InputContainer>
<St.ButtonContainer>
<St.SubmitButton type="button" onClick={onLoginBtnClick}>
로그인
</St.SubmitButton>
<Link to={"/signup"}>
<St.RegisterButton type="button">회원가입</St.RegisterButton>
</Link>
Comment on lines +57 to +59

Choose a reason for hiding this comment

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

Link 자체를 스타일링 하는 방법두 있어용!
RegisterLink = styled(Link) 이런식으로 가능합니다!
참고참고 ~

Copy link
Member Author

Choose a reason for hiding this comment

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

헐랭! 합세때 바로 써먹어봐야징 ,,

{/* <St.RegisterButton onClick={onRegisterBtnClick}>
회원가입
</St.RegisterButton> */}
Comment on lines +60 to +62

Choose a reason for hiding this comment

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

주석 지우기 얍!

</St.ButtonContainer>
</St.ModalBox>
</St.ModalContainer>
);
};

export default Login;
50 changes: 50 additions & 0 deletions assignment/week04/login-project/src/pages/Mypage.jsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,50 @@
import axios from "axios";
import React, { useEffect, useState } from "react";
import { Link, useNavigate, useParams } from "react-router-dom";
import { St } from "../styles/Design";
import img from "../assets/5.jpg";
const Mypage = () => {
const { userId } = useParams();
const navigate = useNavigate();
const [username, setUserName] = useState("");
const [nickname, setNickName] = useState("");
useEffect(() => {
userId !== "" && getUserInfo();
Copy link
Member

Choose a reason for hiding this comment

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

이 코드는 결고ㅏ가 어떻게 나오는건가요??!!,,,

}, [userId]);
const getUserInfo = () => {
try {
axios
.get(`${import.meta.env.VITE_BASE_URL}/api/v1/members/${userId}`)
.then((response) => {
setUserName(response.data.username);
setNickName(response.data.nickname);
Comment on lines +19 to +20

Choose a reason for hiding this comment

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

const {username, nickname} = responose.data
=> 이런식으로 구조분해 할당으로 가져오는것도 가능합니당!

});
} catch (err) {
console.log(err);
}
};
const onLogoutBtnClick = () => {
navigate("/login");
};
return (
<St.ModalContainer>
<St.ModalBox>
<St.ModalTitle>MY PAGE</St.ModalTitle>
<St.UserInfoContainer>
<St.UserProfile src={img} alt="profile" />
<St.UserInfoBox>
<St.UserInfo>ID : {username}</St.UserInfo>
<St.UserInfo>닉네임 : {nickname}</St.UserInfo>
</St.UserInfoBox>
</St.UserInfoContainer>
<St.ButtonContainer>
<St.SubmitButton type="button" onClick={onLogoutBtnClick}>
로그아웃
</St.SubmitButton>
</St.ButtonContainer>
</St.ModalBox>
</St.ModalContainer>
);
};

export default Mypage;
Loading