40 lines
939 B
TypeScript
40 lines
939 B
TypeScript
import { useMutation, useQueryClient } from "@tanstack/react-query";
|
|
import {
|
|
updatePublication,
|
|
type UpdatePublicationPayload,
|
|
} from "../../api/publications";
|
|
import { toast } from "react-toastify";
|
|
|
|
export const useUpdatePublication = () => {
|
|
const queryClient = useQueryClient();
|
|
|
|
return useMutation({
|
|
mutationFn: ({
|
|
id,
|
|
payload,
|
|
}: {
|
|
id: number;
|
|
payload: UpdatePublicationPayload;
|
|
}) => updatePublication(id, payload),
|
|
onSuccess: () => {
|
|
queryClient.invalidateQueries({ queryKey: ["publications"] });
|
|
toast.success("Updated Publication")
|
|
},
|
|
onError: (error: any) => {
|
|
const data = error?.response?.data;
|
|
|
|
if (data?.image?.length) {
|
|
toast.error(data.image[0]);
|
|
return;
|
|
}
|
|
|
|
if (data?.video?.length) {
|
|
toast.error(data.video[0]);
|
|
return;
|
|
}
|
|
|
|
toast.error("Failed to create publication");
|
|
},
|
|
});
|
|
};
|