|
@@ -2,7 +2,7 @@ import { useEffect } from "react";
|
|
|
import { connect } from "react-redux";
|
|
|
import{OneGood} from "../components";
|
|
|
import {createStore, combineReducers, applyMiddleware, bindActionCreators} from 'redux';
|
|
|
-import {gql, urlUpload, actionPromise, actionGoodCard, getGoods, actionGoods, actionCartAdd, actionCartDelete} from "../reducers";
|
|
|
+import {gql, urlUpload, actionPromise, actionGoodCard, getGoods, actionGoods, actionCartAdd, actionCartDelete, actionCartClear} from "../reducers";
|
|
|
|
|
|
|
|
|
|
|
@@ -20,10 +20,7 @@ function arrFromObj(obj) {
|
|
|
|
|
|
var newArr = [];
|
|
|
for (let key in obj) {
|
|
|
-
|
|
|
-
|
|
|
newArr.push(obj[key])
|
|
|
-
|
|
|
}
|
|
|
return newArr;
|
|
|
}
|
|
@@ -32,39 +29,44 @@ function arrFromObj(obj) {
|
|
|
const mapStateToProps = state => ({
|
|
|
state: state,
|
|
|
basket: state.basket,
|
|
|
- // idGoodsObj: ObjFilter(state.basket, "price"),
|
|
|
GoodsArr: arrFromObj(ObjFilter(state.basket, "price")),
|
|
|
- // goodCard: getGoods(state, "goodCard", "GoodFindOne"),
|
|
|
-
|
|
|
-
|
|
|
});
|
|
|
|
|
|
const mapDispatchToProps = dispatch => bindActionCreators({
|
|
|
- //getData: actionGoods,
|
|
|
onAdd: actionCartAdd,
|
|
|
onDel: actionCartDelete,
|
|
|
+ onClear: actionCartClear
|
|
|
}, dispatch);
|
|
|
|
|
|
|
|
|
-const BasketPage = ({ basket, GoodsArr, onAdd, onDel}) => {
|
|
|
-
|
|
|
-
|
|
|
- console.log(basket);
|
|
|
-
|
|
|
+const BasketPage = ({ basket, GoodsArr, onAdd, onDel, onClear}) => {
|
|
|
+
|
|
|
+ if(!basket.price){
|
|
|
+ return(
|
|
|
+ <div>Зайдіть у каталог щоб замовити, та повертайтесь</div>
|
|
|
+ )
|
|
|
+ }
|
|
|
return (
|
|
|
<>
|
|
|
<div className = "basketInner">
|
|
|
-
|
|
|
- {GoodsArr.map((good) => <div className = "oneGood"><OneGood key = {good._id} id = {good.id}
|
|
|
+ <div className = "basketgoodsInner">
|
|
|
+ {GoodsArr.map((good) =>
|
|
|
+ <div className = "oneGood"><OneGood key = {good._id} id = {good.id}
|
|
|
name = {good.name} price = {good.price} image = {good.image ? `${urlUpload}/${good.image[0].url}` : `https://images.ua.prom.st/2259265311_korobka-syurpriz-dlya.jpg`}/>
|
|
|
<div className = "basketButoons">
|
|
|
<button onClick = {() => onAdd(good.name, good.price, good.id, good.description, good.image)}>+</button>
|
|
|
<h4>{good.count}</h4>
|
|
|
<button onClick = {() => onDel(good.name, good.price, good.id, good.description, good.image)}>-</button>
|
|
|
</div>
|
|
|
- </div>
|
|
|
- )}
|
|
|
|
|
|
+
|
|
|
+ </div>
|
|
|
+ )}
|
|
|
+ </div>
|
|
|
+ <div className = "basketBottom">
|
|
|
+ <button>Замовити</button>
|
|
|
+ <button onClick = {() => onClear(basket)}>ТаНуНафіг</button>
|
|
|
+ </div>
|
|
|
</div>
|
|
|
</>
|
|
|
)
|