import React from "react"; import { connect } from "react-redux"; import { userProduct } from "~/Redux/actions"; import { makeStyles } from "@material-ui/core/styles"; import Table from "@material-ui/core/Table"; import TableBody from "@material-ui/core/TableBody"; import TableCell from "@material-ui/core/TableCell"; import TableContainer from "@material-ui/core/TableContainer"; import TableHead from "@material-ui/core/TableHead"; import TableRow from "@material-ui/core/TableRow"; import Paper from "@material-ui/core/Paper"; import DeleteOutlineOutlinedIcon from "@material-ui/icons/DeleteOutlineOutlined"; import "./index.scss"; const useStyles = makeStyles({ table: {}, }); const grades = [ "پیش دبستان", "اول", "دوم", "سوم", "چهارم", "پنجم", "ششم", "هفتم", "هشتم", "نهم", "دهم", "یازدهم", "دوازدهم", ]; const maxMobileSize = 550; const maxDesktopSize = 1250; const fontSize = { mobile: { info: { strong: window.innerWidth > maxMobileSize ? 15 : window.innerWidth / 28, p: window.innerWidth > maxMobileSize ? 12 : window.innerWidth / 36, span: window.innerWidth > maxMobileSize ? 12 : window.innerWidth / 36, }, price: { strong: window.innerWidth > maxMobileSize ? 16 : window.innerWidth / 22, span: window.innerWidth > maxMobileSize ? 13 : window.innerWidth / 40, }, counter: { button: window.innerWidth > maxMobileSize ? 20 : window.innerWidth / 25, span: window.innerWidth > maxMobileSize ? 15 : window.innerWidth / 25, }, delete: { span: window.innerWidth > maxMobileSize ? 13 : window.innerWidth / 28, }, }, desktop: { info: { strong: window.innerWidth > maxDesktopSize ? 15 : window.innerWidth / 75, p: window.innerWidth > maxDesktopSize ? 12 : window.innerWidth / 95, span: window.innerWidth > maxDesktopSize ? 12 : window.innerWidth / 95, }, price: { strong: window.innerWidth > maxDesktopSize ? 18 : window.innerWidth / 60, span: window.innerWidth > maxDesktopSize ? 13 : window.innerWidth / 95, }, counter: { button: window.innerWidth > maxDesktopSize ? 20 : window.innerWidth / 65, span: window.innerWidth > maxDesktopSize ? 15 : window.innerWidth / 65, }, delete: { span: window.innerWidth > maxDesktopSize ? 15 : window.innerWidth / 75, }, }, }; function BasicTable(props) { const classes = useStyles(); const { list, handleCounter, handleDelete, route, factorInfo } = props; const sum = () => { let total = 0; for (let i = 0; i < list.length; i++) { total += list[i].count * 1; } return total; }; return ( <> {window.innerWidth < 1000 ? ( محصولات قیمت {route === "callback" ? ( تعداد ) : null} {list.map((row, i) => ( ))} {route === "cart" && factorInfo ? ( مبلغ کل {factorInfo.sumPrice} {sum()} محصول ) : null}
) : null} {window.innerWidth > 1000 ? ( محصولات قیمت تعداد {list.map((row, i) => ( ))} {factorInfo ? ( مبلغ کل {factorInfo.sumPrice} {sum()} محصول ) : null}
) : null} ); } const Item = (props) => { const { data, pushToCart, id, route, factorInfo } = props; return ( <> {window.innerWidth < 1000 ? (
{data.product.book.name}
{`نسخه ${ +data.product.productType === 1 ? "الکترونیکی" : "چاپی" } ${data.product.book.name} `}

{`پایه ${grades[data.product.book.gradeId]}`}

همراه با: {data.product.book.items || "کد فعالسازی محتوای الکترونیک"} {route !== "callback" ? (
pushToCart({ productId: data.productId, userId: id, count: -data.count, }) } /> pushToCart({ productId: data.productId, userId: id, count: -data.count, }) } style={{ fontSize: fontSize.mobile.delete.span, color: "#FC120A", cursor: "pointer", }} > حذف
) : null}
{data.product.price * data.count || "1000"} {route !== "callback" ? ( {data.product.price || "100"} قیمت هر واحد ) : null}
{route === "cart" ? (
{data.count}
) : null}
{route === "callback" ? ( {data.count} ) : null}
) : null} {window.innerWidth > 1000 ? (
{data.product.book.name}
{`نسخه ${ +data.product.productType === 1 ? "الکترونیکی" : "چاپی" } ${data.product.book.name} `}

{`پایه ${grades[data.product.book.gradeId]}`}

همراه با: {data.product.book.items || "کد فعالسازی محتوای الکترونیک"}
{data.product.price * data.count || "1000"} تومان قیمت هر عدد {data.product.price || "100"} تومان
{data.count}
handleDelete(data.id)} onClick={() => pushToCart({ productId: data.productId, userId: id, count: -data.count, }) } /> handleDelete(data.id)} onClick={() => pushToCart({ productId: data.productId, userId: id, count: -data.count, }) } style={{ fontSize: fontSize.desktop.delete.span, cursor: "pointer", }} > حذف
) : null} ); }; export default connect( (state) => ({ loading: state.userProduct.loading, info: state.book.info, id: state.user.status.id, factorInfo: state.userFactor.info, }), { pushToCart: userProduct.add } )(BasicTable);