test cmment
parent
7fc2737439
commit
2e7a2d1740
|
@ -9,18 +9,31 @@ import Image from "next/image";
|
||||||
import PersianNumber from "plugins/PersianNumber";
|
import PersianNumber from "plugins/PersianNumber";
|
||||||
import logo from "../../../public/images/logo.png";
|
import logo from "../../../public/images/logo.png";
|
||||||
import moment from "jalali-moment";
|
import moment from "jalali-moment";
|
||||||
|
import Chapar from "plugins/Chapar";
|
||||||
|
import { toast } from "react-toastify";
|
||||||
|
import { useRouter } from "next/navigation";
|
||||||
|
|
||||||
const ProductData = ({ params, data }) => {
|
const ProductData = ({ params, data }) => {
|
||||||
console.log("data", data);
|
console.log("data", data);
|
||||||
const [product, setProduct] = useState([]);
|
const [product, setProduct] = useState([]);
|
||||||
const [specificationsHeader, setSpecificationsHeader] = useState([]);
|
const [specificationsHeader, setSpecificationsHeader] = useState([]);
|
||||||
const [productBarDetail, setProductBarDetail] = useState(0);
|
const [productBarDetail, setProductBarDetail] = useState(0);
|
||||||
|
const [comment, setComment] = useState("0");
|
||||||
|
|
||||||
|
const router = useRouter();
|
||||||
|
|
||||||
const fetchPost = async (id) => {
|
const fetchPost = async (id) => {
|
||||||
const res = await fetch(`${process.env.NEXT_PUBLIC_API_URL}/product/${id}`);
|
const res = await fetch(`${process.env.NEXT_PUBLIC_API_URL}/product/${id}`);
|
||||||
const post = await res.json();
|
const post = await res.json();
|
||||||
setProduct(post.product);
|
setProduct(post.product);
|
||||||
};
|
};
|
||||||
|
const fetchReview = async (id) => {
|
||||||
|
const res = await fetch(
|
||||||
|
`${process.env.NEXT_PUBLIC_API_URL}/product/${id}/review?page=0`
|
||||||
|
);
|
||||||
|
const post = await res.json();
|
||||||
|
setProduct(post.product);
|
||||||
|
};
|
||||||
|
|
||||||
const displaySpecifications = (specs) => {
|
const displaySpecifications = (specs) => {
|
||||||
let data = [];
|
let data = [];
|
||||||
|
@ -51,8 +64,37 @@ const ProductData = ({ params, data }) => {
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
|
const createProductReview = async () => {
|
||||||
|
const body = { title: "", comment, rate: "", productId: params.id[0] };
|
||||||
|
try {
|
||||||
|
const data = await Chapar.post(
|
||||||
|
`${process.env.NEXT_PUBLIC_API_URL}/product/review`,
|
||||||
|
body
|
||||||
|
);
|
||||||
|
|
||||||
|
// fetchReview();
|
||||||
|
} catch ({ error, status }) {
|
||||||
|
toast.error(`${error?.response?.data?.message}`, {
|
||||||
|
position: "bottom-right",
|
||||||
|
closeOnClick: true,
|
||||||
|
});
|
||||||
|
}
|
||||||
|
};
|
||||||
|
|
||||||
|
const handleCreateReview = () => {
|
||||||
|
const token = localStorage.getItem("token");
|
||||||
|
|
||||||
|
if (token) {
|
||||||
|
createProductReview();
|
||||||
|
} else {
|
||||||
|
router.push("/login");
|
||||||
|
}
|
||||||
|
};
|
||||||
|
|
||||||
useEffect(() => {
|
useEffect(() => {
|
||||||
fetchPost(params.id[0]);
|
fetchPost(params.id[0]);
|
||||||
|
fetchReview(params.id[0]);
|
||||||
}, []);
|
}, []);
|
||||||
|
|
||||||
useEffect(() => {
|
useEffect(() => {
|
||||||
|
@ -137,13 +179,13 @@ const ProductData = ({ params, data }) => {
|
||||||
{data?.product?.files?.length > 0 ? (
|
{data?.product?.files?.length > 0 ? (
|
||||||
<Image
|
<Image
|
||||||
src={`${process.env.NEXT_PUBLIC_STORAGE_URL}/${
|
src={`${process.env.NEXT_PUBLIC_STORAGE_URL}/${
|
||||||
product.files && product.files[0].fileLocation
|
product?.files && product?.files[0].fileLocation
|
||||||
}`}
|
}`}
|
||||||
width={350}
|
width={350}
|
||||||
height={350}
|
height={350}
|
||||||
className=" mx-auto !object-cover"
|
className=" mx-auto !object-cover"
|
||||||
onClick={() => CTX.setIsOpenLightBox(true)}
|
onClick={() => CTX.setIsOpenLightBox(true)}
|
||||||
alt={`${product.persianName} - ${product.englishName}`}
|
alt={`${product?.persianName} - ${product?.englishName}`}
|
||||||
property
|
property
|
||||||
loading="eager"
|
loading="eager"
|
||||||
/>
|
/>
|
||||||
|
@ -528,8 +570,12 @@ const ProductData = ({ params, data }) => {
|
||||||
id=""
|
id=""
|
||||||
cols="30"
|
cols="30"
|
||||||
rows="8"
|
rows="8"
|
||||||
|
onChange={(e) => setComment(e.target.value)}
|
||||||
/>
|
/>
|
||||||
<div className="flex justify-end">
|
<div
|
||||||
|
className="flex justify-end"
|
||||||
|
onClick={() => handleCreateReview()}
|
||||||
|
>
|
||||||
<button className="btn btn-primary text-sm py-3 rounded-3xl">
|
<button className="btn btn-primary text-sm py-3 rounded-3xl">
|
||||||
ارسال دیدگاه ( برای ارسال دیدگاه باید ابتدا ورود کنید){" "}
|
ارسال دیدگاه ( برای ارسال دیدگاه باید ابتدا ورود کنید){" "}
|
||||||
</button>
|
</button>
|
||||||
|
|
Loading…
Reference in New Issue