Skip to content

Commit cf055a0

Browse files
committed
Feat: 댓글 삭제 api 추가 #65
1 parent 2940baa commit cf055a0

File tree

4 files changed

+41
-3
lines changed

4 files changed

+41
-3
lines changed

components/ui/BoardCard/BoardCardPackage/BoardCardModalPackage/ModalComments.tsx

+3-3
Original file line numberDiff line numberDiff line change
@@ -52,14 +52,14 @@ export default function BoardCardModalComments({
5252
>
5353
<li className="w-full rounded-[10px] hover:bg-primary-50 active:bg-primary-100">
5454
<button className="w-full p-3 body1" type="button">
55-
차단하기
55+
삭제하기
5656
</button>
5757
</li>
58-
<li className="w-full rounded-[10px] hover:bg-primary-50 active:bg-primary-100">
58+
{/* <li className="w-full rounded-[10px] hover:bg-primary-50 active:bg-primary-100">
5959
<button className="w-full p-3 body1" type="button">
6060
신고하기
6161
</button>
62-
</li>
62+
</li> */}
6363
<li className="w-full rounded-[10px] hover:bg-primary-50 active:bg-primary-100">
6464
<button
6565
className="w-full p-3 body1"

components/ui/BoardCard/ModalBoardCard.tsx

+1
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,7 @@ export default function ModalBoardCard({ board }: { board: Board }) {
1111
userName={board.writer}
1212
userImage={board.userImageUrl}
1313
createdDate={board.createdDate}
14+
boardId={board.id}
1415
/>
1516
<BoardCardModal.Content
1617
type="modal"

hooks/mutations/useDeleteComment.ts

+17
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
1+
import { deleteComment } from '@/service/board';
2+
import Toast from '@/utils/notification';
3+
import { useMutation } from '@tanstack/react-query';
4+
5+
export default function useDeleteComment() {
6+
const { mutate, isLoading } = useMutation({
7+
mutationFn: ({ boardId, replyId }: { boardId: number; replyId: number }) =>
8+
deleteComment(boardId, replyId),
9+
onSuccess: () => {
10+
Toast.success('댓글이 성공적으로 삭제 되었습니다.');
11+
},
12+
onError: () => {
13+
Toast.error('댓글을 삭제하지 못했습니다. 잠시후 다시 시도해주세요.🥲');
14+
},
15+
});
16+
return { mutate, isLoading };
17+
}

service/board.ts

+20
Original file line numberDiff line numberDiff line change
@@ -74,6 +74,26 @@ export async function getCommentList(
7474
}
7575
}
7676

77+
export async function deleteComment(boardId: number, replyId: number) {
78+
const url = `/endpoint/api/reply/remove/${boardId}/${replyId}`;
79+
try {
80+
const response = await fetch(url);
81+
if (response.status === 401) {
82+
throw new AuthError('로그인이 필요한 서비스입니다.');
83+
}
84+
if (!response.ok) {
85+
throw new Error(`서버오류:${response.status}`);
86+
}
87+
return await response.json();
88+
} catch (error) {
89+
if (error instanceof AuthError) {
90+
window.location.replace('/auth/login');
91+
alert(error.message);
92+
}
93+
throw error;
94+
}
95+
}
96+
7797
export async function addBookmarkBoard(boardId: number) {
7898
const url = `endpoint/api/bookmark/add?boardId=${boardId}`;
7999
try {

0 commit comments

Comments
 (0)