Skip to content

Commit

Permalink
Merge pull request #64 from 2024-Team-Techeer-Salon/feat/#63
Browse files Browse the repository at this point in the history
[feat] 채팅방 삭제 기능 구현
  • Loading branch information
jinoo0306 authored Jun 16, 2024
2 parents fd4e4f7 + da01438 commit 6f451bb
Show file tree
Hide file tree
Showing 2 changed files with 31 additions and 0 deletions.
21 changes: 21 additions & 0 deletions src/api/chat.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
import { api } from './axios.config.ts';

export const deleteChat = async (chatId: number) => {
try {
const response = await api.delete(`chattings/rooms/${chatId}`);
return response.data;
} catch (error) {
console.error('chat delete api request error : ', error);
throw error;
}
};

export const getChats = async (meetingId: number) => {
try {
const response = await api.get(`/chats/${meetingId}`);
return response.data.data;
} catch (error) {
console.error('chat get api request error : ', error);
throw error;
}
};
10 changes: 10 additions & 0 deletions src/app/meeting/[meetingParam]/MeetingHeader.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@ import {
patchEndMeeting,
deleteMeeting,
} from '@/api/meetings.ts';
import { deleteChat } from '@/api/chat.ts';
import Swal from 'sweetalert2';
import { useEffect, useRef } from 'react';

Expand Down Expand Up @@ -50,6 +51,13 @@ function MeetingHeader({
document.removeEventListener('mousedown', handleClickOutside);
};
}, []);

const closeChatRoom = async () => {
await deleteChat(meetingId).then((data) => {
console.log('채팅방 삭제 성공 : ', data);
});
};

return (
<div className="flex h-full w-full flex-col items-center">
{/* 모임 정보 상단 */}
Expand Down Expand Up @@ -143,6 +151,7 @@ function MeetingHeader({
}).then((result) => {
if (result.isConfirmed) {
patchEndMeeting(meetingId);
closeChatRoom();
window.location.reload();
Swal.fire({
title: '모임 종료!',
Expand Down Expand Up @@ -171,6 +180,7 @@ function MeetingHeader({
}).then((result) => {
if (result.isConfirmed) {
deleteMeeting(meetingId);
closeChatRoom();
router.push('/home');
Swal.fire({
title: '삭제 완료!',
Expand Down

0 comments on commit 6f451bb

Please sign in to comment.