From d2d49d5607bda486fd9e708a021aaca67f6edf8b Mon Sep 17 00:00:00 2001 From: shlee9999 <95556588+shlee9999@users.noreply.github.com> Date: Thu, 5 Dec 2024 11:23:53 +0900 Subject: [PATCH] =?UTF-8?q?=E2=99=BB=EF=B8=8FRefactor:=20else=EB=AC=B8=20?= =?UTF-8?q?=EC=A0=9C=EA=B1=B0?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .vscode/typescript.code-snippets | 8 ++++---- src/apis/chatRoom/createChatRoom.ts | 5 ++--- src/apis/chatRoom/fetchChatRoomList.ts | 5 ++--- src/apis/friend/fetchFriendList.ts | 5 ++--- src/apis/member/fetchProfile.ts | 5 ++--- src/components/SendMessageForm/index.tsx | 19 +++++++++++-------- 6 files changed, 23 insertions(+), 24 deletions(-) diff --git a/.vscode/typescript.code-snippets b/.vscode/typescript.code-snippets index e7e11ee..4bd6c80 100644 --- a/.vscode/typescript.code-snippets +++ b/.vscode/typescript.code-snippets @@ -59,10 +59,10 @@ " default:", " throw new Error(message || '알 수 없는 오류가 발생했습니다.')", " }", - " } else {", - " // 요청 자체가 실패한 경우", - " throw new Error('네트워크 연결을 확인해주세요')", - " }", + " } ", + " // 요청 자체가 실패한 경우", + " throw new Error('네트워크 연결을 확인해주세요')", + " ", " }", "", " console.error('예상치 못한 에러:', error);", diff --git a/src/apis/chatRoom/createChatRoom.ts b/src/apis/chatRoom/createChatRoom.ts index f527849..bde5dad 100644 --- a/src/apis/chatRoom/createChatRoom.ts +++ b/src/apis/chatRoom/createChatRoom.ts @@ -37,10 +37,9 @@ export const createChatRoom = async (req: CreateChatRoomRequest): Promise & { export default function SendMessageForm({ chatRoomId, chatCount, ...rest }: SendMessageFormProps) { const onSubmit = async (e: React.FormEvent) => { e.preventDefault() - if (rest.onSubmit) rest.onSubmit(e) - else { - if (chatCount === 0) { - //* 채팅방 생성 - await createChatRoom({ opponentMemberId: 123 }) - } - //* 채팅 전송 웹소켓 + if (rest.onSubmit) { + rest.onSubmit(e) + return } + + if (chatCount === 0) { + //* 채팅방 생성 + await createChatRoom({ opponentMemberId: 123 }) + } + //* 채팅 전송 웹소켓 + console.log('chatRoomId:', chatRoomId) } - console.log('chatRoomId:', chatRoomId) + return (