-
Notifications
You must be signed in to change notification settings - Fork 0
[4주차 기본/심화/공유 과제] SOPT 회원 조회 페이지 #10
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
base: main
Are you sure you want to change the base?
Changes from all commits
1a74c45
79da03b
a8d913a
8e3c3a8
f36a829
cf78438
87bd216
f9b5bc4
78a949c
e3e3965
06b3fd5
09ce997
896ff65
dace2c7
1577c6f
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,2 @@ | ||
| # .env | ||
| VITE_APP_BASE_URL=https://api.atsopt-seminar4.site |
| 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? |
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,12 @@ | ||
| # 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) uses [Babel](https://babeljs.io/) for Fast Refresh | ||
| - [@vitejs/plugin-react-swc](https://github.com/vitejs/vite-plugin-react/blob/main/packages/plugin-react-swc) uses [SWC](https://swc.rs/) for Fast Refresh | ||
|
|
||
| ## Expanding the ESLint configuration | ||
|
|
||
| If you are developing a production application, we recommend using TypeScript with type-aware lint rules enabled. Check out the [TS template](https://github.com/vitejs/vite/tree/main/packages/create-vite/template-react-ts) for information on how to integrate TypeScript and [`typescript-eslint`](https://typescript-eslint.io) in your project. |
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,33 @@ | ||
| import js from '@eslint/js' | ||
| import globals from 'globals' | ||
| import reactHooks from 'eslint-plugin-react-hooks' | ||
| import reactRefresh from 'eslint-plugin-react-refresh' | ||
|
|
||
| export default [ | ||
| { ignores: ['dist'] }, | ||
| { | ||
| files: ['**/*.{js,jsx}'], | ||
| languageOptions: { | ||
| ecmaVersion: 2020, | ||
| globals: globals.browser, | ||
| parserOptions: { | ||
| ecmaVersion: 'latest', | ||
| ecmaFeatures: { jsx: true }, | ||
| sourceType: 'module', | ||
| }, | ||
| }, | ||
| plugins: { | ||
| 'react-hooks': reactHooks, | ||
| 'react-refresh': reactRefresh, | ||
| }, | ||
| rules: { | ||
| ...js.configs.recommended.rules, | ||
| ...reactHooks.configs.recommended.rules, | ||
| 'no-unused-vars': ['error', { varsIgnorePattern: '^[A-Z_]' }], | ||
| 'react-refresh/only-export-components': [ | ||
| 'warn', | ||
| { allowConstantExport: true }, | ||
| ], | ||
| }, | ||
| }, | ||
| ] |
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,13 @@ | ||
| <!doctype html> | ||
| <html lang="en"> | ||
|
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. 3주차 과제 때 배웠는데 사소하지만 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>Vite + React</title> | ||
| </head> | ||
| <body> | ||
| <div id="root"></div> | ||
| <script type="module" src="/src/main.jsx"></script> | ||
| </body> | ||
| </html> | ||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,31 @@ | ||
| { | ||
| "name": "week4-hw", | ||
| "private": true, | ||
| "version": "0.0.0", | ||
| "type": "module", | ||
| "scripts": { | ||
| "dev": "vite", | ||
| "build": "vite build", | ||
| "lint": "eslint .", | ||
| "preview": "vite preview" | ||
| }, | ||
| "dependencies": { | ||
| "@emotion/react": "^11.14.0", | ||
| "@emotion/styled": "^11.14.0", | ||
| "axios": "^1.9.0", | ||
| "react": "^19.1.0", | ||
| "react-dom": "^19.1.0", | ||
| "react-router": "^7.6.0" | ||
| }, | ||
| "devDependencies": { | ||
| "@eslint/js": "^9.25.0", | ||
| "@types/react": "^19.1.2", | ||
| "@types/react-dom": "^19.1.2", | ||
| "@vitejs/plugin-react-swc": "^3.9.0", | ||
| "eslint": "^9.25.0", | ||
| "eslint-plugin-react-hooks": "^5.2.0", | ||
| "eslint-plugin-react-refresh": "^0.4.19", | ||
| "globals": "^16.0.0", | ||
| "vite": "^6.3.5" | ||
| } | ||
| } |
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,6 @@ | ||
| import { RouterProvider } from "react-router"; | ||
| import router from "./router/Router"; | ||
| const App = () => { | ||
| return <RouterProvider router={router} />; | ||
| }; | ||
| export default App; |
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,83 @@ | ||
| /** @jsxImportSource @emotion/react */ | ||
| import { css } from "@emotion/react"; | ||
| import { useState, useEffect } from "react"; | ||
| import { btnStyle } from "../pages/Login/LoginStyles.styles"; | ||
| import { | ||
| mainInputStyle, | ||
| myPageInputArea, | ||
| } from "../pages/MyPage/MyPageStyles.style"; | ||
| import api from "../services/api"; | ||
|
|
||
| const MyPageInput = ({ title, label, btnTxt, name }) => { | ||
| const [inputValue, setInputValue] = useState(""); | ||
| const [nicknameList, setNicknameList] = useState([]); | ||
| const [userId, setUserId] = useState(""); | ||
| useEffect(() => { | ||
| const storedUserId = localStorage.getItem("userId"); | ||
| if (storedUserId) { | ||
| setUserId(storedUserId); | ||
| } | ||
| }, []); | ||
| const handleUpdateNickname = async () => { | ||
| if (name === "myInfo") { | ||
| try { | ||
| const response = await api.patch( | ||
| "/api/v1/users", | ||
| { nickname: inputValue }, | ||
| { headers: { userId } } | ||
| ); | ||
| alert(`${inputValue}로 닉네임 변경 성공 !`); | ||
| } catch (error) { | ||
| console.error("Error updating nickname", error); | ||
| alert("닉네임을 변경하는 데 실패했습니다."); | ||
| } | ||
| } else if (name === "view") { | ||
| try { | ||
| const response = await api.get(`/api/v1/users?keyword=${inputValue}`); | ||
|
|
||
| const nicknameList = response.data.data.nicknameList || []; | ||
| if (nicknameList.length === 0) { | ||
| alert("닉네임이 없습니다."); | ||
| } else { | ||
| console.log("User details fetched successfully", response.data); | ||
| setNicknameList(nicknameList); | ||
| } | ||
| } catch (error) { | ||
| console.error("Error fetching user details", error); | ||
| alert("닉네임을 조회하는 데 실패했습니다."); | ||
| } | ||
|
Comment on lines
+34
to
+48
Member
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. 닉네임 변경이 아닌 부분은 따로 역할 분리를 하는 게 좋을 거 같아요 ! 혹시 하나로 작성하신 이유가 있을까요? |
||
| } else { | ||
| alert("회원 정보 보기 페이지에서는 닉네임을 변경할 수 없습니다."); | ||
| } | ||
| }; | ||
|
|
||
| return ( | ||
| <div css={myPageInputArea}> | ||
| <h1>{title}</h1> | ||
| <div>{label}</div> | ||
| <input | ||
| value={inputValue} | ||
| onChange={(e) => setInputValue(e.target.value)} | ||
| placeholder={label} | ||
| type="text" | ||
| css={mainInputStyle} | ||
| /> | ||
| <div css={btnStyle} onClick={handleUpdateNickname}> | ||
| {btnTxt} | ||
| </div> | ||
|
Comment on lines
+65
to
+67
Member
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. 클릭 가능한 요소는 button 태그를 사용하는게 시맨틱 측면에서 좋을듯 합니다 !!! |
||
|
|
||
| {name === "view" && nicknameList.length > 0 && ( | ||
| <div> | ||
| <h3>검색된 닉네임 목록</h3> | ||
| <ul> | ||
| {nicknameList.map((nickname, index) => ( | ||
| <li key={index}>{nickname}</li> | ||
| ))} | ||
|
Comment on lines
+73
to
+75
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. 리스트 렌더링 시 |
||
| </ul> | ||
| </div> | ||
| )} | ||
| </div> | ||
| ); | ||
| }; | ||
|
|
||
| export default MyPageInput; | ||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,9 @@ | ||
| import { StrictMode } from "react"; | ||
| import { createRoot } from "react-dom/client"; | ||
| import App from "./App.jsx"; | ||
|
|
||
| createRoot(document.getElementById("root")).render( | ||
| <StrictMode> | ||
| <App /> | ||
| </StrictMode> | ||
| ); |
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,76 @@ | ||
| /** @jsxImportSource @emotion/react */ | ||
| import { css } from "@emotion/react"; | ||
| import { useState, useEffect } from "react"; | ||
| import { useNavigate } from "react-router"; | ||
| import axios from "axios"; | ||
| import api from "../../services/api"; | ||
| import { | ||
| mainStyle, | ||
| formStyle, | ||
| formInputStyle, | ||
| btnStyle, | ||
| } from "./LoginStyles.styles"; | ||
|
|
||
| const Login = () => { | ||
| const [loginId, setLoginId] = useState(""); | ||
| const [password, setPassword] = useState(""); | ||
| const [userId, setUserId] = useState(""); | ||
| const navigate = useNavigate(); | ||
| useEffect(() => { | ||
| if (userId) { | ||
| localStorage.setItem("userId", userId); // userId가 변경되면 localStorage에 저장 | ||
| } | ||
| }, [userId]); | ||
| const fetchDetailData = async () => { | ||
| try { | ||
| const res = await api.post("/api/v1/auth/signin", { | ||
|
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. api 부분 axiosInstance 등을 통해 따로 분리해서 관리하면 더 편하고 깔끔해지더라구요!! 한 번 시도해보시는 걸 추천드리옵니다 |
||
| loginId, | ||
| password, | ||
| }); | ||
| console.log(res.data.data.userId); | ||
| setUserId(res.data.data.userId); | ||
| localStorage.setItem("userId", userId); | ||
|
Comment on lines
+31
to
+32
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.
|
||
| navigate("/mypage/myInfo"); | ||
| } catch (error) { | ||
| console.log(error.code); | ||
| } | ||
| }; | ||
| const handleLogin = () => { | ||
| if (loginId && password) { | ||
| fetchDetailData(); | ||
| } else { | ||
| alert("아이디와 비밀번호를 모두 입력해주세요."); | ||
| } | ||
| }; | ||
|
|
||
| return ( | ||
| <div css={mainStyle}> | ||
| <h2>로그인</h2> | ||
| <form css={formStyle}> | ||
| <h3>비밀번호</h3> | ||
| <div css={formInputStyle}> | ||
| <input | ||
| value={loginId} | ||
| onChange={(e) => setLoginId(e.target.value)} | ||
| placeholder="아이디" | ||
| type="text" | ||
| /> | ||
| <input | ||
| value={password} | ||
| onChange={(e) => setPassword(e.target.value)} | ||
| placeholder="비밀번호" | ||
| type="password" | ||
| /> | ||
| </div> | ||
| <div css={btnStyle} onClick={handleLogin}> | ||
| 로그인 | ||
| </div> | ||
|
Comment on lines
+65
to
+67
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. 로그인/회원가입 버튼이 div로 되어 있어서, <button css={btnStyle} onClick={handleLogin}>로그인</button> |
||
| <div css={btnStyle} onClick={() => navigate("/sign")}> | ||
| 회원가입 | ||
| </div> | ||
| </form> | ||
| </div> | ||
| ); | ||
| }; | ||
|
|
||
| export default Login; | ||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,44 @@ | ||
| /** @jsxImportSource @emotion/react */ | ||
| import { css } from "@emotion/react"; | ||
| export const mainStyle = css` | ||
| background-color: rgb(228, 228, 228); | ||
| width: 100%; | ||
| height: 100vh; | ||
| display: flex; | ||
| flex-direction: column; | ||
| gap: 50px; | ||
| align-items: center; | ||
| `; | ||
|
|
||
| export const formStyle = css` | ||
| display: flex; | ||
| flex-direction: column; | ||
| gap: 20px; | ||
| justify-content: center; | ||
| align-items: center; | ||
| `; | ||
| export const formInputStyle = css` | ||
| display: flex; | ||
| flex-direction: row; | ||
| gap: 20px; | ||
| & input { | ||
| width: 200px; | ||
| height: 30px; | ||
| border-radius: 10px; | ||
| border: none; | ||
| padding-left: 10px; | ||
| &:focus { | ||
| outline: none; | ||
| border: 1px solid black; | ||
| } | ||
| } | ||
| `; | ||
| export const btnStyle = css` | ||
| background-color: rgb(0, 0, 0); | ||
| color: white; | ||
| width: 100px; | ||
| padding: 10px; | ||
| border-radius: 10px; | ||
| cursor: pointer; | ||
| text-align: center; | ||
| `; |
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.
과제라서 상관없긴 하지만 다른 프로젝트에선 보안 등을 위해 해당 파일은
.gitignore에 추가하면 좋을 것 같습니다 ㅎㅎ!!