|
@@ -1,4 +1,4 @@
|
|
-import { actionOrdersFind, urlUpload} from "../reducers";
|
|
|
|
|
|
+import { actionOrdersFind, urlUpload, actionOrderAdd, actionOrderAddOrder} from "../reducers";
|
|
import { connect } from "react-redux";
|
|
import { connect } from "react-redux";
|
|
import { useEffect, useState, useRef } from "react";
|
|
import { useEffect, useState, useRef } from "react";
|
|
import {BrowserRouter as Router, Route, Link, Switch, Redirect, useHistory} from 'react-router-dom';
|
|
import {BrowserRouter as Router, Route, Link, Switch, Redirect, useHistory} from 'react-router-dom';
|
|
@@ -23,9 +23,26 @@ const OneOrderGood = ({img, name, count, keyprop, price}) => {
|
|
|
|
|
|
|
|
|
|
|
|
|
|
-const OneOrder = ({price, total, _id, img, isAdmin, keyprop, goodsArr = [],count, createdAt}) => {
|
|
|
|
|
|
+const OneOrder = ({price, total, _id, owner, img, onClick, isAdmin, keyprop, goodsArr = [],count, createdAt}) => {
|
|
const date = new Date(+createdAt);
|
|
const date = new Date(+createdAt);
|
|
const history = useHistory();
|
|
const history = useHistory();
|
|
|
|
+
|
|
|
|
+
|
|
|
|
+
|
|
|
|
+
|
|
|
|
+
|
|
|
|
+ function goodsObj(arr) {
|
|
|
|
+ let oneObj = {};
|
|
|
|
+ for(let i = 0; i < arr.length; i++) {
|
|
|
|
+ oneObj[arr[i].good._id] = arr[i];
|
|
|
|
+ }
|
|
|
|
+
|
|
|
|
+ return oneObj
|
|
|
|
+ }
|
|
|
|
+
|
|
|
|
+
|
|
|
|
+
|
|
|
|
+
|
|
return(
|
|
return(
|
|
|
|
|
|
<div key = {keyprop} className = "oneOrder">
|
|
<div key = {keyprop} className = "oneOrder">
|
|
@@ -35,8 +52,8 @@ const OneOrder = ({price, total, _id, img, isAdmin, keyprop, goodsArr = [],count
|
|
</h5>
|
|
</h5>
|
|
<div key = {Math.random()} className = "oneOrderInner">
|
|
<div key = {Math.random()} className = "oneOrderInner">
|
|
<div className = "oneOrderGoods">
|
|
<div className = "oneOrderGoods">
|
|
- {(!goodsArr || goodsArr.length == 0) && <div key = {`${_id}${Math.random}`}>Замовлення скасовано</div>}
|
|
|
|
- {goodsArr && goodsArr.map((good) => {
|
|
|
|
|
|
+ {(!goodsArr || goodsArr.length == 0 || !total) && <div key = {`${_id}${Math.random}`}>Замовлення скасовано</div>}
|
|
|
|
+ {goodsArr && total > 0 && goodsArr.map((good) => {
|
|
if(good.good == null || good.good.name == null) {
|
|
if(good.good == null || good.good.name == null) {
|
|
return(
|
|
return(
|
|
<div key = {`${Math.random()}`}>Товар відмінено</div>
|
|
<div key = {`${Math.random()}`}>Товар відмінено</div>
|
|
@@ -44,6 +61,7 @@ const OneOrder = ({price, total, _id, img, isAdmin, keyprop, goodsArr = [],count
|
|
} else {
|
|
} else {
|
|
|
|
|
|
return(
|
|
return(
|
|
|
|
+
|
|
|
|
|
|
<OneOrderGood key = {Math.random()} name = {good.good ? good.good.name : "товар"} count = {good.count} price = {good.good ? good.good.price : ""} img = {good.good && good.good.images && good.good.images[0].url ? `${good.good.images[0].url}` : `https://images.ua.prom.st/2259265311_korobka-syurpriz-dlya.jpg`}/>
|
|
<OneOrderGood key = {Math.random()} name = {good.good ? good.good.name : "товар"} count = {good.count} price = {good.good ? good.good.price : ""} img = {good.good && good.good.images && good.good.images[0].url ? `${good.good.images[0].url}` : `https://images.ua.prom.st/2259265311_korobka-syurpriz-dlya.jpg`}/>
|
|
|
|
|
|
@@ -53,7 +71,11 @@ const OneOrder = ({price, total, _id, img, isAdmin, keyprop, goodsArr = [],count
|
|
})}
|
|
})}
|
|
</div>
|
|
</div>
|
|
<div> {<h5>{(total && total > 0 && total != 0) ? `Сума замовлення: ${total}грн` : ""}</h5>}
|
|
<div> {<h5>{(total && total > 0 && total != 0) ? `Сума замовлення: ${total}грн` : ""}</h5>}
|
|
- {isAdmin && goodsArr && total > 0 && <button onClick = {() => history.push(`/orderPage/${_id}`)}>Редагувати</button>}
|
|
|
|
|
|
+ {isAdmin && goodsArr && total > 0 && <button onClick = {() => {
|
|
|
|
+ let newObj = goodsObj(goodsArr)
|
|
|
|
+ {onClick(_id, newObj, total, owner)}
|
|
|
|
+ history.push(`/orderPage/${_id}`) }}>
|
|
|
|
+ Редагувати</button>}
|
|
|
|
|
|
</div>
|
|
</div>
|
|
</div>
|
|
</div>
|
|
@@ -67,14 +89,14 @@ const OneOrder = ({price, total, _id, img, isAdmin, keyprop, goodsArr = [],count
|
|
|
|
|
|
|
|
|
|
|
|
|
|
-const OrdersList = ({orders = [], status, ordersFind, owner, isAdmin, match:{params:{_id}}}) => {
|
|
|
|
|
|
+const OrdersList = ({orders = [], onOrder, status, ordersFind, owner, isAdmin, match:{params:{_id}}}) => {
|
|
const history = useHistory();
|
|
const history = useHistory();
|
|
|
|
|
|
function ordersOnPage(arr) {
|
|
function ordersOnPage(arr) {
|
|
let newArr = arr.slice();
|
|
let newArr = arr.slice();
|
|
newArr.reverse()
|
|
newArr.reverse()
|
|
- console.log(newArr)
|
|
|
|
- return newArr.map((order) => <OneOrder isAdmin = {isAdmin} key = {order._id} _id = {order._id} createdAt = {order.createdAt} goodsArr = {order.orderGoods} total = {order.total}/>)}
|
|
|
|
|
|
+ //console.log(newArr)
|
|
|
|
+ return newArr.map((order) => <OneOrder owner = {order.owner._id} onClick = {onOrder} isAdmin = {isAdmin} key = {order._id} _id = {order._id} createdAt = {order.createdAt} goodsArr = {order.orderGoods} total = {order.total}/>)}
|
|
|
|
|
|
|
|
|
|
useEffect(() => {
|
|
useEffect(() => {
|
|
@@ -140,8 +162,8 @@ const mapStateToProps = state => ({
|
|
|
|
|
|
|
|
|
|
const mapDispatchToProps = dispatch => bindActionCreators({
|
|
const mapDispatchToProps = dispatch => bindActionCreators({
|
|
-
|
|
|
|
- ordersFind: actionOrdersFind
|
|
|
|
|
|
+ onOrder: actionOrderAddOrder,
|
|
|
|
+ ordersFind: actionOrdersFind
|
|
}, dispatch);
|
|
}, dispatch);
|
|
|
|
|
|
const COrdersList = connect(mapStateToProps, mapDispatchToProps)(OrdersList);
|
|
const COrdersList = connect(mapStateToProps, mapDispatchToProps)(OrdersList);
|