Skip to content

Commit 0273791

Browse files
committed
feat: 채팅 수락 시 로직 구현
1 parent 5825b95 commit 0273791

File tree

4 files changed

+40
-12
lines changed

4 files changed

+40
-12
lines changed

src/apis/chat.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -34,13 +34,13 @@ export const cancelChatRequest = async (emotionRecordId: number) => {
3434
//채팅방 생성
3535
export const createChatroom = async (emotionRecordId: number) => {
3636
const { data } = await axiosInstance.post(
37-
`/chat/chatroom/create?recordId=${emotionRecordId}`,
37+
`/chat/create?recordId=${emotionRecordId}`,
3838
{},
3939
);
4040
return data;
4141
};
4242
//채팅방 닫기
4343
export const closeChatroom = async (chatRoomId: number) => {
44-
const { data } = await axiosInstance.post(`/chat/chatroom/close?chatRoomId=${chatRoomId}`, {});
44+
const { data } = await axiosInstance.post(`/chat/close?chatRoomId=${chatRoomId}`, {});
4545
return data;
4646
};

src/components/ChatConnectLoadingSheet.tsx

Lines changed: 35 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -6,14 +6,13 @@ import { useSheetStore } from '@/store/sheetStore';
66
import { useEffect, useState } from 'react';
77
import dayjs from 'dayjs';
88
import duration from 'dayjs/plugin/duration';
9-
import { cancelChatRequest } from '@/apis/chat';
9+
import { cancelChatRequest, createChatroom } from '@/apis/chat';
1010
import { useNavigate } from 'react-router';
1111
dayjs.extend(duration);
1212

1313
export default function ChatConnectLoadingSheet() {
1414
const navigate = useNavigate();
15-
//zustand로 관리
16-
//거절, 취소하거나 홈으로 가기 누르면 false로
15+
1716
const { currentRecord, closeAllSheets, closeSheet } = useSheetStore();
1817

1918
const [timeLeft, setTimeLeft] = useState(60);
@@ -25,6 +24,7 @@ export default function ChatConnectLoadingSheet() {
2524
navigate('/home');
2625
};
2726

27+
//타이머 60초
2828
useEffect(() => {
2929
const endTime = new Date().getTime() + 60 * 1000; // 현재 시간 + 60초
3030

@@ -50,14 +50,14 @@ export default function ChatConnectLoadingSheet() {
5050

5151
const formattedTime = dayjs.duration(timeLeft, 'seconds').format('mm:ss');
5252

53-
//채팅 요청 취소
53+
//채팅 요청 취소(요청 보낸 사람)
5454
const cancel = async () => {
55-
console.log(currentRecord);
5655
if (!currentRecord) {
5756
console.log('record가 존재하지 않습니다');
5857
return;
5958
}
6059
try {
60+
console.log(currentRecord);
6161
await cancelChatRequest(currentRecord.recordId);
6262
console.log('채팅 취소');
6363

@@ -67,7 +67,30 @@ export default function ChatConnectLoadingSheet() {
6767
}
6868
};
6969

70-
const isReceiver = false;
70+
//채팅방 생성 (요청 받는 사람 입장에서 생성?)
71+
const createChat = async () => {
72+
try {
73+
const data = await createChatroom(17);
74+
console.log(data);
75+
76+
if (data.code === 200) {
77+
navigate('/chatroom');
78+
closeAllSheets();
79+
}
80+
//500 이면 이미 방 있음 => 기존 채팅방으로
81+
} catch (error) {
82+
console.log(error);
83+
}
84+
};
85+
86+
//채팅 요정 거절
87+
const refuseRequest = () => {
88+
closeSheet('isChatLoadingSheetOpen');
89+
};
90+
91+
//채팅 신청한 사람이 상대가 수락했다는 sse 받으면 closeAllSheet, chatroom으로 이동
92+
93+
const isReceiver = true;
7194

7295
if (connetFail) {
7396
return (
@@ -135,8 +158,12 @@ export default function ChatConnectLoadingSheet() {
135158
{/* 받는 사람일 경우 */}
136159
{isReceiver && (
137160
<div className="absolute bottom-10 flex gap-[6px] px-3 w-full">
138-
<Button variant="primary">수락하기</Button>
139-
<Button variant="secondary">거절하기</Button>
161+
<Button onClick={createChat} variant="primary">
162+
수락하기
163+
</Button>
164+
<Button onClick={refuseRequest} variant="secondary">
165+
거절하기
166+
</Button>
140167
</div>
141168
)}
142169
</div>

src/components/modalSheet/ChatActionButtons.tsx

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -28,7 +28,7 @@ function ChatActionButtons({
2828
}: ChatActionButtonsProps) {
2929
const navigate = useNavigate();
3030

31-
const { openSheet, closeAllSheets } = useSheetStore(); // 모달 시트
31+
const { openSheet } = useSheetStore(); // 모달 시트
3232

3333
const handleGoToUserPage = () => {
3434
// closeAllSheets(); // 모든 시트를 닫아야할지 카드모달시트만 닫으면 될지 고민중

src/styles/index.css

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,8 @@
33
@import '@styles/typography.css';
44
@import '@styles/scrollbar.css';
55

6-
body {
6+
7+
html {
78
overflow-x: hidden;
89
overflow-y: hidden;
910
}

0 commit comments

Comments
 (0)