-
Notifications
You must be signed in to change notification settings - Fork 1
/
mutations.tsx
34 lines (30 loc) · 965 Bytes
/
mutations.tsx
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
import { useMutation, type UseQueryOptions } from "@tanstack/react-query";
import { useOverlay } from "@toss/use-overlay";
import type { AxiosError } from "axios";
import DuplicatedOverlay from "~/components/Post/PostAddPage/DuplicatedOverlay";
import { deletePost, updatePost, uploadPost } from ".";
export const useDeletePost = (
onSuccess: Pick<UseQueryOptions, "onSuccess">["onSuccess"]
) =>
useMutation(deletePost, {
onSuccess
});
export const useUpdatePost = (
onSuccess: Pick<UseQueryOptions, "onSuccess">["onSuccess"]
) =>
useMutation(updatePost, {
onSuccess
});
export const useUploadPost = (
onSuccess: Pick<UseQueryOptions, "onSuccess">["onSuccess"]
) => {
const overlay = useOverlay();
return useMutation(uploadPost, {
onSuccess,
onError: (e: AxiosError<{ message: string }>) => {
if (e.response?.data.message === "Duplicated item") {
overlay.open(() => <DuplicatedOverlay />);
}
}
});
};