Skip to content

Commit 60d0386

Browse files
authored
Merge pull request #42 from boostcampwm-2022/feat/#37-K
Feat/#37-K: ๋กœ๊ทธ์ธ API ์—ฐ๋™
2 parents 17bf19d + e2d8513 commit 60d0386

File tree

36 files changed

+627
-170
lines changed

36 files changed

+627
-170
lines changed

โ€Žclient/package.jsonโ€Ž

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,7 @@
1414
"classnames": "^2.3.2",
1515
"react": "^18.2.0",
1616
"react-dom": "^18.2.0",
17+
"react-loader-spinner": "^5.3.4",
1718
"react-router-dom": "^6.4.3"
1819
},
1920
"devDependencies": {

โ€Žclient/src/App.tsxโ€Ž

Lines changed: 25 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,16 +1,35 @@
1-
import { BrowserRouter, Routes, Route } from 'react-router-dom';
2-
3-
import { LoginPage, WorkspacePage } from './pages';
4-
import 'style/reset.scss';
1+
import { useState, useEffect } from 'react';
2+
import { Routes, Route, useNavigate } from 'react-router-dom';
3+
import { getAuth } from 'src/apis/auth';
4+
import UserContext, { User } from 'src/contexts/user';
5+
import { LoginPage, OAuthPage, WorkspacePage } from 'src/pages';
6+
import 'styles/reset.scss';
57

68
function App() {
9+
const [user, setUser] = useState<User>({ id: -1, name: '', avatarUrl: '' });
10+
const navigate = useNavigate();
11+
12+
const autoLogin = async () => {
13+
const currentUser = await getAuth();
14+
15+
if (!currentUser) return;
16+
17+
setUser(currentUser);
18+
navigate('/workspace');
19+
};
20+
21+
useEffect(() => {
22+
autoLogin();
23+
}, []);
24+
725
return (
8-
<BrowserRouter>
26+
<UserContext.Provider value={{ user, setUser }}>
927
<Routes>
1028
<Route path="/" element={<LoginPage />} />
29+
<Route path="/oauth" element={<OAuthPage />} />
1130
<Route path="/workspace" element={<WorkspacePage />} />
1231
</Routes>
13-
</BrowserRouter>
32+
</UserContext.Provider>
1433
);
1534
}
1635

โ€Žclient/src/apis/auth.tsโ€Ž

Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,26 @@
1+
import { http } from './http';
2+
import { OK, CREATED } from './http-status';
3+
4+
export const getAuth = async () => {
5+
const res = await http.get(`/auth`);
6+
7+
if (res.status !== OK) throw new Error();
8+
9+
return res.data;
10+
};
11+
12+
export const postAuthLogin = async (code: string) => {
13+
const res = await http.post(`/auth/login`, { code });
14+
15+
if (res.status !== CREATED) throw new Error();
16+
17+
return res.data;
18+
};
19+
20+
export const deleteAuthlogout = async () => {
21+
const res = await http.delete(`/auth/logout`);
22+
23+
if (res.status !== OK) throw new Error();
24+
25+
return;
26+
};
Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
export const OK = 200;
2+
export const CREATED = 201;
3+
4+
export const BAD_REQUEST = 400;
5+
export const UNAUTHORIZED = 401;
6+
7+
export const INTERNAL_SERVER_ERROR = 500;

โ€Žclient/src/apis/http.tsโ€Ž

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,8 @@
11
import axios from 'axios';
2+
import env from 'config';
23

3-
const SERVER_URL = 'http://localhost:8080';
4+
const SERVER_PATH = env.SERVER_PATH;
45

56
export const http = axios.create({
6-
baseURL: SERVER_URL,
7+
baseURL: SERVER_PATH,
78
});

โ€Žclient/src/apis/index.tsโ€Ž

Lines changed: 0 additions & 1 deletion
This file was deleted.

โ€Žclient/src/apis/user.tsโ€Ž

Lines changed: 5 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,10 @@
11
import { http } from './http';
2+
import { OK } from './http-status';
23

34
export const getWorkspaces = async (userId: number) => {
4-
try {
5-
const { data } = await http.get(`/user/${userId}/workspace`);
5+
const res = await http.get(`/user/${userId}/workspace`);
66

7-
return data;
8-
} catch (e) {
9-
return;
10-
}
7+
if (res.status !== OK) throw new Error();
8+
9+
return res.data;
1110
};

โ€Žclient/src/components/SelectModal/style.module.scssโ€Ž

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
@import 'style/color.scss';
1+
@import 'styles/color.module.scss';
22

33
.modal {
44
z-index: 100;

โ€Žclient/src/components/WorkspaceList/style.module.scssโ€Ž

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
@import "../../styles/color.scss";
1+
@import 'styles/color.module.scss';
22

33
.workspace__container {
44
background-color: $primary-100;

โ€Žclient/src/components/WorkspaceModal/index.tsxโ€Ž

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -28,7 +28,7 @@ function WorkspaceModal({
2828
<>
2929
<span className={style.text}>{text}</span>
3030
<input className={style.input} type="text" onChange={onInput} />
31-
<Button text={btnText} isDisable={!inputValue.length} />
31+
<Button text={btnText} isDisabled={!inputValue.length} />
3232
</>
3333
</Modal>
3434
);

0 commit comments

Comments
ย (0)