cancel request

This commit is contained in:
hamid zarghami
2025-12-02 09:01:48 +03:30
parent 42b43c0863
commit a7ba7b664c
2 changed files with 26 additions and 5 deletions
+19 -2
View File
@@ -6,7 +6,7 @@ import { Controller, SubmitHandler, useForm } from "react-hook-form"
import { CardBank, SendWithdraw } from "../../types"
import { ErrorComponent } from "../common/error"
import { useMutation, useQueryClient } from "@tanstack/react-query"
import { sendwithdraw } from "../../services/api/wallet"
import { cancelWithdraw, sendwithdraw } from "../../services/api/wallet"
import toast from "react-hot-toast"
import { handleError } from "../../utility/error-handle"
import { Input } from "../common/input"
@@ -25,6 +25,11 @@ export const WalletAddress: FC<Props> = ({ pending, walletBalance }) => {
mutationKey: ["withdraw"]
})
const { mutate: cancelWithdrawMutation, isPending: isCancelPending } = useMutation({
mutationFn: cancelWithdraw,
mutationKey: ["cancel-withdraw"]
})
const [price, setPrice] = useState<string>('')
const { handleSubmit, formState: { errors }, control, watch } = useForm<any>({
})
@@ -86,8 +91,20 @@ export const WalletAddress: FC<Props> = ({ pending, walletBalance }) => {
}
}
}
const handleCancelWithdraw = async () => {
await cancelWithdrawMutation(undefined, {
onSuccess: () => {
toast.success("درخواست برداشت با موفقیت لغو شد")
queryClient.invalidateQueries({ queryKey: ["wallet"] })
setPrice('')
},
onError: (err: any) => handleError(err)
})
}
return (
<form onSubmit={handleSubmit(handleSendWithdraw)} className="w-full flex flex-col lg:flex-row bg-auth-form p-[30px] rounded-[40px] gap-8">
<form onSubmit={handleSubmit(pending ? handleCancelWithdraw : handleSendWithdraw)} className="w-full flex flex-col lg:flex-row bg-auth-form p-[30px] rounded-[40px] gap-8">
<div className="w-full h-full flex items-center justify-center">
<img src="/svgs/dashboard/wallet.svg" alt="wallet" className="size-full max-w-[500px] max-h-[500px]" />
</div>
+7 -3
View File
@@ -1,6 +1,10 @@
import axiosInstance from "../axios";
import { OverviewResponse } from "./overview";
export const getWalletDetails = () => axiosInstance.get<OverviewResponse[] | OverviewResponse | [], any>("/gps/overview/wallet")
export const sendwithdraw = (payload: any) => axiosInstance.post("/gps/withdraw", payload)
export const getWalletDetails = () =>
axiosInstance.get<OverviewResponse[] | OverviewResponse | [], any>(
"/gps/overview/wallet"
);
export const sendwithdraw = (payload: any) =>
axiosInstance.post("/gps/withdraw", payload);
export const cancelWithdraw = () => axiosInstance.delete("/gps/withdraw");