import React, { Component } from "react"; import { connect } from "react-redux"; import { transport, userFactor } from "~/Redux/actions"; import Navbar from "../Home/Navbar/index"; import Footer from "../Home/Footer/index"; import Table from "./Table/index"; import DiscoutCode from "./Discount/index"; import DeliveryMethod from "./DeliveryMethod/index"; import Factor from "./Factor/index"; import Loader from "~/components/Loader/index"; import { Link, useHistory } from "react-router-dom"; import "./index.scss"; function Navigate({ path }) { let history = useHistory(); return <>{history.push(path)}>; } const maxDesktopSize = 1250; const maxMobileSize = 550; const fontSize = { desktop: { h1: window.innerWidth > maxDesktopSize ? 30 : window.innerWidth / 40, th: window.innerWidth > maxDesktopSize ? 16 : window.innerWidth / 80, h2: window.innerWidth > maxDesktopSize ? 16 : window.innerWidth / 55, h3: window.innerWidth > maxDesktopSize ? 12 : window.innerWidth / 90, strong: window.innerWidth > maxDesktopSize ? 12 : window.innerWidth / 90, span: window.innerWidth > maxDesktopSize ? 10 : window.innerWidth / 95, p: window.innerWidth > maxMobileSize ? 13 : window.innerWidth / 90, }, mobile: { h1: window.innerWidth > maxMobileSize ? 20 : window.innerWidth / 13, h2: window.innerWidth > maxMobileSize ? 16 : window.innerWidth / 24, h3: window.innerWidth > maxMobileSize ? 12 : window.innerWidth / 30, strong: window.innerWidth > maxMobileSize ? 12 : window.innerWidth / 30, span: window.innerWidth > maxMobileSize ? 10 : window.innerWidth / 34, p: window.innerWidth > maxMobileSize ? 12 : window.innerWidth / 32, input: window.innerWidth > maxMobileSize ? 16 : window.innerWidth / 20, }, }; class Cart extends Component { state = { selectedDelivery: { name: "", price: 0 }, discount: 0, totalPrice: null, list: this.props.list, controlFactorInfoRepeat: true, }; componentDidUpdate(prevProps, prevState) { if (window.location.search) if (!window.location.search.includes("NOK") && !window.location.hash) { let Authority = window.location.search .slice(1) .split("&")[0] .split("=")[1]; this.props.getVerify({ Authority }); window.location.hash = "verified"; } // if (this.props.factorInfo === null && !this.controlFactorInfoRepeat) { // this.props.getFactorInfo({}); // this.controlFactorInfoRepeat = true; // } // if (this.props.list.length > 0) { // let wantedId; //should be zero // for (let item of this.props.list) { // if (item.condition === 2) { // wantedId = item.id; // break; // } // } // if (this.props.list.length !== 1) { // // this.props.getInfo({ id: wantedId }); // } // } else { // // this.props.getFactorInfo({}); // } } componentDidMount() { localStorage.removeItem("afterLogin"); window.scrollTo(0, 0); this.props.getTransportList(); this.props.getFactorInfo({}); } handleCounter = (type, id) => { if (type === "increase") { this.setState((prevState) => ({ list: prevState.list.map((item) => item.id === id ? { ...item, number: item.number + 1 } : item ), })); } else { this.setState((prevState) => ({ list: prevState.list.map((item) => item.id === id ? { ...item, number: item.number - 1 } : item ), })); } }; handleDelete = (id) => { let list = this.state.list.filter((item) => item.id !== id); this.setState({ list: list, }); }; totalPrice = () => { let total = 0; for (let i = 0; i < this.state.list.length; i++) { total += this.state.list[i].price * this.state.list[i].number; } return total - this.state.discount + this.state.selectedDelivery.price; }; render() { const { list, payPrice, payMethods, factorInfo } = this.props; if (!factorInfo || list.length === 0) return (
{window.t("با توجه به شرایط یکی از دو گزینه زیر را انتخاب کنید")}
{window.t( "با توجه به شرایط یکی از دو گزینه زیر را انتخاب کنید" )}{" "}
با توجه به شرایط یکی از دو گزینه زیر را انتخاب کنید")}