diff --git a/src/api/auth.ts b/src/api/auth.ts index df62358..b85185f 100644 --- a/src/api/auth.ts +++ b/src/api/auth.ts @@ -33,3 +33,11 @@ export const logout = async () => { throw error } } + +export const signout = async () => { + try { + await authApi.post('/auth/withdraw') + } catch (error) { + throw error + } +} diff --git a/src/app/poll/[id]/page.tsx b/src/app/poll/[id]/page.tsx index 65772a8..2231442 100644 --- a/src/app/poll/[id]/page.tsx +++ b/src/app/poll/[id]/page.tsx @@ -194,7 +194,7 @@ export default function PollDetailPage() { try { await deleteVote(data.voteId) setDeleteModalOpen(false) - router.back() + router.push('/balanse') } catch (error) { console.error('게시글 삭제 실패:', error) alert('게시글 삭제에 실패했습니다.') @@ -259,6 +259,7 @@ export default function PollDetailPage() { comments={comments} voteId={data.voteId} onClose={() => setOpen(false)} + profile={profile} /> )} {data && ( diff --git a/src/components/pages/my/accountControlSection.tsx b/src/components/pages/my/accountControlSection.tsx index 689772f..fd21f9f 100644 --- a/src/components/pages/my/accountControlSection.tsx +++ b/src/components/pages/my/accountControlSection.tsx @@ -1,5 +1,5 @@ import { useAppDispatch } from '@/hooks/utils/useAppDispatch' -import { logoutThunk } from '@/store/thunks/authThunks' +import { logoutThunk, signoutThunk } from '@/store/thunks/authThunks' export default function AccountControlSection() { const dispatch = useAppDispatch() @@ -8,14 +8,20 @@ export default function AccountControlSection() { dispatch(logoutThunk()) } + const handleSignout = () => { + dispatch(signoutThunk()) + } + return ( 계정 관리 - + 로그아웃 - - 탈퇴하기 + + + 탈퇴하기 + ) diff --git a/src/components/pages/poll/Comment/commentDetail.tsx b/src/components/pages/poll/Comment/commentDetail.tsx index af223bf..9d7a47c 100644 --- a/src/components/pages/poll/Comment/commentDetail.tsx +++ b/src/components/pages/poll/Comment/commentDetail.tsx @@ -26,17 +26,20 @@ import { ModalBody, ModalFooter, } from '@/components/ui/modal' +import { Profile } from '@/types/member' interface CommentDetailProps { comments?: Comment[] voteId?: number | string onClose?: () => void + profile: Profile } const CommentDetail = ({ comments = [], voteId, onClose, + profile, }: CommentDetailProps) => { const [openReplies, setOpenReplies] = useState>({}) const [currentSort, setCurrentSort] = useState<'popular' | 'latest'>( @@ -201,13 +204,12 @@ const CommentDetail = ({ const confirmDelete = async () => { const { commentId } = deleteConfirmModal - if (!commentId) return + if (!commentId || !voteId) return try { await deleteComment(commentId) - setLocalComments((prev) => - prev.filter((comment) => comment.commentId !== commentId), - ) + const response = await fetchComments(voteId, { sort: currentSort }) + setLocalComments(response.comments) setDeleteConfirmModal({ isOpen: false, commentId: null }) } catch (error) { console.error('댓글 삭제 실패:', error) @@ -294,12 +296,15 @@ const CommentDetail = ({ - toggleMenu(comment.commentId)} - > - - + {(profile.role === 'ADMIN' || + comment.nickname === profile.nickname) && ( + toggleMenu(comment.commentId)} + > + + + )} {openMenus[comment.commentId] && ( async (dispatch: AppDispatch) => { @@ -53,3 +53,13 @@ export const logoutThunk = () => async (dispatch: AppDispatch) => { throw err } } + +export const signoutThunk = () => async (dispatch: AppDispatch) => { + try { + await signoutApi() + dispatch(logout()) + clearTokens() + } catch (err) { + throw err + } +}