25 lines
822 B
JavaScript
25 lines
822 B
JavaScript
import { useMutation, useQueryClient } from "@tanstack/react-query";
|
|
import PaymentRequestRepository from "../repositories/PaymentRequestRepository";
|
|
import showToast from "../services/toastService";
|
|
|
|
export const useCreatePaymentRequest = (onSuccessCallBack) => {
|
|
const queryClient = useQueryClient();
|
|
|
|
return useMutation({
|
|
mutationFn: async (payload) => {
|
|
await PaymentRequestRepository.CreatePaymentRequest(payload);
|
|
},
|
|
|
|
onSuccess: (_, variables) => {
|
|
queryClient.invalidateQueries({ queryKey: ["PaymentRequest"] });
|
|
showToast("Payment Created Successfully", "success");
|
|
if (onSuccessCallBack) onSuccessCallBack();
|
|
},
|
|
onError: (error) => {
|
|
showToast(
|
|
error.message || "Something went wrong please try again !",
|
|
"error"
|
|
);
|
|
},
|
|
});
|
|
}; |