From d24fcdbd7fb0730d00bd07c52bc84ccc12c76da2 Mon Sep 17 00:00:00 2001 From: amir hosein gorji Date: Tue, 10 May 2022 01:48:34 +0430 Subject: [PATCH] =?UTF-8?q?update=2016=20files=20=D9=82=D8=AB=D8=A6=D8=AE?= =?UTF-8?q?=D8=B1=D8=AB=20=D8=B1=D9=87=DB=8C=D8=AB=D8=AE?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- package.json | 4 +- src/Redux/proxy.js | 1 + src/Redux/reducers/public.js | 5 +- src/Redux/reducers/userProduct.js | 2 +- src/views/Cart/Table/index.js | 17 ++-- src/views/Checkout/Table/index.js | 1 + src/views/Home/Footer/index.js | 28 ++++- src/views/Home/index.js | 6 +- src/views/Product/AddToCart/index.js | 7 +- src/views/Product/index.js | 10 +- src/views/Products/List/index.js | 4 +- src/views/Products/Product/index.js | 24 ++--- src/views/QRScan/Input/index.js | 36 +++++++ src/views/QRScan/LastQr/index.js | 1 + src/views/QRScan/Modal/index.js | 147 ++++++++++++++++++++++++--- src/views/QRScan/Modal/index.scss | 54 ++++++++-- src/views/QRScan/index.js | 38 ++++--- 17 files changed, 310 insertions(+), 75 deletions(-) create mode 100644 src/views/QRScan/Input/index.js diff --git a/package.json b/package.json index ddd1f09..3c7e101 100644 --- a/package.json +++ b/package.json @@ -109,7 +109,7 @@ "workbox-webpack-plugin": "5.1.4" }, "scripts": { - "start": "node scripts/start.js", + "start": "node scripts/start.js ", "build": "node scripts/build.js && npm run clean", "test": "node scripts/test.js", "clean": "find ./build -name \"*.map\" -type f -delete" @@ -199,4 +199,4 @@ ] ] } -} +} \ No newline at end of file diff --git a/src/Redux/proxy.js b/src/Redux/proxy.js index 213f44a..a5f2843 100644 --- a/src/Redux/proxy.js +++ b/src/Redux/proxy.js @@ -46,6 +46,7 @@ class Proxy { dispatch = dispatch || (() => {}); dispatch({ type: `${url.split("/")[0]}/loading` }); let response = await fetch(); + switch (response.status) { case 200: dispatch({ type: url, data: response.data.data, params }); diff --git a/src/Redux/reducers/public.js b/src/Redux/reducers/public.js index 1cac6b4..e8ab89c 100644 --- a/src/Redux/reducers/public.js +++ b/src/Redux/reducers/public.js @@ -36,11 +36,12 @@ export default function publicApi(state = initialState, action) { case "public/homePage": let itemsLevel; // if (window.innerWidth > 1000) { - const jadidTarin = data.filter( + + const jadidTarin = data?.filter( (item) => item.title === "کتاب‌های دانوین" ); itemsLevel = - jadidTarin[0] && jadidTarin[0].data + jadidTarin && jadidTarin[0] && jadidTarin[0].data ? jadidTarin[0].data .map((item) => item.book.gradeId * 1) .sort((a, b) => a - b) diff --git a/src/Redux/reducers/userProduct.js b/src/Redux/reducers/userProduct.js index cccb820..0a6b577 100644 --- a/src/Redux/reducers/userProduct.js +++ b/src/Redux/reducers/userProduct.js @@ -18,7 +18,7 @@ export default function userProduct(state = initialState, action) { (item) => item.condition === 2 && item.product.productType === (1 || 3) ); const hasPhysical = - data.filter((item) => item.product.productType === 2).length > 0 + data.filter((item) => item?.product?.productType === 2).length > 0 ? true : false; return { diff --git a/src/views/Cart/Table/index.js b/src/views/Cart/Table/index.js index af7cf20..7f74077 100644 --- a/src/views/Cart/Table/index.js +++ b/src/views/Cart/Table/index.js @@ -182,6 +182,7 @@ function BasicTable(props) { const Item = (props) => { const { data, pushToCart, id, route } = props; + if (!data.product) return null; return ( <> {window.innerWidth < 1000 ? ( @@ -308,25 +309,25 @@ const Item = (props) => { ) : null} {window.innerWidth > 1000 ? ( - +
{data.product.book.name}
{`نسخه ${ - +data.product.productType === 1 ? "الکترونیکی" : "چاپی" - } ${data.product.book.name} `} + +data.product?.productType === 1 ? "الکترونیکی" : "چاپی" + } ${data.product?.book?.name} `} -

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

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

همراه با: - {data.product.book.items || "کد فعالسازی محتوای الکترونیک"} + {data.product?.book?.items || "کد فعالسازی محتوای الکترونیک"}
diff --git a/src/views/Checkout/Table/index.js b/src/views/Checkout/Table/index.js index 45ce6e1..674912d 100644 --- a/src/views/Checkout/Table/index.js +++ b/src/views/Checkout/Table/index.js @@ -143,6 +143,7 @@ function BasicTable(props) { const Item = (props) => { const { data, route } = props; + if (!data.product) return null; return ( <> {window.innerWidth < 1000 ? ( diff --git a/src/views/Home/Footer/index.js b/src/views/Home/Footer/index.js index 29eefe4..22c59f6 100644 --- a/src/views/Home/Footer/index.js +++ b/src/views/Home/Footer/index.js @@ -24,16 +24,38 @@ export default class Footer extends Component {
آدرس

آدرس: تهران، میدان فردوسی، خیابان موسوی، پلاک ۳۰

- {/*

شماره تماس: ۸۸۸۱۴۶۳۷-۰۲۱

*/}
-
- ۸۸۸۱۴۶۳۷ + + {/* */}
Info@Danovin.ir خانه diff --git a/src/views/Home/index.js b/src/views/Home/index.js index 2c8da40..66b3ae3 100644 --- a/src/views/Home/index.js +++ b/src/views/Home/index.js @@ -55,10 +55,10 @@ class Home extends Component { //componentDidupdate = this.componentDidMount(); render() { const { homeData, loading } = this.props; - if (!loading && this.props.homeData.length === 0) + if (!loading && this.props.homeData?.length === 0) return this.componentDidMount(); const mobile = window.innerWidth < 1000; - if (loading && this.props.homeData.length === 0) + if (loading && this.props.homeData?.length === 0) return (
- {homeData.map((item, i) => ( + {homeData?.map((item, i) => ( ))} {window.location.host.indexOf("app") > -1 ? null : } diff --git a/src/views/Product/AddToCart/index.js b/src/views/Product/AddToCart/index.js index 60a71ef..59450e2 100644 --- a/src/views/Product/AddToCart/index.js +++ b/src/views/Product/AddToCart/index.js @@ -64,7 +64,8 @@ function AddToCart(props) { style={{ fontSize: 14, fontWeight: "bold", width: "100%" }} className="d-flex" > - {info.product[productType].name} + {/* {info.product[productType].name} */} + {info.product[0].name}
@@ -118,7 +119,7 @@ function AddToCart(props) { productId: page === "digital" ? info.product[0].id - : info.product[1].id, + : info.product[0].id, userId: props.id, count: 1, }); @@ -127,7 +128,7 @@ function AddToCart(props) { localStorage.setItem("afterLogin", window.location.pathname); localStorage.setItem( "pushToCart", - page === "digital" ? info.product[0].id : info.product[1].id + page === "digital" ? info.product[0].id : info.product[0].id ); Navigate({ path: "/auth" }); } diff --git a/src/views/Product/index.js b/src/views/Product/index.js index 2a1b803..816f40c 100644 --- a/src/views/Product/index.js +++ b/src/views/Product/index.js @@ -80,7 +80,7 @@ function Addbutton({ page, info, pushToCart, userId }) { if (proxy.status()) pushToCart({ productId: - page === "digital" ? info.product[0].id : info.product[1].id, + page === "digital" ? info.product[0].id : info.product[0].id, userId, count: 1, }); @@ -89,7 +89,7 @@ function Addbutton({ page, info, pushToCart, userId }) { localStorage.setItem("afterLogin", window.location.pathname); localStorage.setItem( "pushToCart", - page === "digital" ? info.product[0].id : info.product[1].id + page === "digital" ? info.product[0].id : info.product[0].id ); Navigate({ path: "/auth" }); } @@ -137,7 +137,7 @@ class Product extends Component { name={ page === "digital" ? info.product[0].name - : info.product[1].name + : info.product[0].name } />
@@ -155,7 +155,7 @@ class Product extends Component { price={ page === "digital" ? info.product[0].price - : info.product[1].price + : info.product[0].price } // off={product.off} page={page} @@ -222,7 +222,7 @@ class Product extends Component {

{page === "digital" ? info.product[0].price - : info.product[1].price}{" "} + : info.product[0].price}{" "} تومان

diff --git a/src/views/Products/List/index.js b/src/views/Products/List/index.js index 4621756..e5e62ee 100644 --- a/src/views/Products/List/index.js +++ b/src/views/Products/List/index.js @@ -9,7 +9,7 @@ import "./index.scss"; class List extends React.Component { componentDidMount() { - if (this.props.list.length === 0) this.props.getList(); + if (this.props.list?.length === 0) this.props.getList(); } render() { @@ -18,7 +18,7 @@ class List extends React.Component { return window.innerWidth > 1000 ? (
{!loading ? ( - filterResult.length > 0 ? ( + filterResult?.length > 0 ? ( (Array.isArray(filterResult) ? filterResult : []).map((item, i) => ( )) diff --git a/src/views/Products/Product/index.js b/src/views/Products/Product/index.js index 079a878..5366120 100644 --- a/src/views/Products/Product/index.js +++ b/src/views/Products/Product/index.js @@ -67,7 +67,7 @@ function Product(props) { className="mobile-products-product__links--physical d-flex justify-content-between align-items-center" >

نسخه چاپی

- {product.product[1].price} تومان + {product.product[0].price} تومان
{ if (proxy.status()) props.pushToCart({ - productId: product.product[1].id, + productId: product.product[0].id, userId: props.id, count: 1, }); @@ -84,7 +84,7 @@ function Product(props) { "afterLogin", window.location.pathname ); - localStorage.setItem("pushToCart", product.product[1].id); + localStorage.setItem("pushToCart", product.product[0].id); Navigate({ path: "/auth" }); } }} @@ -92,13 +92,13 @@ function Product(props) {
-
+ {/*

الکترونیکی

- {/* {product.product[0].price} تومان */} + {/* {product.product[0].price} تومان به زودی
@@ -116,7 +116,7 @@ function Product(props) { >
-
+
*/}
) : null} @@ -143,7 +143,7 @@ function Product(props) { >

نسخه چاپی

- {product.product[1].price} تومان + {product.product[0].price} تومان
{ if (proxy.status()) props.pushToCart({ - productId: product.product[1].id, + productId: product.product[0].id, userId: props.id, count: 1, }); else { toast.info("جهت ادامه فرآیند خرید وارد حساب خود شوید"); localStorage.setItem("afterLogin", window.location.pathname); - localStorage.setItem("pushToCart", product.product[1].id); + localStorage.setItem("pushToCart", product.product[0].id); Navigate({ path: "/auth" }); } }} @@ -167,14 +167,14 @@ function Product(props) {
-
+ {/*

نسخه الکترونیک

- {/* {product.product[0].price} تومان */} + {/* {product.product[0].price} تومان به زودی
@@ -192,7 +192,7 @@ function Product(props) { >
-
+
*/} ) : null} diff --git a/src/views/QRScan/Input/index.js b/src/views/QRScan/Input/index.js new file mode 100644 index 0000000..d8c164d --- /dev/null +++ b/src/views/QRScan/Input/index.js @@ -0,0 +1,36 @@ +import React, { useState } from "react"; +import TextField from "@material-ui/core/TextField"; + +export default function FormPropsTextFields(props) { + const [value, setValue] = useState(props.defaultValue[props.name]); + + const { parent, maxLength, onInput, variant, required } = props; + return ( +
+
+ { + parent.onChange(e.target.name, e.target.value); + }} + // defaultValue={defaultValue[props.name] || ""} + value={value || ""} + required={required} + inputProps={{ maxLength }} + onInput={(e) => setValue(onInput(e.target.value))} + /> +
+
+ ); +} + +FormPropsTextFields.defaultProps = { + align: "right", + maxLength: "", + inputMode: "numeric", + defaultValue: "", +}; diff --git a/src/views/QRScan/LastQr/index.js b/src/views/QRScan/LastQr/index.js index 3615974..47e8908 100644 --- a/src/views/QRScan/LastQr/index.js +++ b/src/views/QRScan/LastQr/index.js @@ -4,6 +4,7 @@ import { Link } from "react-router-dom"; import "./index.scss"; const grades = [ + "0", "اول", "دوم", "سوم", diff --git a/src/views/QRScan/Modal/index.js b/src/views/QRScan/Modal/index.js index ef41813..d9a7648 100644 --- a/src/views/QRScan/Modal/index.js +++ b/src/views/QRScan/Modal/index.js @@ -1,8 +1,8 @@ import React, { Component } from "react"; import { Link } from "react-router-dom"; - +import onInput from "~/util/onInput"; +import Input from "../Input/index"; import "./index.scss"; - const maxMobileSize = 550; const fontSize = { @@ -11,9 +11,21 @@ const fontSize = { a: window.innerWidth > maxMobileSize ? 20 : window.innerWidth / 20, }, }; -export default class QRModal extends Component { +class QRModal extends Component { + state = { pageNumber: "" }; + onChange(k, v) { + this.setState({ [k]: v }); + } render() { - const { tail, parent } = this.props; + let { tail, parent, myList } = this.props; + let { pageNumber } = this.state; + let hasZ10 = false; + let hasO4 = false; + if (tail === "Zist10-147") { + hasO4 = myList.find((item) => +item.product.bookId === 10); + hasZ10 = myList.find((item) => +item.product.bookId === 6); + } + return ( <> {window.innerWidth < 1000 ? ( @@ -21,27 +33,130 @@ export default class QRModal extends Component { اسکن کد QR موفقیت آمیز بود. - - {tail} - - + + {hasO4 ? ( + <> +
+
کتاب علوم چهارم
+ + + لطفا شماره صفحه را وارد نمایید + +
+ +
+
+
+ + {hasZ10 ? "علوم چهارم" : "تایید"} + + {hasZ10 ? ( + + زیست دهم + + ) : null} + +
+ + ) : ( + <> + + {tail} + + + + )} ) : (
اسکن کد QR موفقیت آمیز بود. - - {tail} - - + {hasO4 ? ( + <> +
+
کتاب علوم چهارم
+
+ + لطفا شماره صفحه را وارد نمایید + + +
+
+
+ + {hasZ10 ? "علوم چهارم" : "تایید"} + + {hasZ10 ? ( + + زیست دهم + + ) : null} + +
+ + ) : ( + <> + + {tail} + + + + )}
)} ); } } +export default QRModal; +// export default connect( +// (state) => ({ myList: state.userProduct.myList || [] }), +// { getMyList: userProduct.myList } +// )(QRModal); diff --git a/src/views/QRScan/Modal/index.scss b/src/views/QRScan/Modal/index.scss index 2b0aa12..af0c501 100644 --- a/src/views/QRScan/Modal/index.scss +++ b/src/views/QRScan/Modal/index.scss @@ -12,7 +12,7 @@ font-family: numeralLight; color: white; } - a { + a.ok { text-decoration: none; width: 50%; margin: 25px auto; @@ -24,7 +24,8 @@ font-family: numeralLight; border-radius: 25px; } - button { + button, + .button { text-decoration: none; width: 30%; min-width: 100px; @@ -53,9 +54,9 @@ font-family: numeralLight; color: white; } - a { + a.ok { text-decoration: none; - width: 50%; + width: 40%; margin: 25px auto; background-color: #00cc69; border: 2px solid white; @@ -65,11 +66,12 @@ font-family: numeralLight; border-radius: 25px; } - button { + button, + .button { text-decoration: none; width: 25%; max-width: 100px; - margin: 15px auto; + margin: 15px; background-color: #cc001b; border: 2px solid white; padding: 10px 0px; @@ -80,6 +82,32 @@ } } +.o4input { + background-color: #ffffff88; + width: 70px; + border: 0px; + border-radius: 5px; +} +.o4 { + direction: rtl; + text-decoration: none; + width: 40%; + margin: 25px auto; + background-color: #175b6d; + border: 2px solid white; + padding: 20px 0px; + text-align: center; + color: white; + font-family: numeralLight; + border-radius: 25px; +} +.o4input input:focus-visible { + border: 0px; + outline: none; +} +.button { + background-color: #00cc69 !important; +} @keyframes qrModal { 0% { left: -100vw; @@ -90,3 +118,17 @@ top: 0px; } } + +.MuiTextField-root { + border: 0; + margin: 5px; + display: flex; + font-family: numeralLight; +} +.MuiTextField-root fieldset { + border: 0; +} +.MuiTextField-root input { + direction: rtl; + text-align: right; +} diff --git a/src/views/QRScan/index.js b/src/views/QRScan/index.js index 540725d..81d07bc 100644 --- a/src/views/QRScan/index.js +++ b/src/views/QRScan/index.js @@ -9,7 +9,7 @@ import ReplayIcon from "@material-ui/icons/Replay"; import FlipCameraIosIcon from "@material-ui/icons/FlipCameraIos"; import { connect } from "react-redux"; -import { qr } from "~/Redux/actions"; +import { qr, userProduct } from "~/Redux/actions"; import sciense_6 from "../../assets/images/sciense-6.png"; @@ -28,17 +28,19 @@ class QRScan extends Component { state = { value: null, facingMode: 0, - tail: null, + tail: null, //"Zist10-146", }; - + componentDidMount() { + console.log(this.props.myList); + if (!this.props.myList) this.props.getMyList({}); + } async componentDidUpdate() { if (this.state.value) { let tail = this.state.value.slice( this.state.value.lastIndexOf("/") + 1, this.state.value.length ); - this.props.info({ tail: tail }); - console.log(this.props.list, tail); + // if (tail.length) this.props.info({ tail: tail }); this.setState({ value: null, tail: tail }); } } @@ -77,12 +79,16 @@ class QRScan extends Component { > - ) : ( + ) : this.state.tail === null ? ( - )} + ) : null} {this.state.tail === null ? null : ( - + )} @@ -124,7 +130,11 @@ class QRScan extends Component { )} {this.state.tail === null ? null : ( - + )} {localStorage.getItem("latestQr") ? (
@@ -145,9 +155,13 @@ class QRScan extends Component { } } -export default connect((state) => ({ list: state.qr.list }), { info: qr.info })( - QRScan -); +export default connect( + (state) => ({ list: state.qr.list, myList: state.userProduct.myList }), + { + getMyList: userProduct.myList, + info: qr.info, + } +)(QRScan); QRScan.defaultProps = { data: [