Skip to content

Commit

Permalink
feat : 키워드 답장 편지 삭제 API 연동 (#356)
Browse files Browse the repository at this point in the history
  • Loading branch information
mmjjaa authored Dec 8, 2024
1 parent b4388b4 commit cf4ee1c
Show file tree
Hide file tree
Showing 3 changed files with 66 additions and 1 deletion.
16 changes: 15 additions & 1 deletion src/components/LetterDetailPage/Delete/DeleteModal.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ import { Margin } from '@/components/Common/Margin/Margin';
import { useParams, useNavigate, useLocation } from 'react-router-dom';
import { useDeleteKeywordLetter } from '@/hooks/useDeleteKeywordLetter';
import { useDeleteMapSentLetter } from '@/hooks/useDeleteMapSentLetter';
import { useDeleteKeywordReplyLetter } from '@/hooks/useDeleteKeywordReplyLetter';
import { useToastStore } from '@/hooks';

type DeleteModalProps = {
Expand All @@ -26,7 +27,19 @@ export const DeleteModal = ({ closeModal }: DeleteModalProps) => {
const mapMutation = useDeleteMapSentLetter({
letterIds: [Number(letterId)]
});
const mutation = letterType === 'keyword' ? keywordMutation : mapMutation;

const keywordReplyMutation = useDeleteKeywordReplyLetter({
letterId: Number(letterId),
boxType: transformedLetterType
});

const mutation =
letterType === 'keyword'
? dataType === 'received'
? keywordReplyMutation
: keywordMutation
: mapMutation;

const { addToast } = useToastStore();

const handleDelete = () => {
Expand All @@ -45,6 +58,7 @@ export const DeleteModal = ({ closeModal }: DeleteModalProps) => {
}
});
};

return (
<div className="flex flex-col bg-white rounded-2xl items-center justify-center w-full h-full p-4">
<Margin top={10} />
Expand Down
23 changes: 23 additions & 0 deletions src/hooks/useDeleteKeywordReplyLetter.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
import { useMutation, UseMutationOptions } from '@tanstack/react-query';
import { deleteKeywordReplyLetter } from '@/service/detail/deleteKeywordReplyLetter';

type UseDeleteKeywordReplyLetterProps = {
letterId: number;
boxType: string;
};

export const useDeleteKeywordReplyLetter = (
{ letterId, boxType }: UseDeleteKeywordReplyLetterProps,
options?: UseMutationOptions<string, Error, void>
) => {
return useMutation<string, Error, void>({
mutationFn: async () => {
const response = await deleteKeywordReplyLetter({
letterId,
boxType
});
return response.result;
},
...options
});
};
28 changes: 28 additions & 0 deletions src/service/detail/deleteKeywordReplyLetter.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
import { defaultApi } from '@/service/api';
import { ApiResponseType } from '@/types/apiResponse';

type deleteKeywordReplyLettersRequestProps = {
letterId: number;
boxType: string;
};

type deleteKeywordReplyLettersResponse = ApiResponseType<string>;

export async function deleteKeywordReplyLetter({
letterId,
boxType
}: deleteKeywordReplyLettersRequestProps): Promise<deleteKeywordReplyLettersResponse> {
const api = defaultApi();

const response = await api.delete<deleteKeywordReplyLettersResponse>(
'/letters/replies',
{
data: {
letterId,
boxType
}
}
);

return response.data;
}

0 comments on commit cf4ee1c

Please sign in to comment.