You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
 
 
 

207 lines
7.6 KiB

/* eslint-disable jsx-a11y/anchor-is-valid */
import React from "react";
import { Link, useHistory } from "react-router-dom";
import { toast } from "react-toastify";
import proxy from "~/Redux/proxy";
// import basket from "../../../assets/icons/basket.png";
import basket2 from "../../../assets/icons/basket2.png";
import { connect } from "react-redux";
import { userProduct } from "~/Redux/actions";
import "./index.scss";
const grades = [
window.t("پیش دبستان"),
window.t("اول"),
window.t("دوم"),
window.t("سوم"),
window.t("چهارم"),
window.t("پنجم"),
window.t("ششم"),
window.t("هفتم"),
window.t("هشتم"),
window.t("نهم"),
window.t("دهم"),
window.t("یازدهم"),
window.t("دوازدهم"),
];
function Product(props) {
let history = useHistory();
function Navigate({ path }) {
history.push(path);
}
const { product } = props;
let productId = localStorage.getItem("pushToCart");
if (productId) {
localStorage.removeItem("pushToCart");
props.pushToCart({
productId,
userId: props.id,
count: 1,
});
setTimeout(() => history.push("/cart"), 2000);
}
return (
<>
{window.innerWidth < 1000 ? (
<div className="mobile-products-product d-flex flex-column ">
<Link
to={`/products/physical/${product.id}`}
className=" align-items-center d-flex flex-column "
style={{ textDecoration: "none" }}
>
<img
className="pimg"
src={`https://dnvn.ir/api/v1/file/${product.fileIds}`}
alt={window.t("عکس مجصول")}
/>
<div className="mobile-products-product__info d-flex flex-column">
<h1>{`${product.name} پایه ${grades[product.gradeId]}`}</h1>
</div>
</Link>
<div className="mobile-products-product__links d-flex flex-column">
<div className="d-flex" style={{ width: "100%" }}>
<Link
to={`/products/physical/${product.id}`}
className="mobile-products-product__links--physical d-flex justify-content-between align-items-center"
>
<h2> {window.t("نسخه چاپی")}</h2>
<span>
{product.product[0].price} {window.t("تومان")}
</span>
</Link>
<div
className="mobile-products-product__links--basket d-flex"
style={{ backgroundColor: "#7fc75d" }}
onClick={() => {
if (proxy.status())
props.pushToCart({
productId: product.product[0].id,
userId: props.id,
count: 1,
});
else {
localStorage.setItem(
"afterLogin",
window.location.pathname
);
localStorage.setItem("pushToCart", product.product[0].id);
Navigate({ path: "/auth" });
}
}}
>
<img src={basket2} alt="" width="20px" height="20px" />
</div>
</div>
{/* <div className="d-flex" style={{ width: "100%", opacity: 0.3 }}>
<span
to={`/products/digital/${product.id}`}
className="mobile-products-product__links--ar d-flex justify-content-between align-items-center"
>
<h2> الکترونیکی")}</h2>
{/* <span>{product.product[0].price} تومان")}</span>
<span> به زودی")}</span>
</span>
<div
className="mobile-products-product__links--basket d-flex"
// onClick={() => {
// proxy.status()
// ? this.props.pushToCart({
// productId: product.product[0].id,
// userId: this.props.id,
// count: 1,
// })
// : toast.info("ابتدا وارد حساب کاربری خود شوید.");
// }}
>
<img src={basket} alt="" width="20px" height="20px" />
</div>
</div> */}
</div>
</div>
) : null}
{window.innerWidth > 1000 ? (
<article className="products-product d-flex flex-column align-items-center">
<Link
to={`/products/physical/${product.id}`}
style={{ textDecoration: "none" }}
>
<img
className="pimg"
src={`https://dnvn.ir/api/v1/file/${product.fileIds}`}
alt={product.name}
/>
<h1 style={{ fontSize: 15 }}>
{`${product.name} ${window.t("پایه")} ${grades[product.gradeId]}`}
</h1>
</Link>
<div className="d-flex" style={{ width: "100%" }}>
<Link
to={`/products/physical/${product.id}`}
style={{ fontSize: 12 }}
className="products-product--physical d-flex justify-content-between align-items-center"
>
<h2 style={{ fontSize: 12 }}>{window.t("نسخه چاپی")}</h2>
<span style={{ fontSize: 12 }}>
{product.product[0].price} {window.t("تومان")}
</span>
</Link>
<div
className="products-product--basket d-flex"
style={{ backgroundColor: "#7fc75d", marginTop: 0 }}
onClick={() => {
if (proxy.status())
props.pushToCart({
productId: product.product[0].id,
userId: props.id,
count: 1,
});
else {
toast.info(
window.t("جهت ادامه فرآیند خرید وارد حساب خود شوید")
);
localStorage.setItem("afterLogin", window.location.pathname);
localStorage.setItem("pushToCart", product.product[0].id);
Navigate({ path: "/auth" });
}
}}
>
<img src={basket2} alt="" width="20px" height="20px" />
</div>
</div>
{/* <div className="d-flex" style={{ width: "100%", opacity: 0.3 }}>
<div
to={`/products/digital/${product.id}`}
className="products-product--ar d-flex justify-content-between align-items-center"
>
<h2 style={{ fontSize: 12 }}>{window.t("نسخه الکترونیک</h2>
<span style={{ fontSize: 12 }}>
{/* {product.product[0].price} تومان
به زودی")} </span>
</div>
<div
className="products-product--basket d-flex"
// onClick={() => {
// proxy.status()
// ? this.props.pushToCart({
// productId: product.product[0].id,
// userId: this.props.id,
// count: 1,
// })
// : toast.info("ابتدا وارد حساب کاربری خود شوید.");
// }}
>
<img src={basket} alt="" width="20px" height="20px" />
</div>
</div> */}
</article>
) : null}
</>
);
}
export default connect((state) => ({}), {
pushToCart: userProduct.add,
})(Product);