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주차 기본/심화/공유 과제] 회원가입 페이지 #5

Open
wants to merge 18 commits into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
18 commits
Select commit Hold shift + click to select a range
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
1 change: 1 addition & 0 deletions week4/assignment/.env
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
VITE_SERVER_URL = http://223.130.135.50:8085
24 changes: 24 additions & 0 deletions week4/assignment/.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?
50 changes: 50 additions & 0 deletions week4/assignment/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,50 @@
# 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:

- Configure the top-level `parserOptions` property like this:

```js
export default tseslint.config({
languageOptions: {
// other options...
parserOptions: {
project: ['./tsconfig.node.json', './tsconfig.app.json'],
tsconfigRootDir: import.meta.dirname,
},
},
})
```

- Replace `tseslint.configs.recommended` to `tseslint.configs.recommendedTypeChecked` or `tseslint.configs.strictTypeChecked`
- Optionally add `...tseslint.configs.stylisticTypeChecked`
- Install [eslint-plugin-react](https://github.com/jsx-eslint/eslint-plugin-react) and update the config:

```js
// eslint.config.js
import react from 'eslint-plugin-react'

export default tseslint.config({
// Set the react version
settings: { react: { version: '18.3' } },
plugins: {
// Add the react plugin
react,
},
rules: {
// other rules...
// Enable its recommended rules
...react.configs.recommended.rules,
...react.configs['jsx-runtime'].rules,
},
})
```
13 changes: 13 additions & 0 deletions week4/assignment/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 week4/assignment/package.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
{
"name": "assignment",
"private": true,
"version": "0.0.0",
"type": "module",
"scripts": {
"dev": "vite",
"build": "tsc -b && vite build",
"lint": "eslint .",
"preview": "vite preview"
},
"dependencies": {
"@emotion/react": "^11.13.3",
"axios": "^1.7.7",
"react": "^18.3.1",
"react-dom": "^18.3.1",
"react-router-dom": "^6.28.0"
},
"devDependencies": {
"@eslint/js": "^9.13.0",
"@types/react": "^18.3.12",
"@types/react-dom": "^18.3.1",
"@vitejs/plugin-react-swc": "^3.5.0",
"eslint": "^9.13.0",
"eslint-plugin-react-hooks": "^5.0.0",
"eslint-plugin-react-refresh": "^0.4.14",
"globals": "^15.11.0",
"typescript": "~5.6.2",
"typescript-eslint": "^8.11.0",
"vite": "^5.4.10"
}
}
1 change: 1 addition & 0 deletions week4/assignment/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.
42 changes: 42 additions & 0 deletions week4/assignment/src/App.css
Original file line number Diff line number Diff line change
@@ -0,0 +1,42 @@
#root {
max-width: 1280px;
margin: 0 auto;
padding: 2rem;
text-align: center;
}

