|
@@ -0,0 +1,146 @@
|
|
|
|
+import { actionOrdersFind, urlUpload} from "../reducers";
|
|
|
|
+import { connect } from "react-redux";
|
|
|
|
+import { useEffect, useState, useRef } from "react";
|
|
|
|
+import {BrowserRouter as Router, Route, Link, Switch, Redirect, useHistory} from 'react-router-dom';
|
|
|
|
+import {createStore, combineReducers, applyMiddleware, bindActionCreators} from 'redux';
|
|
|
|
+
|
|
|
|
+
|
|
|
|
+const OneOrderGood = ({img, name, count, price}) => {
|
|
|
|
+
|
|
|
|
+ return(
|
|
|
|
+ <div className = "oneOrderGood">
|
|
|
|
+ <div className = "goodInner">
|
|
|
|
+ <img src={img ? `${urlUpload}/${img}`: 'https://pngicon.ru/file/uploads/picca-1.png'} />
|
|
|
|
+ <p>{name}</p>
|
|
|
|
+ <span>{price}грн</span>
|
|
|
|
+ </div>
|
|
|
|
+ <div>
|
|
|
|
+ <h5>{count}шт</h5>
|
|
|
|
+ </div>
|
|
|
|
+ </div>
|
|
|
|
+ )
|
|
|
|
+}
|
|
|
|
+
|
|
|
|
+
|
|
|
|
+
|
|
|
|
+const OneOrder = ({price, total, _id, img, goodsArr = [],count, createdAt}) => {
|
|
|
|
+ const date = new Date(+createdAt);
|
|
|
|
+
|
|
|
|
+ return(
|
|
|
|
+
|
|
|
|
+ <div key = {_id} className = "oneOrder">
|
|
|
|
+ <div>
|
|
|
|
+ <h5>
|
|
|
|
+ Створено: {`${date.getDate()}. ${date.getMonth() + 1}. ${date.getFullYear()} о ${date.getHours()}: ${date.getMinutes()}: ${date.getSeconds()} `}
|
|
|
|
+ </h5>
|
|
|
|
+ <div className = "oneOrderInner">
|
|
|
|
+ <div className = "oneOrderGoods">
|
|
|
|
+ {(!goodsArr || goodsArr.length == 0) && <div>Замовлення скасовано</div>}
|
|
|
|
+ {goodsArr && goodsArr.map((good) => {
|
|
|
|
+ if(good.good == null || good.good.name == null) {
|
|
|
|
+ return(
|
|
|
|
+ <div>Товар відмінено</div>
|
|
|
|
+ )
|
|
|
|
+ } else {
|
|
|
|
+
|
|
|
|
+ return(
|
|
|
|
+ <>
|
|
|
|
+ <OneOrderGood name = {good.good ? good.good.name : "товар"} count = {good.count} price = {good.good ? good.good.price : "0"} 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`}/>
|
|
|
|
+
|
|
|
|
+ </>
|
|
|
|
+ )
|
|
|
|
+ }
|
|
|
|
+ })}
|
|
|
|
+ </div>
|
|
|
|
+ <div> {<h5>{(total && total > 0) ? `Сума замовлення: ${total}грн` : ""}</h5>}</div>
|
|
|
|
+ </div>
|
|
|
|
+
|
|
|
|
+
|
|
|
|
+ </div>
|
|
|
|
+
|
|
|
|
+ </div>
|
|
|
|
+ )
|
|
|
|
+}
|
|
|
|
+
|
|
|
|
+
|
|
|
|
+
|
|
|
|
+const OrdersList = ({orders = [], status, ordersFind, owner, isAdmin, match:{params:{_id}}}) => {
|
|
|
|
+ const history = useHistory();
|
|
|
|
+
|
|
|
|
+ function ordersOnPage(arr) {
|
|
|
|
+ let newArr = arr.slice();
|
|
|
|
+ newArr.reverse()
|
|
|
|
+
|
|
|
|
+ return newArr.map((order) => <OneOrder _id = {order._id} createdAt = {order.createdAt} goodsArr = {order.orderGoods} total = {order.total}/>)}
|
|
|
|
+
|
|
|
|
+
|
|
|
|
+ useEffect(() => {
|
|
|
|
+ if(history.location.pathname.includes(`/profile/`)) {
|
|
|
|
+
|
|
|
|
+ ordersFind(`${owner.id}`) ;
|
|
|
|
+ }
|
|
|
|
+ if(isAdmin) {
|
|
|
|
+ ordersFind(`${_id}`) ;
|
|
|
|
+ }
|
|
|
|
+ },[])
|
|
|
|
+
|
|
|
|
+
|
|
|
|
+ return(
|
|
|
|
+ <>
|
|
|
|
+ { (status == "RESOLVED" && orders) &&
|
|
|
|
+
|
|
|
|
+ <div className = "ordersList">
|
|
|
|
+ <h4>Попередні замовлення</h4>
|
|
|
|
+ {orders.length == 0 &&
|
|
|
|
+ <div className = "noOrders" onClick = {() => history.push("/catalog/")}>
|
|
|
|
+ <p>Ще немає жодного замовлення. Саме час це змінити</p>
|
|
|
|
+ <button>В каталог</button></div>}
|
|
|
|
+ {ordersOnPage(orders)}
|
|
|
|
+ {/* {orders.reverse().map((order) => <OneOrder _id = {order._id} createdAt = {order.createdAt} goodsArr = {order.orderGoods} total = {order.total}/>)} */}
|
|
|
|
+
|
|
|
|
+ </div>
|
|
|
|
+ }
|
|
|
|
+ </>
|
|
|
|
+ )
|
|
|
|
+}
|
|
|
|
+
|
|
|
|
+
|
|
|
|
+
|
|
|
|
+const mapStateToProps = state => ({
|
|
|
|
+ state: state,
|
|
|
|
+
|
|
|
|
+ orders: state.promiseRed && state.promiseRed.ordersFind &&
|
|
|
|
+ state.promiseRed.ordersFind.payload && state.promiseRed.ordersFind.payload.data &&
|
|
|
|
+ state.promiseRed.ordersFind.payload.data.OrderFind,
|
|
|
|
+
|
|
|
|
+ token: state.auth && state.auth.token,
|
|
|
|
+
|
|
|
|
+ status: state.promiseRed && state.promiseRed.ordersFind &&
|
|
|
|
+ state.promiseRed.ordersFind.payload && state.promiseRed.ordersFind &&
|
|
|
|
+ state.promiseRed.ordersFind.status,
|
|
|
|
+
|
|
|
|
+ isUserAdmin: state.promiseRed && state.promiseRed.user &&
|
|
|
|
+ state.promiseRed.user.payload && state.promiseRed.user.payload.data &&
|
|
|
|
+ state.promiseRed.user.payload.data.UserFindOne &&
|
|
|
|
+ state.promiseRed.user.payload.data.UserFindOne.acl &&
|
|
|
|
+ state.promiseRed.user.payload.data.UserFindOne.acl.indexOf("admin") > -1,
|
|
|
|
+
|
|
|
|
+ owner: state.auth && state.auth.payload && state.auth.payload.sub &&
|
|
|
|
+ state.auth.payload.sub,
|
|
|
|
+
|
|
|
|
+ isAdmin: state.auth && state.auth.payload && state.auth.payload.sub &&
|
|
|
|
+ state.auth.payload.sub.acl && state.auth.payload.sub.acl.indexOf("admin") > -1,
|
|
|
|
+
|
|
|
|
+
|
|
|
|
+ });
|
|
|
|
+
|
|
|
|
+
|
|
|
|
+
|
|
|
|
+ const mapDispatchToProps = dispatch => bindActionCreators({
|
|
|
|
+
|
|
|
|
+ ordersFind: actionOrdersFind
|
|
|
|
+ }, dispatch);
|
|
|
|
+
|
|
|
|
+ const COrdersList = connect(mapStateToProps, mapDispatchToProps)(OrdersList);
|
|
|
|
+
|
|
|
|
+ export default COrdersList;
|