From 35cde1c1214ae33cd9be808ae11f2e866a0408c5 Mon Sep 17 00:00:00 2001 From: Reza_ashrafi Date: Tue, 12 Jul 2022 15:23:27 +0430 Subject: [PATCH] update 5 files --- src/redux/actions/userFactor.js | 4 + src/redux/reducers/userFactor.js | 8 ++ src/views/Order/components/Book.js | 26 ++-- src/views/Order/index.js | 189 ++++++++++++--------------- src/views/Orders/components/Order.js | 19 ++- 5 files changed, 128 insertions(+), 118 deletions(-) diff --git a/src/redux/actions/userFactor.js b/src/redux/actions/userFactor.js index 83e5ad4..2c7920a 100644 --- a/src/redux/actions/userFactor.js +++ b/src/redux/actions/userFactor.js @@ -27,6 +27,10 @@ const userFactor = { async (dispatch) => await proxy.get("userFactor/fullList", data, { dispatch }), + selectOrder: + (data = {}) => + (dispatch) => + dispatch({ type: "userFactor/selectOrder", data }), //vod vodPayment: (data1 = {}, data2 = {}) => diff --git a/src/redux/reducers/userFactor.js b/src/redux/reducers/userFactor.js index e64e6f8..a80a1d0 100644 --- a/src/redux/reducers/userFactor.js +++ b/src/redux/reducers/userFactor.js @@ -8,6 +8,7 @@ const initialState = { checkEmpty: false, isVerified: null, fullList: [], + selectedOrder: null, }; export default function userFactor(state = initialState, action) { @@ -32,6 +33,13 @@ export default function userFactor(state = initialState, action) { fullList: data, error: null, }; + case "userFactor/selectOrder": + return { + ...state, + loading: false, + selectedOrder: data, + error: null, + }; case "userFactor/info": return { ...state, loading: false, info: data, error: null }; case "userFactor/add": diff --git a/src/views/Order/components/Book.js b/src/views/Order/components/Book.js index c7b381f..2d2c22e 100644 --- a/src/views/Order/components/Book.js +++ b/src/views/Order/components/Book.js @@ -1,35 +1,37 @@ import React from "react"; -import _ from "lodash"; +import { connect } from "react-redux"; -export default function Book({ book }) { +function Book({ book, grades }) { return (
- {window.t("علوم اجتماعی")} + {book?.product?.book?.name || " "} - {window.t("پایه دوم")} - - - {window.t("نسخه دیجیتال")} + {"پایه" + " " + grades[book?.product?.book?.gradeId]}
- 1 + {book?.product?.count}
- 126.000 {window.t("تومان")} + {book?.product?.price + " " + "تومان"}
); } + +const mapStateToProps = (state) => ({ + grades: state.publicApi.grades, +}); + +export default connect(mapStateToProps)(Book); diff --git a/src/views/Order/index.js b/src/views/Order/index.js index 7b7bdd2..eec1e51 100644 --- a/src/views/Order/index.js +++ b/src/views/Order/index.js @@ -2,8 +2,10 @@ import React, { useEffect } from "react"; import Book from "./components/Book"; import { connect } from "react-redux"; import { publicApi } from "../../redux/actions"; +import moment from "jalali-moment"; + +//assets import b1Image from "./assets/b1.png"; -import _ from "lodash"; const colors = { 1: "#FFF700", @@ -25,53 +27,65 @@ function OrderDetails({ order, setHeaderOptions, headerOptions, isMobile }) { setHeaderOptions(headerOptions); } }, []); - + return (
- - {_.join([window.t("شماره سفارش:"), order.number], " ")} - -
- - {status[order.status]} - -
-
-
-
- - {window.t("آدرس تحویل")}: - - - {order.address} - -
-
-
- - {window.t("مشخصات تحویل گیرنده:")} + {order?.transactionId ? ( + + {"شماره سفارش:" + " " + order?.transactionId} - - {order.name} - -
-
+ ) : null} + {order?.condition ? ( +
+ + {status[order?.condition]} + +
+
+ ) : null} +
+ {order?.recieverAddress ? ( +
- {window.t("شماره موبایل:")} + {window.t("آدرس تحویل")}: - {order.cellphone} + {order?.recieverAddress}
+ ) : null} +
+ {order?.recieverName ? ( +
+ + {window.t("مشخصات تحویل گیرنده:")} + + + {order.recieverName} + +
+ ) : null} + {order?.recieverPhone ? ( +
+ + {window.t("شماره موبایل:")} + + + {order.recieverPhone} + +
+ ) : null}
- - {_.join([window.t("کد تحویل:"), order.receiveCode], " ")} - + {order?.recieverPostalCode ? ( + + {"کد تحویل" + " " + order?.recieverPostalCode} + + ) : null}

