diff --git a/src/components/LetterDetailPage/Delete/DeleteModal.tsx b/src/components/LetterDetailPage/Delete/DeleteModal.tsx index 350dd2f8..6a76f79b 100644 --- a/src/components/LetterDetailPage/Delete/DeleteModal.tsx +++ b/src/components/LetterDetailPage/Delete/DeleteModal.tsx @@ -1,6 +1,7 @@ import { Margin } from '@/components/Common/Margin/Margin'; -import { useParams, useNavigate } from 'react-router-dom'; +import { useParams, useNavigate, useLocation } from 'react-router-dom'; import { useDeleteKeywordLetter } from '@/hooks/useDeleteKeywordLetter'; +import { useDeleteMapSentLetter } from '@/hooks/useDeleteMapSentLetter'; import { useToastStore } from '@/hooks'; type DeleteModalProps = { @@ -9,17 +10,23 @@ type DeleteModalProps = { export const DeleteModal = ({ closeModal }: DeleteModalProps) => { const navigate = useNavigate(); + const { pathname } = useLocation(); + const letterType = pathname.split('/')[2]; const { dataType, letterId } = useParams<{ dataType: string; letterId: string; }>(); const transformedLetterType = dataType === 'sent' ? 'SEND' : 'RECEIVE'; - const mutation = useDeleteKeywordLetter({ + const keywordMutation = useDeleteKeywordLetter({ letterId: Number(letterId), boxType: transformedLetterType }); + const mapMutation = useDeleteMapSentLetter({ + letterIds: [Number(letterId)] + }); + const mutation = letterType === 'keyword' ? keywordMutation : mapMutation; const { addToast } = useToastStore(); const handleDelete = () => { @@ -27,14 +34,17 @@ export const DeleteModal = ({ closeModal }: DeleteModalProps) => { onSuccess: () => { closeModal(); addToast('편지 삭제에 성공했습니다.', 'success'); - navigate('/storage/keyword'); + navigate( + letterType === 'keyword' + ? '/storage/keyword' + : '/storage/map' + ); }, onError: () => { addToast('편지 삭제에 실패했습니다.', 'error'); } }); }; - return (