.logo {
height: 6em;
padding: 1.5em;
will-change: filter;
transition: filter 300ms;
}
.logo:hover {
filter: drop-shadow(0 0 2em #646cffaa);
}
.logo.react:hover {
filter: drop-shadow(0 0 2em #61dafbaa);
}

@keyframes logo-spin {
from {
transform: rotate(0deg);
}
to {
transform: rotate(360deg);
}
}

@media (prefers-reduced-motion: no-preference) {
a:nth-of-type(2) .logo {
animation: logo-spin infinite 20s linear;
}
}

.card {
padding: 2em;
}

.read-the-docs {
color: #888;
}
21 changes: 21 additions & 0 deletions week4/assignment/src/App.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
import { Global, ThemeProvider } from "@emotion/react";
import theme from "./styles/theme";
import GlobalStyle from "./styles/global";
import { createBrowserRouter, RouterProvider } from "react-router-dom";
import authRoutes from "./routers/authRoutes";
import myPageRoutes from "./routers/myPageRoutes";

const App = () => {
const router = createBrowserRouter([...authRoutes, ...myPageRoutes]);

return (
<>
<ThemeProvider theme={theme}>
<Global styles={GlobalStyle} />
<RouterProvider router={router} />
</ThemeProvider>
</>
);
};

export default App;
38 changes: 38 additions & 0 deletions week4/assignment/src/apis/getUserHobby.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,38 @@
import { isAxiosError } from "axios";
import serverAxios from "./serverAxios";

const getUserHobby = async () => {
try {
const token = localStorage.getItem("authToken");
const response = await serverAxios.get("/user/my-hobby", {
headers: {
token: `${token}`,
},
});

return response.data.result?.hobby;
} catch (error) {
if (isAxiosError(error)) {
const statusCode = error.response?.status;
let errorMessage = "에러가 발생했습니다.";

if (!statusCode) {
errorMessage = "네트워크 에러입니다.";
} else if (statusCode >= 500) {
errorMessage = "서버 내부 에러입니다.";
} else if (
statusCode === 401 ||
statusCode === 403 ||
statusCode === 404
) {
errorMessage = "잘못된 요청입니다.";
}

throw new Error(errorMessage);
} else {
throw new Error("담당자에게 문의하세요.");
}
}
};

export default getUserHobby;
22 changes: 22 additions & 0 deletions week4/assignment/src/apis/getUserHobbyByNo.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
import { isAxiosError } from "axios";
import serverAxios from "./serverAxios";

const getUserHobbyByNo = async (userNumber: number) => {
try {
const token = localStorage.getItem("authToken");
const response = await serverAxios.get(`/user/${userNumber}/hobby`, {
headers: {
token: `${token}`,
},
});
return response.data.result?.hobby;
} catch (error) {
if (isAxiosError(error)) {
throw new Error("없는 사용자 입니다.");
} else {
throw new Error("담당자에게 문의하세요.");
}
}
};

export default getUserHobbyByNo;
38 changes: 38 additions & 0 deletions week4/assignment/src/apis/postLogin.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,38 @@
import { isAxiosError } from "axios";
import serverAxios from "./serverAxios";
import { LoginInfoType } from "../types/authType";

const postLogin = async (loginInfo: LoginInfoType) => {
try {
const response = await serverAxios.post("/login", {
username: loginInfo.username,
password: loginInfo.password,
});

const token = response.data.result?.token;

if (token) {
return token;
}

throw new Error("Login failed: " + (response.data.code || "Unknown error"));
} catch (error) {
if (isAxiosError(error)) {
const statusCode = error.response?.status;
let errorMessage = "에러입니다.";

if (!statusCode) {
errorMessage = "네트워크 에러입니다.";
} else if (statusCode >= 500) {
errorMessage = "서버 내부 에러입니다.";
} else if (statusCode === 400 || statusCode === 403) {
errorMessage = "잘못된 아이디/비밀번호 입니다.";
}
throw new Error(errorMessage);
} else {
throw new Error("담당자에게 문의하세요.");
}
}
};

export default postLogin;
35 changes: 35 additions & 0 deletions week4/assignment/src/apis/postUser.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,35 @@
import { isAxiosError } from "axios";
import serverAxios from "./serverAxios";
import { SignupInfoType } from "../types/authType";

export const postUser = async (signupInfo: SignupInfoType) => {
try {
const response = await serverAxios.post("/user", {
username: signupInfo.username,
password: signupInfo.password,
hobby: signupInfo.hobby,
});
return response.data.result;
} catch (error) {
if (isAxiosError(error)) {
const statusCode = error.response?.status;
let errorMessage = "에러가 발생했습니다.";

if (!statusCode) {
errorMessage = "네트워크 에러입니다.";
} else if (statusCode >= 500) {
errorMessage = "서버 내부 에러입니다.";
} else if (
statusCode === 400 ||
statusCode === 404 ||
statusCode === 409
) {
errorMessage = "중복된 닉네임 입니다.";
}

throw new Error(errorMessage);
} else {
throw new Error("담당자에게 문의하세요.");
}
}
};
8 changes: 8 additions & 0 deletions week4/assignment/src/apis/serverAxios.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
import axios from "axios";

/** 서버 요청 axios 인스턴스 */
const serverAxios = axios.create({
baseURL:import.meta.env.VITE_SERVER_URL
})

export default serverAxios
40 changes: 40 additions & 0 deletions week4/assignment/src/apis/updateUser.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,40 @@
import { isAxiosError } from "axios";
import serverAxios from "./serverAxios";
import { MyUserInfoType } from "../types/myType";

const updateUser = async (userInfo: MyUserInfoType) => {
try {
const token = localStorage.getItem("authToken");
const response = await serverAxios.put("/user", userInfo, {
headers: {
token: `${token}`,
},
});

return response.data;
} catch (error) {
if (isAxiosError(error)) {
const statusCode = error.response?.status;
let errorMessage = "에러가 발생했습니다.";
if (!statusCode) {
errorMessage = "네트워크 에러입니다.";
} else if (statusCode >= 500) {
errorMessage = "서버 내부 에러입니다.";
} else if (statusCode === 400) {
errorMessage = "8글자 이하로 입력해주세요.";
} else if (
statusCode === 401 ||
statusCode === 403 ||
statusCode === 404
) {
errorMessage = "잘못된 요청입니다.";
}

throw new Error(errorMessage);
} else {
throw new Error("담당자에게 문의하세요.");
}
}
};

export default updateUser;
Loading