{window.t( "این کد را پس از دریافت کالا، به مامور ارسال دانوین اعلام فرمایید" @@ -79,62 +93,52 @@ function OrderDetails({ order, setHeaderOptions, headerOptions, isMobile }) {

- {order.items.map((item, index) => ( - + {order?.userProducts?.map((product, index) => ( + ))}
-
- - {window.t("مبلغ سبد خرید:")} - - - {_.join([order.shoppingCardPrice, window.t("تومان")], " ")} - -
-
- - {window.t("تخفیف:")} - - - {_.join([order.discountPrice, window.t("تومان")], " ")} - -
+ {order?.sumPrice ? ( +
+ + {window.t("مبلغ سبد خرید:")} + + + {order?.sumPrice + " " + "تومان"} + +
+ ) : null}
-
- - {window.t("هزینه ارسال کالا:")} - - - {_.join([order.sendPrice, window.t("تومان")], " ")} - -
-
- - {window.t("جمع هزینه پرداختی:")} - - - {_.join([order.totalPrice, window.t("تومان")], " ")} - -
+ {order?.transportPrice ? ( +
+ + {window.t("هزینه ارسال کالا:")} + + + {order?.transportPrice + " " + "تومان"} + +
+ ) : null} + {order?.payPrice ? ( +
+ + {window.t("جمع هزینه پرداختی:")} + + + {order?.payPrice + " " + "تومان"} + +
+ ) : null}
-
- - {window.t("نحوه پرداخت:")} - - - {order.payMethod} - -
{" "} {window.t("شماره تراکنش:")} - {order.transactionNumber} + {order?.transactionId}
@@ -144,7 +148,7 @@ function OrderDetails({ order, setHeaderOptions, headerOptions, isMobile }) { {window.t("تاریخ تحویل:")}
- {order.date} + {moment(order?.payedAt)?.format("jYYYY/jMM/jDD")}
@@ -154,6 +158,7 @@ function OrderDetails({ order, setHeaderOptions, headerOptions, isMobile }) { const mapStateToProps = (state) => ({ isMobile: state.config.device === "mobile", + order: state.userFactor.selectedOrder }); const mapDispatchToProps = { @@ -161,25 +166,3 @@ const mapDispatchToProps = { }; export default connect(mapStateToProps, mapDispatchToProps)(OrderDetails); - -OrderDetails.defaultProps = { - order: { - number: "535353523653", - receiveCode: "300031", - status: 2, - items: [b1Image, b1Image], - date: "1400/1/11", - cost: "1.240.000", - address: window.t( - "تهران خیابان انقلاب حدفاصل ابوریحان و فلسطین بن بست سروش پلاک 2 واحد 12 شرقی" - ), - name: window.t("هومن عابدی"), - cellphone: "09121234568", - shoppingCardPrice: "981.000", - discountPrice: "12.000", - sendPrice: "18.000", - totalPrice: "18.000", - payMethod: window.t("حضوری"), - transactionNumber: " BS3194DNB98312", - }, -}; diff --git a/src/views/Orders/components/Order.js b/src/views/Orders/components/Order.js index 1411bc8..18f24ac 100644 --- a/src/views/Orders/components/Order.js +++ b/src/views/Orders/components/Order.js @@ -2,6 +2,7 @@ import React from "react"; import { connect } from "react-redux"; import { Link } from "react-router-dom"; import moment from "jalali-moment"; +import { userFactor } from "../../../redux/actions"; //assets import leftArrowIcon from "../../../assets/icons/dropdown-blue.svg"; @@ -20,7 +21,7 @@ const status = { 2: window.t("ارسال شده"), }; -function Order({ order, setDashboardPage, isDashboard }) { +function Order({ order, setDashboardPage, isDashboard, selectOrder }) { return (
@@ -86,7 +87,15 @@ function Order({ order, setDashboardPage, isDashboard }) { (isDashboard ? setDashboardPage("order") : {})} + onClick={() => { + if (isDashboard) { + selectOrder(order); + setDashboardPage("order"); + } else { + selectOrder(order); + return; + } + }} > {window.t("جزئیات سفارش")} ({ isMobile: state.config.device === "mobile", }); -export default connect(mapStateToProps)(Order); +const mapDispatchToProps = { + selectOrder: userFactor.selectOrder, +}; + +export default connect(mapStateToProps, mapDispatchToProps)(Order);