From d2fe71858358f67d776f77e5f4020efcb5a2f22e Mon Sep 17 00:00:00 2001 From: moonkanghyeon Date: Tue, 30 Dec 2025 13:38:26 +0900 Subject: [PATCH] =?UTF-8?q?feat:=20=EA=B2=8C=EC=8B=9C=EA=B8=80=20=EC=82=AD?= =?UTF-8?q?=EC=A0=9C=20=EA=B8=B0=EB=8A=A5=20=EC=B6=94=EA=B0=80=20=EB=B0=8F?= =?UTF-8?q?=20=EC=82=AD=EC=A0=9C=20=EB=AA=A8=EB=8B=AC=20=EA=B5=AC=ED=98=84?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/pages/post/PostContent.tsx | 65 ++++++++++++++++------------------ 1 file changed, 30 insertions(+), 35 deletions(-) diff --git a/src/pages/post/PostContent.tsx b/src/pages/post/PostContent.tsx index 517108f8..7581627c 100644 --- a/src/pages/post/PostContent.tsx +++ b/src/pages/post/PostContent.tsx @@ -17,6 +17,7 @@ import { instance } from '@/assets/shared/lib/axios'; import ReactMarkdown from 'react-markdown'; import remarkGfm from 'remark-gfm'; +import DeleteModal from '@/assets/components/modal/DeleteModal'; interface PostDetailType { id: number; @@ -61,6 +62,8 @@ export default function PostContent() { const [comments, setComments] = useState([]); const [isCommentLoading, setIsCommentLoading] = useState(false); + const [isDeleteModalOpen, setIsDeleteModalOpen] = useState(false); + const calculateTimeAgo = (createdAt: string) => { const now = new Date(); const created = new Date(createdAt); @@ -186,11 +189,9 @@ export default function PostContent() { const handleAdminDelete = async () => { if (!postId) return; - const confirmDelete = window.confirm('게시글을 삭제하시겠습니까?'); - if (!confirmDelete) return; - try { await instance.delete(`/api/admin/post/${postId}`); + toast.success('게시글이 삭제되었습니다.'); navigate(-1); } catch (error: unknown) { @@ -198,11 +199,20 @@ export default function PostContent() { const status = (error as { response?: { status?: number } }).response ?.status; - if (status === 401) toast.error('로그인이 필요합니다.'); - else if (status === 403) toast.error('관리자 권한이 없습니다.'); - else if (status === 404) toast.error('게시글을 찾을 수 없습니다.'); - else toast.error('게시글 삭제에 실패했습니다.'); + if (status === 401) { + toast.error('로그인이 필요합니다.'); + } else if (status === 403) { + toast.error('관리자 권한이 없습니다.'); + } else if (status === 404) { + toast.error('게시글을 찾을 수 없습니다.'); + } else { + toast.error('게시글 삭제에 실패했습니다.'); + } + } else { + toast.error('서버와 통신할 수 없습니다.'); } + } finally { + setIsDeleteModalOpen(false); } }; @@ -231,29 +241,6 @@ export default function PostContent() { } }; - const isAdmin = () => { - try { - const token = localStorage.getItem('accessToken'); - if (!token) return false; - - const payload = JSON.parse(atob(token.split('.')[1])); - - console.log('JWT payload:', payload); - - return ( - payload.role === 'ADMIN' || - payload.role === 'ROLE_ADMIN' || - payload.auth === 'ROLE_ADMIN' || - payload.authority === 'ADMIN' || - payload.roles?.includes('ADMIN') || - payload.roles?.includes('ROLE_ADMIN') - ); - } catch (e) { - console.error('isAdmin error', e); - return false; - } - }; - if (isLoading || !postData) { return ( <> @@ -363,11 +350,12 @@ export default function PostContent() { - {isAdmin() && ( - - )} + @@ -413,6 +401,13 @@ export default function PostContent() { onReport={() => setIsModalOpen(false)} /> )} + + {isDeleteModalOpen && ( + setIsDeleteModalOpen(false)} + onDelete={handleAdminDelete} + /> + )} ); }