From 7df6fb7676ae5b1777983b0e5c83209db9b682a0 Mon Sep 17 00:00:00 2001 From: Suyoung Jung Date: Wed, 25 Oct 2023 22:04:49 +0900 Subject: [PATCH 1/5] =?UTF-8?q?refactor:=20axios=20api=20v2=20=EC=9E=91?= =?UTF-8?q?=EC=84=B1?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- frontend/src/api-v2/apiv2.ts | 53 ++++++++++++++++++++++++++++++++++++ 1 file changed, 53 insertions(+) create mode 100644 frontend/src/api-v2/apiv2.ts diff --git a/frontend/src/api-v2/apiv2.ts b/frontend/src/api-v2/apiv2.ts new file mode 100644 index 000000000..56832ab76 --- /dev/null +++ b/frontend/src/api-v2/apiv2.ts @@ -0,0 +1,53 @@ +import axios, { AxiosError } from 'axios'; +import { history } from 'App'; +import PATH from 'constants/path'; +import { LOCAL_STORAGE_KEY } from 'constants/storage'; +import { ErrorResponse } from 'types/response'; +import { getLocalStorageItem, removeLocalStorageItem } from 'utils/localStorage'; + +const apiV2 = axios.create({ + baseURL: 'http://localhost:7742', + headers: { + 'Content-type': 'application/json', + }, +}); + +apiV2.interceptors.request.use( + (config) => { + const token = getLocalStorageItem({ + key: LOCAL_STORAGE_KEY.ACCESS_TOKEN, + defaultValue: '', + }); + + if (typeof token !== 'string' || !token) return config; + + config.headers = { + 'Content-type': 'application/json', + Authorization: `Bearer ${token}`, + }; + + return config; + }, + + (error) => { + return Promise.reject(error); + } +); + +apiV2.interceptors.response.use( + (response) => { + return response; + }, + + (error: AxiosError) => { + if (error?.response?.status === 401) { + removeLocalStorageItem({ key: LOCAL_STORAGE_KEY.ACCESS_TOKEN }); + + history.push(PATH.LOGIN); + } + + return Promise.reject(error); + } +); + +export default apiV2; From db37a805dabfef80c744762e6de0a28409e1bbf8 Mon Sep 17 00:00:00 2001 From: Suyoung Jung Date: Wed, 25 Oct 2023 22:06:33 +0900 Subject: [PATCH 2/5] =?UTF-8?q?refactor:=20api=20request=20=EB=B0=8F=20que?= =?UTF-8?q?ry=20v2=20=EC=9E=91=EC=84=B1?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- frontend/src/api-v2/managerMap.ts | 18 ++++++++++++++++++ .../src/hooks/query-v2/useManagerMapV2.ts | 19 +++++++++++++++++++ frontend/src/types/response-v2.ts | 13 +++++++++++++ 3 files changed, 50 insertions(+) create mode 100644 frontend/src/api-v2/managerMap.ts create mode 100644 frontend/src/hooks/query-v2/useManagerMapV2.ts create mode 100644 frontend/src/types/response-v2.ts diff --git a/frontend/src/api-v2/managerMap.ts b/frontend/src/api-v2/managerMap.ts new file mode 100644 index 000000000..734c10e67 --- /dev/null +++ b/frontend/src/api-v2/managerMap.ts @@ -0,0 +1,18 @@ +import { AxiosResponse } from 'axios'; +import { QueryFunction, QueryKey } from 'react-query'; +import { QueryManagerMapSuccessV2 } from 'types/response-v2'; +import apiV2 from './apiv2'; + +export interface QueryManagerMapParamsV2 { + mapId: number; +} + +export const queryManagerMapV2: QueryFunction< + AxiosResponse, + [QueryKey, QueryManagerMapParamsV2] +> = ({ queryKey }) => { + const [, data] = queryKey; + const { mapId } = data; + + return apiV2.get(`/api/maps/${mapId}`); +}; diff --git a/frontend/src/hooks/query-v2/useManagerMapV2.ts b/frontend/src/hooks/query-v2/useManagerMapV2.ts new file mode 100644 index 000000000..783b717fe --- /dev/null +++ b/frontend/src/hooks/query-v2/useManagerMapV2.ts @@ -0,0 +1,19 @@ +import { AxiosError, AxiosResponse } from 'axios'; +import { QueryKey, useQuery, UseQueryOptions, UseQueryResult } from 'react-query'; +import { QueryManagerMapParamsV2, queryManagerMapV2 } from 'api-v2/managerMap'; +import { QueryManagerMapParams } from 'api/managerMap'; +import { ErrorResponse } from 'types/response'; +import { QueryManagerMapSuccessV2 } from 'types/response-v2'; + +const useManagerMapV2 = >( + { mapId }: QueryManagerMapParams, + options?: UseQueryOptions< + AxiosResponse, + AxiosError, + TData, + [QueryKey, QueryManagerMapParamsV2] + > +): UseQueryResult> => + useQuery(['getManagerMapV2', { mapId }], queryManagerMapV2, options); + +export default useManagerMapV2; diff --git a/frontend/src/types/response-v2.ts b/frontend/src/types/response-v2.ts new file mode 100644 index 000000000..50ce16b6a --- /dev/null +++ b/frontend/src/types/response-v2.ts @@ -0,0 +1,13 @@ +import { MapItem } from './common'; + +export interface MapItemResponseV2 + extends Omit { + mapDrawing: string; +} + +export interface QueryManagerMapsSuccessV2 { + maps: MapItemResponseV2[]; + organization: string; +} + +export type QueryManagerMapSuccessV2 = MapItemResponseV2; From eb58d784f187a18b3091357dada5b2275e7b2552 Mon Sep 17 00:00:00 2001 From: Suyoung Jung Date: Wed, 25 Oct 2023 22:07:17 +0900 Subject: [PATCH 3/5] =?UTF-8?q?refactor:=20useManagerMap=20=EC=82=AC?= =?UTF-8?q?=EC=9A=A9=EC=B2=98=20v2=20=EB=A7=88=EC=9D=B4=EA=B7=B8=EB=A0=88?= =?UTF-8?q?=EC=9D=B4=EC=85=98?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../src/components/ManagerIconButtons/SlackNotiButton.tsx | 5 +++-- frontend/src/pages/ManagerMapDetail/ManagerMapDetail.tsx | 8 ++------ 2 files changed, 5 insertions(+), 8 deletions(-) diff --git a/frontend/src/components/ManagerIconButtons/SlackNotiButton.tsx b/frontend/src/components/ManagerIconButtons/SlackNotiButton.tsx index b32d6e4ca..d33f4f0a2 100644 --- a/frontend/src/components/ManagerIconButtons/SlackNotiButton.tsx +++ b/frontend/src/components/ManagerIconButtons/SlackNotiButton.tsx @@ -10,11 +10,12 @@ import Modal from 'components/Modal/Modal'; import MESSAGE from 'constants/message'; import useInput from 'hooks/useInput'; import useSlackWebhookUrl from 'pages/ManagerMapDetail/hooks/useSlackWebhookUrl'; -import { ErrorResponse, QueryManagerMapSuccess } from 'types/response'; +import { ErrorResponse } from 'types/response'; +import { QueryManagerMapSuccessV2 } from 'types/response-v2'; import * as Styled from './ManagerIconButton.styled'; interface Props extends ComponentProps { - map: QueryManagerMapSuccess; + map: QueryManagerMapSuccessV2; } const SlackNotiButton = ({ map, ...props }: Props): JSX.Element => { diff --git a/frontend/src/pages/ManagerMapDetail/ManagerMapDetail.tsx b/frontend/src/pages/ManagerMapDetail/ManagerMapDetail.tsx index e5a6622c1..885d06fc6 100644 --- a/frontend/src/pages/ManagerMapDetail/ManagerMapDetail.tsx +++ b/frontend/src/pages/ManagerMapDetail/ManagerMapDetail.tsx @@ -11,13 +11,11 @@ import DateInput from 'components/DateInput/DateInput'; import Header from 'components/Header/Header'; import IconButton from 'components/IconButton/IconButton'; import Layout from 'components/Layout/Layout'; -import MapNoticeButton from 'components/ManagerIconButtons/MapNoticeButton'; -import ShareLinkButton from 'components/ManagerIconButtons/ShareLinkButton'; import SlackNotiButton from 'components/ManagerIconButtons/SlackNotiButton'; import PageHeader from 'components/PageHeader/PageHeader'; import MESSAGE from 'constants/message'; import PATH, { HREF } from 'constants/path'; -import useManagerMap from 'hooks/query/useManagerMap'; +import useManagerMapV2 from 'hooks/query-v2/useManagerMapV2'; import useManagerMapReservations from 'hooks/query/useManagerMapReservations'; import useManagerSpaces from 'hooks/query/useManagerSpaces'; import { Reservation } from 'types/common'; @@ -41,7 +39,7 @@ const ManagerMapDetail = (): JSX.Element => { const [date, setDate] = useState(targetDate ?? dayjs().tz()); - const getMap = useManagerMap( + const getMap = useManagerMapV2( { mapId: mapId }, { enabled: !isNullish(mapId), @@ -158,7 +156,6 @@ const ManagerMapDetail = (): JSX.Element => { rightButtons={ getMap.data?.data != null && ( <> - @@ -168,7 +165,6 @@ const ManagerMapDetail = (): JSX.Element => { - ) } From 5ecec4948a47e0b80e7c7cf232d29d789f29ee6f Mon Sep 17 00:00:00 2001 From: Suyoung Jung Date: Wed, 25 Oct 2023 22:16:46 +0900 Subject: [PATCH 4/5] =?UTF-8?q?refactor:=20=EB=B6=88=ED=95=84=EC=9A=94?= =?UTF-8?q?=ED=95=9C=20Vertical=20Bar=20=EC=A0=9C=EA=B1=B0?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- frontend/src/pages/ManagerMapDetail/ManagerMapDetail.tsx | 1 - 1 file changed, 1 deletion(-) diff --git a/frontend/src/pages/ManagerMapDetail/ManagerMapDetail.tsx b/frontend/src/pages/ManagerMapDetail/ManagerMapDetail.tsx index 885d06fc6..11f0acbbb 100644 --- a/frontend/src/pages/ManagerMapDetail/ManagerMapDetail.tsx +++ b/frontend/src/pages/ManagerMapDetail/ManagerMapDetail.tsx @@ -164,7 +164,6 @@ const ManagerMapDetail = (): JSX.Element => { - ) } From e42e16e72aed11725b699ed31e012ba9a54ff16e Mon Sep 17 00:00:00 2001 From: Suyoung Jung Date: Thu, 2 Nov 2023 15:04:17 +0900 Subject: [PATCH 5/5] =?UTF-8?q?refactor:=20MapItemResponse=20type=EC=97=90?= =?UTF-8?q?=20slackUrl=20=ED=94=84=EB=A1=9C=ED=8D=BC=ED=8B=B0=20=EC=B6=94?= =?UTF-8?q?=EA=B0=80?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- frontend/src/types/response-v2.ts | 1 + 1 file changed, 1 insertion(+) diff --git a/frontend/src/types/response-v2.ts b/frontend/src/types/response-v2.ts index 50ce16b6a..f8c71d260 100644 --- a/frontend/src/types/response-v2.ts +++ b/frontend/src/types/response-v2.ts @@ -3,6 +3,7 @@ import { MapItem } from './common'; export interface MapItemResponseV2 extends Omit { mapDrawing: string; + slackUrl: string; } export interface QueryManagerMapsSuccessV2 {