From dcb7930159741a2ba11f6dc810bfb1f9856e16bc Mon Sep 17 00:00:00 2001 From: kkkkkse Date: Tue, 22 Aug 2023 16:16:29 +0900 Subject: [PATCH] =?UTF-8?q?[feat]=20=EC=98=A4=ED=94=88=20=ED=94=84?= =?UTF-8?q?=EB=A1=9C=ED=95=84=20=EB=AC=B8=EC=9D=98=ED=95=98=EA=B8=B0=20?= =?UTF-8?q?=ED=81=B4=EB=A6=AD=20=EC=8B=9C=20=EC=B1=84=ED=8C=85=EB=B0=A9?= =?UTF-8?q?=EC=9C=BC=EB=A1=9C=20=EC=9D=B4=EB=8F=99=20=EA=B5=AC=ED=98=84?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/constants/apiPaths.ts | 1 + src/pages/OpenProfilePage.tsx | 26 ++++++++++++++++++++------ src/services/ApiService.ts | 13 +++++++++++++ 3 files changed, 34 insertions(+), 6 deletions(-) diff --git a/src/constants/apiPaths.ts b/src/constants/apiPaths.ts index 595a937..e18e53d 100644 --- a/src/constants/apiPaths.ts +++ b/src/constants/apiPaths.ts @@ -9,6 +9,7 @@ export const STATIC_API_PATHS = { AUTO_REPLIES_BY_COMPANY: '/company/auto-replies', REISSUE_TOKEN: '/token', LOGOUT: '/logout', + CREATE_CHATROOM: '/customer/chatrooms', UPLOAD_PROFILE_IMAGE: '/files?folder=profile', }; diff --git a/src/pages/OpenProfilePage.tsx b/src/pages/OpenProfilePage.tsx index a505bcb..1561744 100644 --- a/src/pages/OpenProfilePage.tsx +++ b/src/pages/OpenProfilePage.tsx @@ -1,16 +1,22 @@ -import { useParams } from 'react-router-dom'; +import { useNavigate, useParams } from 'react-router-dom'; import useOpenProfileQuery from '../hooks/useOpenProfileQuery'; +import { apiService } from '../services/ApiService'; + +import { DYNAMIC_ROUTES } from '../constants/routes'; + import ContentLayout from '../components/layout/ContentLayout'; import OpenProfile from '../components/profile/OpenProfile'; export default function OpenProfilePage() { + const navigate = useNavigate(); + const params = useParams(); - const id = Number(params.id); + const companyId = Number(params.id); // TODO : id 없을 때 not found 페이지 이동 - if (!id) { + if (!companyId) { return (

Not Found

@@ -18,7 +24,7 @@ export default function OpenProfilePage() { ); } - const { isLoading, openProfile, error } = useOpenProfileQuery(id); + const { isLoading, openProfile, error } = useOpenProfileQuery(companyId); // TODO : Error Page로 이동하기 if (error) { @@ -29,8 +35,16 @@ export default function OpenProfilePage() { ); } - const handleClickInquiry = () => { - // ... + const handleClickInquiry = async () => { + try { + const chatRoomId = await apiService.createChatRoom({ + companyId, + }); + + navigate(DYNAMIC_ROUTES.CHATROOM(chatRoomId)); + } catch (e) { + // TODO : Error Page로 이동하기 + } }; return ( diff --git a/src/services/ApiService.ts b/src/services/ApiService.ts index 9d16294..359dfb5 100644 --- a/src/services/ApiService.ts +++ b/src/services/ApiService.ts @@ -124,6 +124,19 @@ export default class ApiService { return data; } + async createChatRoom({ companyId } : { + companyId : number; + }) { + const { data } = await this.instance.post( + STATIC_API_PATHS.CREATE_CHATROOM, + { companyId }, + ); + + const { chatRoomId } = data; + + return chatRoomId; + } + async fetchLoginUser({ type } : { type: string; }) {