From df915182735e685edc0c2574054c143fd7360bb2 Mon Sep 17 00:00:00 2001 From: Sonseongoh Date: Sun, 10 Nov 2024 15:18:34 +0900 Subject: [PATCH 1/3] =?UTF-8?q?fix:=20=EB=A9=A4=EB=B2=84=EC=9D=BC=20?= =?UTF-8?q?=EA=B2=BD=EC=9A=B0=EC=97=90=EB=8F=84=20=EC=82=AD=EC=A0=9C=20?= =?UTF-8?q?=EC=A7=84=ED=96=89=EC=8B=9C=20=EB=AA=A8=EB=8B=AC=20=EB=9D=84?= =?UTF-8?q?=EC=9A=B0=EA=B8=B0=20(#107)?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/components/comment/CommentList.tsx | 58 +++++++++++++++++++------- 1 file changed, 44 insertions(+), 14 deletions(-) diff --git a/src/components/comment/CommentList.tsx b/src/components/comment/CommentList.tsx index 9c4a471..e690b15 100644 --- a/src/components/comment/CommentList.tsx +++ b/src/components/comment/CommentList.tsx @@ -46,24 +46,56 @@ const CommentList = () => { const handleDelete = async (commentId: number, type: 'MEMBER' | 'GUEST', password?: string) => { try { if (type === 'MEMBER') { - await axios.delete( - `http://nubble-backend-eb-1-env.eba-f5sb82hp.ap-northeast-2.elasticbeanstalk.com/comments/member/${commentId}`, - { - headers: { 'SESSION-ID': sessionId }, + // 멤버는 default 타입 모달 띄우기 + openModal({ + type: 'default', + title: '댓글 삭제 확인', + onAction: async () => { + try { + // 실제 삭제 요청 + await axios.delete( + `http://nubble-backend-eb-1-env.eba-f5sb82hp.ap-northeast-2.elasticbeanstalk.com/comments/member/${commentId}`, + { + headers: { 'SESSION-ID': sessionId }, + }, + ) + // 삭제 후 상태 업데이트 + setCommentsData((prevComments) => + prevComments.filter((comment) => comment.commentId !== commentId), + ) + } catch (error) { + console.error('댓글 삭제 중 에러 발생:', error) + } }, - ) + }) } else { - // 비밀번호가 없는 경우 모달을 열어 비밀번호 요청 + // 게스트는 password 타입 모달 띄우기 if (!password) { openModal({ type: 'password', title: '댓글 삭제 확인', - onAction: (inputPassword) => handleDelete(commentId, 'GUEST', inputPassword), + onAction: async (inputPassword) => { + try { + await axios.delete( + `http://nubble-backend-eb-1-env.eba-f5sb82hp.ap-northeast-2.elasticbeanstalk.com/comments/guest/${commentId}`, + { + headers: { 'Content-Type': 'application/json' }, + data: { guestPassword: inputPassword }, + }, + ) + // 삭제 후 상태 업데이트는 여기에서 실행 + setCommentsData((prevComments) => + prevComments.filter((comment) => comment.commentId !== commentId), + ) + } catch (error) { + console.error('댓글 삭제 중 에러 발생:', error) + } + }, }) return } - // 비밀번호가 있는 경우 삭제 요청 진행 + // 비밀번호가 제공된 경우 삭제 진행 await axios.delete( `http://nubble-backend-eb-1-env.eba-f5sb82hp.ap-northeast-2.elasticbeanstalk.com/comments/guest/${commentId}`, { @@ -71,17 +103,15 @@ const CommentList = () => { data: { guestPassword: password }, }, ) + // 삭제 후 상태 업데이트 + setCommentsData((prevComments) => + prevComments.filter((comment) => comment.commentId !== commentId), + ) } - - // 댓글 삭제 후 상태 업데이트 - setCommentsData((prevComments) => - prevComments.filter((comment) => comment.commentId !== commentId), - ) } catch (error) { console.error('댓글 삭제 중 에러 발생:', error) } } - if (error) return

{error}

if (!commentsData.length) return

댓글이 없습니다.

From ec54467fa62f037e8586901f28e336efda8d8395 Mon Sep 17 00:00:00 2001 From: Sonseongoh Date: Sun, 10 Nov 2024 23:10:53 +0900 Subject: [PATCH 2/3] =?UTF-8?q?feat:=20=EB=8C=93=EA=B8=80=20=EC=82=AD?= =?UTF-8?q?=EC=A0=9C=20=EB=B0=8F=20=EB=B9=84=EB=B0=80=EB=B2=88=ED=98=B8=20?= =?UTF-8?q?=EC=98=A4=EB=A5=98=EC=8B=9C=20=ED=86=A0=EC=8A=A4=ED=8A=B8?= =?UTF-8?q?=EC=95=8C=EB=A6=BC=20(#107)?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/components/comment/CommentList.tsx | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) diff --git a/src/components/comment/CommentList.tsx b/src/components/comment/CommentList.tsx index e690b15..dc953cb 100644 --- a/src/components/comment/CommentList.tsx +++ b/src/components/comment/CommentList.tsx @@ -9,6 +9,7 @@ import { formatDate } from '@/utils/formatDate' import { useAuthStore } from '@/stores/authStore' import useModalStore from '@/stores/modalStore' import Modal from '@components/Modal' +import { ShowToast } from '@components/Toast' interface Comment { commentId: number @@ -59,12 +60,14 @@ const CommentList = () => { headers: { 'SESSION-ID': sessionId }, }, ) + ShowToast('댓글이 삭제되었습니다.', 'success') // 삭제 후 상태 업데이트 setCommentsData((prevComments) => prevComments.filter((comment) => comment.commentId !== commentId), ) } catch (error) { console.error('댓글 삭제 중 에러 발생:', error) + ShowToast('댓글 삭제 중 오류가 발생했습니다.', 'failed') } }, }) @@ -87,8 +90,9 @@ const CommentList = () => { setCommentsData((prevComments) => prevComments.filter((comment) => comment.commentId !== commentId), ) + ShowToast('댓글이 삭제되었습니다.', 'success') } catch (error) { - console.error('댓글 삭제 중 에러 발생:', error) + ShowToast('비밀번호가 틀렸습니다.', 'failed') } }, }) From fa55ba2374e15c8607869fec469e6f02af02137f Mon Sep 17 00:00:00 2001 From: Sonseongoh Date: Sun, 10 Nov 2024 23:18:31 +0900 Subject: [PATCH 3/3] =?UTF-8?q?fix:=20any=20=ED=83=80=EC=9E=85=20=EC=A0=9C?= =?UTF-8?q?=EA=B1=B0=20(#107)?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/pages/AddQuestion.tsx | 10 +++++++--- 1 file changed, 7 insertions(+), 3 deletions(-) diff --git a/src/pages/AddQuestion.tsx b/src/pages/AddQuestion.tsx index bb25bd8..b5e54d3 100644 --- a/src/pages/AddQuestion.tsx +++ b/src/pages/AddQuestion.tsx @@ -40,9 +40,13 @@ const AddQuestion = () => { useEffect(() => { const getCodingTestList = async () => { try { - const res = await axios.get(`${import.meta.env.VITE_NUBBLE_SERVER}/coding-problems`) - const data = res.data.problems.map((problem: any) => ({ - id: problem.problemId, // problemId 필드를 id로 저장 + const res = await axios.get<{ problems: Question[] }>( + `${import.meta.env.VITE_NUBBLE_SERVER}/coding-problems`, + ) + + // ProblemResponse 배열을 Question 배열로 변환 + const data: Question[] = res.data.problems.map((problem) => ({ + id: problem.id, quizDate: problem.quizDate, problemTitle: problem.problemTitle, }))