maryluis 3 年 前
コミット
c73a46ef60

+ 6 - 0
shop/src/App.css

@@ -36,6 +36,12 @@ button:disabled {
 
 }
 
+.miniWish {
+  display: flex;
+  justify-content: space-around;
+  width: 80px;
+  align-items: center;
+}
  .links {
    text-decoration: none;
    color: rgb(229, 229, 243);

+ 4 - 1
shop/src/components/catalog.js

@@ -9,9 +9,12 @@ import {BrowserRouter as Router, Route, Link, Switch, Redirect, useHistory} from
 
 const CatalogSubLink = ({name, arr}) => {
     const [show, changeValue] = useState(false);
+    const history = useHistory();
     return(
         <li><span  onClick = {() =>changeValue(!show)}>{name} </span>{<ul className="subCatalog">{ show && arr.map(key =>
-            <Links className = {"subLink"} key={`${key._id}${Math.random()}`} url={`/catalog/` + key._id} text={key.name}> </Links>)}</ul>}</li>
+            <Links className = {"subLink"} key={`${key._id}${Math.random()}`} 
+            url={(history.location.pathname.includes(`/catalog`) || history.location.pathname.includes(`/search`)) ? `/catalog/` + key._id : `/orderPage/` + key._id }
+            text={key.name}> </Links>)}</ul>}</li>
 
     )
 }

+ 11 - 14
shop/src/components/goodsList.js

@@ -5,22 +5,12 @@ import {Provider, connect} from 'react-redux';
 import {BrowserRouter as Router, Route, Link, Switch, Redirect, useHistory} from 'react-router-dom';
 
 
