Skip to content

Commit fcf32fb

Browse files
authored
Merge pull request #102 from boostcampwm-2022/feat/#82-S
Feat/#82-S : νŠΉμ • μ›Œν¬μŠ€νŽ˜μ΄μŠ€ 멀버, 회의둝 API 연동 & 둜그인 둜직 λ¦¬νŒ©ν† λ§
2 parents f6d9877 + f294f67 commit fcf32fb

File tree

17 files changed

+163
-71
lines changed

17 files changed

+163
-71
lines changed

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

Lines changed: 14 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -1,42 +1,45 @@
1-
import { useState, useEffect } from 'react';
2-
import { Routes, Route, useNavigate, useLocation } from 'react-router-dom';
1+
import { useEffect, useState } from 'react';
2+
import { Route, Routes, useLocation, useNavigate } from 'react-router-dom';
33
import { getAuth } from 'src/apis/auth';
44
import UserContext from 'src/contexts/user';
55
import { LoadingPage, LoginPage, OAuthPage, WorkspacePage } from 'src/pages';
6-
import { User } from 'src/types/user';
6+
import { UserInfo } from 'src/types/user';
7+
78
import 'styles/reset.scss';
89

910
function App() {
1011
const [isLoaded, setIsLoaded] = useState<boolean>(false);
11-
const [user, setUser] = useState<User | null>(null);
12+
const [userInfo, setUserInfo] = useState<UserInfo | null>(null);
1213

1314
const navigate = useNavigate();
1415
const location = useLocation();
1516

1617
const autoLogin = async () => {
17-
const currentUser = await getAuth();
18+
const { user, workspaces } = await getAuth();
1819

1920
setIsLoaded(true);
2021

21-
if (!currentUser) {
22-
if (location.pathname === '/workspace') navigate('/');
22+
if (!user) {
23+
if (location.pathname.match('/workspace')) navigate('/');
2324
return;
2425
}
2526

26-
setUser(currentUser);
27-
navigate('/workspace');
27+
setUserInfo({ user, workspaces });
28+
29+
const { id } = workspaces[0];
30+
navigate(`/workspace/${id}`);
2831
};
2932

3033
useEffect(() => {
3134
autoLogin();
3235
}, []);
3336

3437
return isLoaded ? (
35-
<UserContext.Provider value={{ user, setUser }}>
38+
<UserContext.Provider value={{ userInfo, setUserInfo }}>
3639
<Routes>
3740
<Route path="/" element={<LoginPage />} />
3841
<Route path="/oauth" element={<OAuthPage />} />
39-
<Route path="/workspace" element={<WorkspacePage />} />
42+
<Route path="/workspace/:id" element={<WorkspacePage />} />
4043
</Routes>
4144
</UserContext.Provider>
4245
) : (

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

Lines changed: 9 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -1,21 +1,20 @@
11
import { PostLoginParams } from 'params/auth';
2+
import { GetUserInfo } from 'src/types/workspace';
23

34
import { http } from './http';
4-
import { OK, CREATED } from './http-status';
5+
import { CREATED, OK } from './http-status';
56

6-
export const getAuth = async () => {
7-
try {
8-
const res = await http.get(`/auth`);
7+
export const getAuth = async (): Promise<GetUserInfo> => {
8+
const res = await http.get(`/auth`);
99

10-
if (res.status !== OK) return null;
10+
if (res.status !== OK) throw new Error();
1111

12-
return res.data;
13-
} catch (e) {
14-
return null;
15-
}
12+
return res.data;
1613
};
1714

18-
export const postAuthLogin = async ({ code }: PostLoginParams) => {
15+
export const postAuthLogin = async ({
16+
code,
17+
}: PostLoginParams): Promise<GetUserInfo> => {
1918
const res = await http.post(`/auth/login`, { code });
2019

2120
if (res.status !== CREATED) throw new Error();

β€Žclient/src/apis/workspace.tsβ€Ž

Lines changed: 13 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,8 @@
1-
import { PostJoinParams, PostParams } from 'params/workspace';
2-
import { Workspace } from 'src/types/workspace';
1+
import { GetInfoParams, PostJoinParams, PostParams } from 'params/workspace';
2+
import { Workspace, WorkspaceInfo } from 'src/types/workspace';
33

44
import { http } from './http';
5-
import { CREATED } from './http-status';
5+
import { CREATED, OK } from './http-status';
66

77
export const postWorkspace = async ({
88
name,
@@ -23,3 +23,13 @@ export const postWorkspaceJoin = async ({
2323

2424
return res.data;
2525
};
26+
27+
export const getWorkspaceInfo = async ({
28+
id,
29+
}: GetInfoParams): Promise<WorkspaceInfo> => {
30+
const res = await http.get(`/workspace/${id}`);
31+
32+
if (res.status !== OK) throw new Error();
33+
34+
return res.data;
35+
};

β€Žclient/src/components/Workspace/index.tsxβ€Ž

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,16 @@
11
import Confbar from 'components/Confbar';
22
import Mom from 'components/Mom';
33
import Sidebar from 'components/Sidebar';
4+
import { TMom } from 'src/types/mom';
5+
import { TUser } from 'src/types/user';
46

5-
function Workspace() {
7+
interface WorkspaceProps {
8+
name: string;
9+
members: TUser[];
10+
moms: TMom[];
11+
}
12+
13+
function Workspace({ name, members, moms }: WorkspaceProps) {
614
return (
715
<>
816
<Sidebar />

β€Žclient/src/components/WorkspaceList/index.tsxβ€Ž

Lines changed: 2 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,6 @@ import Selector from 'common/Selector';
22
import WorkspaceModal from 'components/WorkspaceModal';
33
import WorkspaceThumbnaliList from 'components/WorkspaceThumbnailList';
44
import { memo, useEffect, useState } from 'react';
5-
import { getWorkspaces } from 'src/apis/user';
65
import { MENUS } from 'src/constants/workspace';
76
import SetWorkspacesContext from 'src/contexts/set-workspaces';
87
import { useUserContext } from 'src/hooks/useUserContext';
@@ -17,17 +16,11 @@ function WorkspaceList() {
1716

1817
const [workspaces, setWorkspaces] = useState<Workspace[]>([]);
1918

20-
const updateWorkspaces = async (userId: number) => {
21-
const { workspaces } = await getWorkspaces({ id: userId });
22-
setWorkspaces(workspaces);
23-
};
24-
2519
useEffect(() => {
26-
if (!userContext.user) {
20+
if (!userContext.userInfo) {
2721
return;
2822
}
29-
30-
updateWorkspaces(userContext.user.id);
23+
setWorkspaces(userContext.userInfo.workspaces);
3124
}, []);
3225

3326
const [selectedMenu, setSelectedMenu] = useState<number>(0);

β€Žclient/src/contexts/user.tsβ€Ž

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,9 @@
11
import { createContext, Dispatch, SetStateAction } from 'react';
2-
import { User } from 'src/types/user';
2+
import { UserInfo } from 'src/types/user';
33

44
interface IUserContext {
5-
user: User | null;
6-
setUser: Dispatch<SetStateAction<User | null>>;
5+
userInfo: UserInfo | null;
6+
setUserInfo: Dispatch<SetStateAction<UserInfo | null>>;
77
}
88

99
const UserContext = createContext<IUserContext | null>(null);

β€Žclient/src/pages/OAuth/index.tsxβ€Ž

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -20,9 +20,10 @@ function OAuthPage() {
2020
try {
2121
const authorizedUser = await postAuthLogin({ code });
2222

23-
userContext.setUser(authorizedUser);
23+
userContext.setUserInfo(authorizedUser);
2424

25-
navigate('/workspace');
25+
const id = authorizedUser.workspaces[0].id;
26+
navigate(`/workspace/${id}`);
2627
} catch (e) {
2728
navigate('/');
2829
}

β€Žclient/src/pages/Workspace/index.tsxβ€Ž

Lines changed: 25 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,37 @@
11
import Workspace from 'components/Workspace';
22
import WorkspaceList from 'components/WorkspaceList';
3+
import { useEffect, useState } from 'react';
4+
import { useParams } from 'react-router-dom';
5+
import { getWorkspaceInfo } from 'src/apis/workspace';
6+
import { WorkspaceInfo } from 'src/types/workspace';
37

48
import style from './style.module.scss';
59

610
function WorkspacePage() {
11+
const { id } = useParams();
12+
const [workspace, setWorkspace] = useState<WorkspaceInfo | null>(null);
13+
14+
const loadWorkspaceInfo = async () => {
15+
if (id) {
16+
const workspaceInfo = await getWorkspaceInfo({ id });
17+
setWorkspace(workspaceInfo);
18+
}
19+
};
20+
21+
useEffect(() => {
22+
loadWorkspaceInfo();
23+
}, []);
24+
725
return (
826
<div className={style.container}>
927
<WorkspaceList />
10-
<Workspace />
28+
{workspace && ( // TODO: μž„μ‹œλ‘œ λ§Œλ“€μ—ˆμ–΄μš”
29+
<Workspace
30+
name={workspace.name}
31+
members={workspace.members}
32+
moms={workspace.moms}
33+
/>
34+
)}
1135
</div>
1236
);
1337
}

β€Žclient/src/types/mom.d.tsβ€Ž

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
export type TMom = {
2+
id: number;
3+
name: string;
4+
};

β€Žclient/src/types/user.d.tsβ€Ž

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,12 @@
1-
export interface User {
1+
import { Workspace } from './workspace';
2+
3+
export type TUser = {
24
id: number;
35
name: string;
46
avatarUrl: string;
7+
};
8+
9+
export interface UserInfo {
10+
user: User;
11+
workspaces: Workspace[];
512
}

0 commit comments

Comments
Β (0)