Browse Source

actionFind goods

maryluis 3 years ago
parent
commit
6b1772bf83

+ 18 - 6
shop/src/components/profilePage.js

@@ -1,7 +1,7 @@
 import {CUsersList, SearchUserInput, CUpdateAdminForm} from "./index";
 import {CUsersList, SearchUserInput, CUpdateAdminForm} from "./index";
 import {gql, urlUpload, actionPromise, actionGoodCard, getGoods,
 import {gql, urlUpload, actionPromise, actionGoodCard, getGoods,
     actionUserFindOne, updateImgAction, actionAuthLogin, actionAuthLogout,
     actionUserFindOne, updateImgAction, actionAuthLogin, actionAuthLogout,
-    actionUserUpdate,getData, actionLogin } from "../reducers";
+    actionUserUpdate, actionOrdersFind, getData, actionLogin } from "../reducers";
 import {createStore, combineReducers, applyMiddleware, bindActionCreators} from 'redux';
 import {createStore, combineReducers, applyMiddleware, bindActionCreators} from 'redux';
 import { connect } from "react-redux";
 import { connect } from "react-redux";
 import { useEffect, useState, useRef } from "react";
 import { useEffect, useState, useRef } from "react";
@@ -10,7 +10,7 @@ import {BrowserRouter as Router, Route, Link, Switch, Redirect, useHistory} from
 import { NewAuth } from "../reducers/actionAuthLog";
 import { NewAuth } from "../reducers/actionAuthLog";
 
 
 
 
-const YourProfile = ({state, updateStatus, updatedUser = {}, newImg, token, onLogin, onLogout, updateImg, 
+const YourProfile = ({state, orders, updateStatus, updatedUser = {}, newImg, token, onLogin, onLogout, updateImg, 
                         updateUser, isUserAdmin = {}, status, data = {}, getData, 
                         updateUser, isUserAdmin = {}, status, data = {}, getData, 
                         match:{params:{_id}}, isAdmin = [], isOwner = {}, newPicture = "clear"}) => {
                         match:{params:{_id}}, isAdmin = [], isOwner = {}, newPicture = "clear"}) => {
 
 
@@ -25,7 +25,16 @@ const YourProfile = ({state, updateStatus, updatedUser = {}, newImg, token, onLo
     // const [isUpdatePage, changePage] = useState(false);
     // const [isUpdatePage, changePage] = useState(false);
     // const [newImage, getImage] = useState({});
     // const [newImage, getImage] = useState({});
 
 
-     useEffect(() =>  history.location.pathname.includes(`/profile/`) ? getData(`${isOwner.id}`) : getData(`${_id}`),[history.location.pathname])
+     useEffect(() =>   {
+       if(history.location.pathname.includes(`/profile/`)) {
+        getData(`${isOwner.id}`);
+        orders(`${isOwner.id}`) ;
+       }
+       else {
+        getData(`${_id}`);
+        orders(`${_id}`) ;
+       }
+    },[history.location.pathname])
 
 
      useEffect( 
      useEffect( 
        async() => {
        async() => {
@@ -50,7 +59,7 @@ const YourProfile = ({state, updateStatus, updatedUser = {}, newImg, token, onLo
      const [searchInput, changeValue] = useState("Пошук");
      const [searchInput, changeValue] = useState("Пошук");
      
      
 
 
-    //  console.log(state);
+      console.log(state);
     //  console.log(data);
     //  console.log(data);
      
      
 
 
@@ -192,7 +201,9 @@ const mapStateToProps = state => ({
      state.promiseRed.photo.payload && state.promiseRed.photo.payload,
      state.promiseRed.photo.payload && state.promiseRed.photo.payload,
 
 
      isAdmin: state.auth && state.auth.payload && 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
+     state.auth.payload.sub.acl && state.auth.payload.sub.acl.indexOf("admin") > -1,
+
+     
   });
   });
 
 
 
 
@@ -202,7 +213,8 @@ const mapStateToProps = state => ({
     updateImg: updateImgAction,
     updateImg: updateImgAction,
     updateUser: actionUserUpdate,
     updateUser: actionUserUpdate,
     onLogout: actionAuthLogout,
     onLogout: actionAuthLogout,
-    onLogin: actionLogin
+    onLogin: actionLogin,
+    orders: actionOrdersFind
   }, dispatch);
   }, dispatch);
 
 
 const CYourProfile = connect(mapStateToProps, mapDispatchToProps)
 const CYourProfile = connect(mapStateToProps, mapDispatchToProps)

+ 30 - 0
shop/src/reducers/actionOrdersFind.js

@@ -0,0 +1,30 @@
+import {actionPromise, gql} from "./index";
+
+
+
+const actionOrdersFind = (data) => {
+
+    return async dispatch => {
+
+        const queryJson = JSON.stringify(
+            [{"___owner" : data}]
+        )
+
+        await dispatch(actionPromise("ordersFind", gql (
+            `query orders ($query: String) {
+                OrderFind(query: $query){
+                  total
+                  _id
+                  orderGoods {count, _id, price, good {name, price}}
+                  createdAt
+                  owner {
+                    login
+                  }
+                  
+                }
+            }`, {query: queryJson}
+        )))
+    }
+}
+
+export default actionOrdersFind;

+ 2 - 1
shop/src/reducers/index.js

@@ -17,6 +17,7 @@ import actionUserFindOne from "./actionFindOneUser";
 import actionUserUpdate from "./actionUserUpdate";
 import actionUserUpdate from "./actionUserUpdate";
 import actionSearchUser from "./actionSearchUser";
 import actionSearchUser from "./actionSearchUser";
 import actionGoodUpdate from "./actionGoodUpdate";
 import actionGoodUpdate from "./actionGoodUpdate";
+import actionOrdersFind from "./actionOrdersFind";
 
 
 
 
 function promiseReducer(state={}, action){
 function promiseReducer(state={}, action){
@@ -39,7 +40,7 @@ function promiseReducer(state={}, action){
       basket: cartReducer
       basket: cartReducer
   }), compose(applyMiddleware(thunk)))
   }), compose(applyMiddleware(thunk)))
 
 
-export {actionPromise, gql, actionGoods, getData, promiseReducer, store, actionSearch,
+export {actionPromise, actionOrdersFind,  gql, actionGoods, getData, promiseReducer, store, actionSearch,
    actionLogin, authReducer, actionAuthLogin, actionAuthLogout, urlUpload, actionGoodCard, 
    actionLogin, authReducer, actionAuthLogin, actionAuthLogout, urlUpload, actionGoodCard, 
    updateImgAction, actionCartAdd, actionCartDelete, actionCartClear, actionOrder,
    updateImgAction, actionCartAdd, actionCartDelete, actionCartClear, actionOrder,
     actionReg, actionUserFindOne, actionUserUpdate, actionSearchUser, actionGoodUpdate};
     actionReg, actionUserFindOne, actionUserUpdate, actionSearchUser, actionGoodUpdate};