-  // const mapStateToProps = state => ({
-  //   state: state,
-  //   arr: getData(state),
-  //   // search: getGoods(state)
-  // });
-  
-  // const mapDispatchToProps = dispatch => bindActionCreators({
-  //   getData: actionGoods
-  // }, dispatch);
-  
 
 
 
 const GoodsList = ({arr = [], isWish, className = "goods", wishAdd, wishDelete, onAdd, onAddtoOrder}) => {
   const history = useHistory();
-  // console.log(arr)
+
   if(arr.length == 0) {
     return(
         <>
@@ -38,19 +28,26 @@ const GoodsList = ({arr = [], isWish, className = "goods", wishAdd, wishDelete,
         />
         <div>
           {isWish.indexOf(good._id) == -1 ? 
+          <div className = "miniWish">
+          <span>Хочу!</span>
           <svg onClick = {() => wishAdd (good._id)} xmlns="http://www.w3.org/2000/svg" width="16" height="16" fill="currentColor" className="bi bi-heart" viewBox="0 0 16 16">
             <path d="M8 2.748l-.717-.737C5.6.281 2.514.878 1.4 3.053c-.523 1.023-.641 2.5.314 4.385.92 1.815 2.834 3.989 6.286 6.357 3.452-2.368 5.365-4.542 6.286-6.357.955-1.886.838-3.362.314-4.385C13.486.878 10.4.28 8.717 2.01L8 2.748zM8 15C-7.333 4.868 3.279-3.04 7.824 1.143c.06.055.119.112.176.171a3.12 3.12 0 0 1 .176-.17C12.72-3.042 23.333 4.867 8 15z"/>
-          </svg> :
+          </svg>
+          </div>
+           :
+           <div className = "miniWish">
+             <span>Не хочу!</span>
           <svg onClick = {() => wishDelete (good._id)} xmlns="http://www.w3.org/2000/svg" width="16" height="16" fill="currentColor" className="bi bi-heart-fill" viewBox="0 0 16 16">
             <path fillRule="evenodd" d="M8 1.314C12.438-3.248 23.534 4.735 8 15-7.534 4.736 3.562-3.248 8 1.314z"/>
           </svg>
+          </div>
           }
 
 
           </div>
         <div>
            {(history.location.pathname.includes(`/catalog/`) || history.location.pathname.includes(`/search/`) || history.location.pathname.includes(`/wishes`)) && <button onClick = {() => onAdd(good.name, good.price, good._id,  good.description, good.images)}>В кошик</button>}
-           {history.location.pathname.includes(`/orderPage/`) && <button onClick = {() => onAddtoOrder(good._id, good.name, good.images, good.price,   )}>Додати до замовлення</button>} 
+           {history.location.pathname.includes(`/orderPage/`) && <button onClick = {() => onAddtoOrder(good._id, good.price,  good.name, good.images, )}>Додати до замовлення</button>} 
         </div>
       </div>
       
@@ -60,6 +57,6 @@ const GoodsList = ({arr = [], isWish, className = "goods", wishAdd, wishDelete,
   )
 }
 
-//  const CGoodsList = connect(mapStateToProps, mapDispatchToProps)(GoodsList);
+
 
  export default GoodsList;

+ 0 - 46
shop/src/components/goodsListSearch.js

@@ -1,46 +0,0 @@
-// import {OneGood} from "./index";
-// import {createStore, combineReducers, applyMiddleware, bindActionCreators} from 'redux';
-// import {getData, actionGoods, actionWishDelete, actionWishAdd, getSearchedGoods, actionSearch} from "../reducers";
-// import {Provider, connect} from 'react-redux';
-// import {GoodsNotFound } from "./index";
-
-// const mapStateToProps = state => ({
-//     state: state,
-//     search: getData(state, "search"),
-
-//     status: state.promiseRed && state.promiseRed.search &&
-//     state.promiseRed.search.payload && state.promiseRed.search &&
-//     state.promiseRed.search.status,
-
-//     wishes: state.wishListReducer
-    
-//   });
-  
-//   const mapDispatchToProps = dispatch => bindActionCreators({
-//     getData: actionSearch,
-//     addWish: actionWishAdd,
-//     delWish: actionWishDelete,
-    
-//   }, dispatch);
-  
-
-
-// const GoodsListSearch = ({status, wishes,addWish, delWish, search = [], className = "goods"}) => {
-    
-//     if(search.length == 0) {
-//         return(
-//             <>
-//             <GoodsNotFound/>
-//             </>
-//         )
-//     }
-//   return (
-//     <div className = {className}>          
-//       {search.map((good) => <OneGood key = {good._id} name = {good.name} price = {good.price} image = {good.images ? `http://shop-roles.asmer.fs.a-level.com.ua/${good.images[0].url}` : `https://images.ua.prom.st/2259265311_korobka-syurpriz-dlya.jpg`}/>)}
-//     </div>
-//   )
-// }
-
-//  const CGoodsListSearch = connect(mapStateToProps, mapDispatchToProps)(GoodsListSearch);
-
-//  export default CGoodsListSearch;

+ 5 - 13
shop/src/components/header.js

@@ -2,7 +2,6 @@ import {Footer, Links} from "./index"
 import {BrowserRouter as Router, Route, Link, Switch, Redirect, useHistory} from 'react-router-dom';
 import {Provider, connect} from 'react-redux';
 import React, {Component, useState, useEffect} from 'react';
-// import createHistory from "history/createBrowserHistory";
 import {actionAuthLogout, actionUserFindOne} from "../reducers"
 import {createStore, combineReducers, applyMiddleware} from 'redux';
 import thunk from 'redux-thunk';
@@ -21,7 +20,6 @@ const StandartMenu = ({className = "standartMenu", getCat = null}) => {
 
                 <Links url = {"/catalog"} text = {"Каталог"}/>
                 <Links url = {"/about"} text = {"Про нас"}/>
-                {/* <Links url = {"/post"} text = {"Оплата і доставка"}/> */}
                 <Links url = {"/contacts"} text = {"Контакти"}></Links>
 
             </ul>
@@ -51,7 +49,7 @@ const TabletMenu = ({}) => {
 }
 
 const ToLoginPage = ({login, onLogout, getData, NickName = "User", loginId}) => {
-    // useEffect(() => login && getData(loginId),[login])
+
     const history = useHistory();
 
     
@@ -63,8 +61,10 @@ const ToLoginPage = ({login, onLogout, getData, NickName = "User", loginId}) =>
         </svg>
         <Link to = {login ? "/profile/": "/login"} >
             <span className = "link">{login ? login : "Вхід"}</span>
-            {login && <button onClick = {() => onLogout()}>Вихід</button>}
-        </Link>
+            </Link>
+            {login && <button onClick = {() =>  { onLogout()
+                    window.location.reload()}}>Вихід</button>}
+
         </>
     )
 }
@@ -117,8 +117,6 @@ const CBasket = connect(s => ({data: s.basket, basketCount: s.basket.price}), {}
 
 const Header = ({}) => {
 
-    // const [wishes, wishesCount] = useState(0);
-    // console.log(connect((s) => ({isLoggedIn: s.auth.payload})))
     return(
         <>
             <div className = "header">
@@ -130,12 +128,6 @@ const Header = ({}) => {
 
                 <div className = "rightSide">
                     <CWishes/>
-                    {/* <div>
-                        <svg xmlns="http://www.w3.org/2000/svg" width="16" height="16" fill="currentColor" className="bi bi-heart" viewBox="0 0 16 16">
-                        <path d="M8 2.748l-.717-.737C5.6.281 2.514.878 1.4 3.053c-.523 1.023-.641 2.5.314 4.385.92 1.815 2.834 3.989 6.286 6.357 3.452-2.368 5.365-4.542 6.286-6.357.955-1.886.838-3.362.314-4.385C13.486.878 10.4.28 8.717 2.01L8 2.748zM8 15C-7.333 4.868 3.279-3.04 7.824 1.143c.06.055.119.112.176.171a3.12 3.12 0 0 1 .176-.17C12.72-3.042 23.333 4.867 8 15z"/>
-                        </svg>
-                        <span>Хочу({wishes})</span>
-                    </div> */}
                     <div>
                         <CToLoginPage/>
 

+ 1 - 4
shop/src/components/index.js

@@ -1,6 +1,5 @@
 import React, { useState } from 'react';
 import {BrowserRouter as Router, Route, Link, Switch, Redirect} from 'react-router-dom';
-// import createHistory from "history/createBrowserHistory";
 import {createStore, combineReducers, applyMiddleware} from 'redux';
 import Header from "./header";
 import Footer from "./footer";
@@ -12,11 +11,9 @@ import OneGood from './oneGood';
 import CGoodsList from "./goodsList";
 import {SearchInput, SearchUserInput} from "./searchInput";
 import CGoodsSearch from "./goodsSearch";
-import CGoodsListSearch from "./goodsListSearch";
 import GoodsNotFound from "./goodsNotFound";
 import LoginForm from "./loginOnPage";
 import CGoodCard from "./goodCard";
-// import {CUpdateForm} from "./updateForm";
 import CYourProfile from "./profilePage";
 import CBasketPage from "./basket";
 import COrderPage from "./orderDonePage";
@@ -26,7 +23,7 @@ import COrderUpdate from "./orderUpdate";
 import CWishesPage from "./wishesPage";
 
 
-export {Header,Footer, actionCatalogCard, Main, Links, CGoodsCategory, OneGood, CGoodsList, SearchInput, CGoodsSearch, CGoodsListSearch, GoodsNotFound, 
+export {Header,Footer, actionCatalogCard, Main, Links, CGoodsCategory, OneGood, CGoodsList, SearchInput, CGoodsSearch, GoodsNotFound, 
 LoginForm, CGoodCard, CWishesPage, CYourProfile, COrderUpdate, CBasketPage, COrdersList, COrderPage, CUsersList, SearchUserInput};
 
 

+ 21 - 28
shop/src/components/profilePage.js

@@ -27,21 +27,23 @@ const YourProfile = ({state, orders, loginStatus = {}, updateStatus, updatedUser
     const [showUpdate, onShow] = useState(false);
     const [searchInput, changeValue] = useState("Пошук");
 
-    // const [isUpdatePage, changePage] = useState(false);
-    // const [newImage, getImage] = useState({});
 
-     useEffect(() =>   {
-       if(history.location.pathname.includes(`/profile/`)) {
-        getData(`${isOwner.id}`);
-        orders(`${isOwner.id}`) ;
-       }
-       else {
-        getData(`${_id}`);
-        if(isAdmin) {
-        orders(`${_id}`) ;
-        }
+    useEffect( async () =>   {
+      if(history.location.pathname.includes(`/profile/`)) {
+       await getData(`${isOwner.id}`);
+       await orders(`${isOwner.id}`) ;
+      }
+      else {
+       await getData(`${_id}`);
+       if(isAdmin) {
+       await orders(`${_id}`) ;
        }
-    },[history.location.pathname])
+      }
+   },[history.location.pathname])
+
+    
+
+
 
      useEffect( 
        async() => {
@@ -61,12 +63,7 @@ const YourProfile = ({state, orders, loginStatus = {}, updateStatus, updatedUser
      
      
 
-     
-
-     
 
-       console.log(state);
-    // //  console.log(data);
      
 
         return (
@@ -126,20 +123,16 @@ const YourProfile = ({state, orders, loginStatus = {}, updateStatus, updatedUser
                         changeImg(true);
                       }
                         }/>
-                    <button disabled = {(newPicture == "PENDING") ||
-                       ( !isAdmin && (!nowPassword)) || 
-                        ((isAdmin && isOwner.id == data._id) && !nowPassword ) ||
-                        (Object.keys(loginStatus).length == 0) ||
-                        (loginStatus.status && loginStatus.status == "RESOLVED" && !loginStatus.payload.data.login) 
+                    <button disabled = {
+                      (newPicture == "PENDING") ||
+                      ( !isAdmin && (!nowPassword)) || 
+                       ((isAdmin &&  isOwner.id && data._id && isOwner.id == data._id) && !nowPassword ) ||
+                       (Object.keys(loginStatus).length == 0) ||
+                       (loginStatus.status && loginStatus.status == "RESOLVED" && !loginStatus.payload.data.login) 
                       }  
                          onClick = {
                         async () => {
 
-                          // if(!isAdmin || (isAdmin && isOwner.id == data._id)){
-
-                          //   await onLogin(data.login, nowPassword);
-
-                          //  }
                             let newUser = {};
                             newUser._id = data._id;
                             if(nick){

+ 4 - 7
shop/src/reducers/orderUpdateReduser.js

@@ -66,6 +66,7 @@ function orderUpdateReducer(state, { type, total, id, owner, goods, Id, images,
     if (type === "ORDER_ADD_NEW_GOOD") {
 
         if(state.goods[Id]){
+
             state = {
                 ...state,
                 goods : {
@@ -99,7 +100,8 @@ function orderUpdateReducer(state, { type, total, id, owner, goods, Id, images,
                         price: price,
                     }
 
-                }
+                },
+                total: +state.total + price    
             }
         }
     }
@@ -153,7 +155,7 @@ const actionOrderAddOne = (Id, id, goods, images) => ({
     images
 
 });
-const actionOrderAddNewGood = (Id, name, images, price) => ({
+const actionOrderAddNewGood = (Id, price,  name, images, ) => ({
     type: "ORDER_ADD_NEW_GOOD",
 
     Id,
@@ -170,9 +172,4 @@ const actionOrderClear = () => ({
 })
 
 
-// const actionCartClear = (count, price) => ({
-//     type: "CART_CLEAR",
-//     count,
-//     price
-// });
 export {orderUpdateReducer, actionOrderClear, actionOrderAddNewGood, actionOrderAddOne, actionOrderAddOrder, actionOrderDelete};