Skip to content

Commit 9d9d1f6

Browse files
committed
refactor: 로컬 테스트 환경 구축
1 parent 29ae6b9 commit 9d9d1f6

File tree

8 files changed

+51
-38
lines changed

8 files changed

+51
-38
lines changed

src/api/apiInstance.ts

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -92,7 +92,6 @@ apiInstance.interceptors.response.use(
9292
if (error.response.status === 401) {
9393
if (code === 100) {
9494
navigate(PATH.ENROLL);
95-
9695
return Promise.reject(error);
9796
}
9897

@@ -129,7 +128,7 @@ apiInstance.interceptors.response.use(
129128

130129
// 리프레시 토큰이 만료됨
131130
// sessionStorage.removeItem('Authorization');
132-
// navigate(PATH.LOGIN);
131+
navigate(PATH.LOGIN);
133132
return Promise.reject(error);
134133
}
135134
}

src/api/config.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
const getApiBaseUrl = () => {
22
const host = window.location.hostname;
33

4+
if (host === 'localhost') return import.meta.env.VITE_LOCAL_URL;
45
if (host === 'test.codemonster.site') return import.meta.env.VITE_TEST_URL;
56
if (host === 'codemonster.site') return import.meta.env.VITE_BASE_URL;
67

src/api/dashboard.ts

Lines changed: 32 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
import { isDevMode } from '@/utils/cookie.ts';
22

3-
import { subjectMock, teamArticlesMock, teamInfoMock } from '@/api/mocks.ts';
3+
import { subjectMock } from '@/api/mocks.ts';
44

55
import apiInstance from './apiInstance';
66
import { ITeamInfo } from './team';
@@ -32,12 +32,31 @@ export interface IArticle {
3232

3333
export interface IArticlesByDateResponse {
3434
content: IArticle[];
35-
page: {
36-
size: number;
37-
number: number;
38-
totalElements: number;
39-
totalPages: number;
35+
empty: boolean;
36+
first: boolean;
37+
last: boolean;
38+
number: number;
39+
numberOfElements: number;
40+
pageable: {
41+
offset: number;
42+
pageNumber: number;
43+
pageSize: number;
44+
paged: boolean;
45+
unpaged: boolean;
46+
sort: {
47+
empty: boolean;
48+
sorted: boolean;
49+
unsorted: boolean;
50+
};
4051
};
52+
size: number;
53+
sort: {
54+
empty: boolean;
55+
sorted: boolean;
56+
unsorted: boolean;
57+
};
58+
totalElements: number;
59+
totalPages: number;
4160
}
4261

4362
export interface ITopicResponse {
@@ -58,11 +77,11 @@ export const getTeamInfoAndTags = async (
5877
year: number,
5978
month: number
6079
): Promise<ITeamInfoAndTagsResponse> => {
61-
if (isDevMode()) {
62-
await new Promise((r) => setTimeout(r, 1000));
80+
// if (isDevMode()) {
81+
// await new Promise((r) => setTimeout(r, 1000));
6382

64-
return teamInfoMock.data;
65-
}
83+
// return teamInfoMock.data;
84+
// }
6685

6786
const res = await apiInstance.get<ServerResponse<ITeamInfoAndTagsResponse>>(
6887
`/v1/teams/${teamId}/team-page`,
@@ -77,9 +96,9 @@ export const getArticlesByDate = async (
7796
date: string,
7897
page: number
7998
): Promise<IArticlesByDateResponse> => {
80-
if (isDevMode()) {
81-
return teamArticlesMock.data;
82-
}
99+
// if (isDevMode()) {
100+
// return teamArticlesMock.data;
101+
// }
83102

84103
const res = await apiInstance.get<ServerResponse<IArticlesByDateResponse>>(
85104
`/v1/articles/${teamId}/by-date`,

src/api/mypage.ts

Lines changed: 6 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,4 @@
1-
import { isDevMode } from '@/utils/cookie.ts';
2-
31
import apiInstance from '@/api/apiInstance';
4-
import { myArticlesMock, myPageTeamMock } from '@/api/mocks.ts';
52
import { ServerResponse } from '@/api/types';
63

74
export type TeamAbstraction = {
@@ -12,9 +9,9 @@ export type TeamAbstraction = {
129
};
1310

1411
export const queryMyTeamInfo = async () => {
15-
if (isDevMode()) {
16-
return myPageTeamMock.data;
17-
}
12+
// if (isDevMode()) {
13+
// return myPageTeamMock.data;
14+
// }
1815

1916
const res =
2017
await apiInstance.get<ServerResponse<TeamAbstraction[]>>(
@@ -49,9 +46,9 @@ export type MyArticleResponse = {
4946
};
5047

5148
export const queryMyArticles = async (teamId: number, page: number) => {
52-
if (isDevMode()) {
53-
return myArticlesMock.data;
54-
}
49+
// if (isDevMode()) {
50+
// return myArticlesMock.data;
51+
// }
5552

5653
const res = await apiInstance.get<ServerResponse<MyArticleResponse>>(
5754
`v1/articles/${teamId}/my-page`,

src/api/user.ts

Lines changed: 3 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,5 @@
1-
import { isDevMode } from '@/utils/cookie.ts';
2-
31
import apiInstance from '@/api/apiInstance';
42
import { API_BASE_URL } from '@/api/config.ts';
5-
import { membersInfoMock } from '@/api/mocks.ts';
63
import { ServerResponse } from '@/api/types';
74

85
export const kakaoOauth2LoginUrl = `${API_BASE_URL}/oauth2/authorization/kakao`;
@@ -100,9 +97,9 @@ type MemberInfoResp = {
10097
};
10198

10299
export const getMemberInfo = async () => {
103-
if (isDevMode()) {
104-
return membersInfoMock.data;
105-
}
100+
// if (isDevMode()) {
101+
// return membersInfoMock.data;
102+
// }
106103

107104
const res =
108105
await apiInstance.get<ServerResponse<MemberInfoResp>>('v1/members/info');

src/components/features/TeamDashboard/SidebarAndAnnouncement.tsx

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,3 @@
1-
import { isDevMode, isLoggedIn } from '@/utils/cookie.ts';
2-
31
import { useWindowWidth } from '@/hooks/useWindowWidth';
42

53
import { Box } from '@/components/commons/Box';
@@ -25,10 +23,11 @@ import SettingsRedIcon from '@/assets/TeamDashboard/settings_red.png';
2523
import { breakpoints } from '@/constants/breakpoints';
2624
import { colors } from '@/constants/colors';
2725
import { PATH } from '@/routes/path';
26+
import { isLoggedInAtom } from '@/store/auth';
2827
import { selectedPostIdAtom } from '@/store/dashboard';
2928
import { confirmAtom } from '@/store/modal';
3029
import styled from '@emotion/styled';
31-
import { useSetAtom } from 'jotai';
30+
import { useAtom, useSetAtom } from 'jotai';
3231

3332
interface ISidebarAndAnnouncementProps {
3433
teamInfo: ITeamInfo;
@@ -53,6 +52,7 @@ export const SidebarAndAnnouncement: React.FC<ISidebarAndAnnouncementProps> = ({
5352
const toggleExpand = () => setIsExpanded((prev) => !prev);
5453
const [isDropdownOpen, setIsDropdownOpen] = useState(false);
5554
const setConfirm = useSetAtom(confirmAtom);
55+
const [isLoggedIn] = useAtom(isLoggedInAtom);
5656

5757
const onClick = () => {
5858
if (isMyTeam) {
@@ -69,7 +69,7 @@ export const SidebarAndAnnouncement: React.FC<ISidebarAndAnnouncementProps> = ({
6969
};
7070

7171
const joinTeam = () => {
72-
if (!isLoggedIn() && !isDevMode()) {
72+
if (!isLoggedIn) {
7373
sessionStorage.setItem('redirect', location.pathname);
7474
navigate(PATH.LOGIN, {
7575
state: {

src/pages/TeamAdmin/TeamAdmin.tsx

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -374,7 +374,7 @@ const TeamAdmin = () => {
374374
});
375375
// 가장 비용이 적은 캐싱
376376
if (isPaginationReady && articlesData) {
377-
totalPageCache = articlesData.page.totalPages;
377+
totalPageCache = articlesData.totalPages;
378378
}
379379

380380
const handleShowTopicDetail = () => {
@@ -528,7 +528,7 @@ const TeamAdmin = () => {
528528
onShowArticleDetail={handleShowArticleDetail}
529529
/>
530530
<Pagination
531-
totalPages={articlesData?.page?.totalPages ?? totalPageCache}
531+
totalPages={articlesData?.totalPages ?? totalPageCache}
532532
currentPageProp={page}
533533
onPageChange={handlePageChange}
534534
hideShadow={isMobile}

src/pages/TeamDashboard/TeamDashboard.tsx

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -65,7 +65,7 @@ const TeamDashboardPage = () => {
6565
});
6666
// 가장 비용이 적은 캐싱
6767
if (isPaginationReady && articlesData) {
68-
totalPageCache = articlesData.page.totalPages;
68+
totalPageCache = articlesData.totalPages;
6969
}
7070

7171
const onClickCalendarDate = (newDate: string) => {
@@ -138,7 +138,7 @@ const TeamDashboardPage = () => {
138138
onShowArticleDetail={handleShowArticleDetail}
139139
/>
140140
<Pagination
141-
totalPages={articlesData?.page?.totalPages ?? totalPageCache}
141+
totalPages={articlesData?.totalPages ?? totalPageCache}
142142
currentPageProp={page}
143143
onPageChange={handlePageChange}
144144
hideShadow={isMobile}

0 commit comments

Comments
 (0)