fix : change count with checkout discount

This commit is contained in:
alij
2024-06-23 09:44:47 +04:30
parent 5250ae2a54
commit 780c345629

View File

@@ -19,12 +19,12 @@ const ModalBuy = ({ isOpen, setIsOpen, configId }: ModalBuyProps) => {
const separateByThree = (num: number): string => { const separateByThree = (num: number): string => {
return num.toString().replace(/\B(?=(\d{3})+(?!\d))/g, ","); return num.toString().replace(/\B(?=(\d{3})+(?!\d))/g, ",");
}; };
const { data, error, isLoading, isFetching } = useQuery({ const { data, error, isLoading, isFetching, refetch } = useQuery({
queryKey: ["configSee", configId], queryKey: ["configSee", configId],
queryFn: () => { queryFn: () => {
return axios.get(`/home/config/${configId}/see`); return axios.get(`/home/config/${configId}/see`);
}, },
enabled: isOpen, enabled: isOpen,
}); });
const [price, setPrice] = useState(0); const [price, setPrice] = useState(0);
@@ -98,6 +98,8 @@ const ModalBuy = ({ isOpen, setIsOpen, configId }: ModalBuyProps) => {
return `${res.data.alert}`; return `${res.data.alert}`;
}, },
error: (err: AxiosError) => { error: (err: AxiosError) => {
formik.setFieldValue("discount", "");
refetch();
let errorMessage = "یک خطای غیرمنتظره رخ داد"; let errorMessage = "یک خطای غیرمنتظره رخ داد";
if ( if (
err.response?.data && err.response?.data &&
@@ -116,14 +118,14 @@ const ModalBuy = ({ isOpen, setIsOpen, configId }: ModalBuyProps) => {
if (status === "inc") { if (status === "inc") {
formik.setFieldValue("count", formik.values.count + 1); formik.setFieldValue("count", formik.values.count + 1);
chnageCountDebouncedMutation({ chnageCountDebouncedMutation({
...formik.values,
count: formik.values.count + 1, count: formik.values.count + 1,
status: formik.values.status,
}); });
} else if (status === "dec") { } else if (status === "dec") {
formik.setFieldValue("count", formik.values.count - 1); formik.setFieldValue("count", formik.values.count - 1);
chnageCountDebouncedMutation({ chnageCountDebouncedMutation({
...formik.values,
count: formik.values.count - 1, count: formik.values.count - 1,
status: formik.values.status,
}); });
} }
}; };
@@ -205,7 +207,7 @@ const ModalBuy = ({ isOpen, setIsOpen, configId }: ModalBuyProps) => {
مبلغ قابل پرداخت :{" "} مبلغ قابل پرداخت :{" "}
<span className="px-[2px] rounded-md bg-secondTheme text-gray-950"> <span className="px-[2px] rounded-md bg-secondTheme text-gray-950">
{separateByThree( {separateByThree(
price === 0 ? data?.data?.result?.price || 0 : price price === 0 ? data?.data?.result?.price || 0 : price
)} )}
</span> </span>
</h1> </h1>