fix : fix send request before open modal
This commit is contained in:
@@ -4,11 +4,17 @@ import Alert from "../../../../../components/alert/Alert";
|
||||
import Button from "../../../../../components/button";
|
||||
import ModalBuy from "./ModalBuy";
|
||||
import { useState } from "react";
|
||||
import { useSelector } from "react-redux";
|
||||
import { RootState } from "../../../../../redux/store";
|
||||
import { useNavigate } from "react-router-dom";
|
||||
import toast from "react-hot-toast";
|
||||
|
||||
const ListAllProduct = ({ activeId }: { activeId: number }) => {
|
||||
const axios = useAxios();
|
||||
const [isOpen, setIsOpen] = useState(false);
|
||||
const [configId, setConfigId] = useState(1);
|
||||
const { token } = useSelector((state: RootState) => state.token);
|
||||
const navigate = useNavigate();
|
||||
const { data, error, isLoading, isFetching } = useQuery({
|
||||
queryKey: ["configs", activeId],
|
||||
queryFn: () => {
|
||||
@@ -67,6 +73,7 @@ const ListAllProduct = ({ activeId }: { activeId: number }) => {
|
||||
<div className="w-full h-full flex flex-col" key={item.id}>
|
||||
<img src={item.image} alt={item.title} />
|
||||
<div className="w-full h-full flex justify-center items-center">
|
||||
{token ? (
|
||||
<Button
|
||||
extra="!w-4/5 !bg-secondTheme"
|
||||
onClick={() => {
|
||||
@@ -76,6 +83,17 @@ const ListAllProduct = ({ activeId }: { activeId: number }) => {
|
||||
>
|
||||
خرید
|
||||
</Button>
|
||||
) : (
|
||||
<Button
|
||||
extra="!w-4/5 !bg-secondTheme"
|
||||
onClick={() => {
|
||||
toast.error("برای خرید باید وارد شوید");
|
||||
navigate("/login");
|
||||
}}
|
||||
>
|
||||
ورود
|
||||
</Button>
|
||||
)}
|
||||
</div>
|
||||
</div>
|
||||
);
|
||||
|
||||
@@ -24,6 +24,7 @@ const ModalBuy = ({ isOpen, setIsOpen, configId }: ModalBuyProps) => {
|
||||
queryFn: () => {
|
||||
return axios.get(`/home/config/${configId}/see`);
|
||||
},
|
||||
enabled: isOpen,
|
||||
});
|
||||
const [price, setPrice] = useState(0);
|
||||
|
||||
@@ -204,7 +205,7 @@ const ModalBuy = ({ isOpen, setIsOpen, configId }: ModalBuyProps) => {
|
||||
مبلغ قابل پرداخت :{" "}
|
||||
<span className="px-[2px] rounded-md bg-secondTheme text-gray-950">
|
||||
{separateByThree(
|
||||
price === 0 ? data?.data?.result?.price : price
|
||||
price === 0 ? data?.data?.result?.price || 0 : price
|
||||
)}
|
||||
</span>
|
||||
</h1>
|
||||
|
||||
Reference in New Issue
Block a user