Skip to content

Commit

Permalink
Merge pull request #55 from kkkkkSE/feat/open-profile
Browse files Browse the repository at this point in the history
[feat] 오픈 프로필 문의하기 클릭 시 채팅방으로 이동 구현
  • Loading branch information
kkkkkSE authored Aug 22, 2023
2 parents 2fd6fb5 + dcb7930 commit e72daa8
Show file tree
Hide file tree
Showing 3 changed files with 34 additions and 6 deletions.
1 change: 1 addition & 0 deletions src/constants/apiPaths.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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',
};

Expand Down
26 changes: 20 additions & 6 deletions src/pages/OpenProfilePage.tsx
Original file line number Diff line number Diff line change
@@ -1,24 +1,30 @@
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 (
<div>
<p>Not Found</p>
</div>
);
}

const { isLoading, openProfile, error } = useOpenProfileQuery(id);
const { isLoading, openProfile, error } = useOpenProfileQuery(companyId);

// TODO : Error Page로 이동하기
if (error) {
Expand All @@ -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 (
Expand Down
13 changes: 13 additions & 0 deletions src/services/ApiService.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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;
}) {
Expand Down

0 comments on commit e72daa8

Please sign in to comment.