|
@@ -1,5 +1,5 @@
|
|
|
import { connect } from "react-redux";
|
|
|
-import {gql, urlUpload, actionPromise, actionGoodCard, getGoods} from "../reducers";
|
|
|
+import {gql, urlUpload, actionPromise, actionGoodCard, getGoods, actionCartAdd} from "../reducers";
|
|
|
import {createStore, combineReducers, applyMiddleware, bindActionCreators} from 'redux';
|
|
|
import { useEffect, useState } from 'react';
|
|
|
import {BrowserRouter as Router, Route, Link, Switch, Redirect, useHistory} from 'react-router-dom';
|
|
@@ -10,11 +10,14 @@ import {BrowserRouter as Router, Route, Link, Switch, Redirect, useHistory} from
|
|
|
|
|
|
const mapStateToProps = state => ({
|
|
|
state: state,
|
|
|
+ basket: state.basket,
|
|
|
goodCard: getGoods(state, "goodCard", "GoodFindOne")
|
|
|
});
|
|
|
|
|
|
const mapDispatchToProps = dispatch => bindActionCreators({
|
|
|
- getData: actionGoodCard
|
|
|
+ getData: actionGoodCard,
|
|
|
+ onAdd: actionCartAdd
|
|
|
+
|
|
|
}, dispatch);
|
|
|
|
|
|
|
|
@@ -23,10 +26,10 @@ import {BrowserRouter as Router, Route, Link, Switch, Redirect, useHistory} from
|
|
|
|
|
|
|
|
|
|
|
|
- const GoodCard = ({id, goodCard = null, getData, className = "goodCard"}) => {
|
|
|
+ const GoodCard = ({id, goodCard = null, state, onAdd, getData, className = "goodCard"}) => {
|
|
|
const history = useHistory();
|
|
|
useEffect(() => getData(id), [id]);
|
|
|
-
|
|
|
+ console.log(state)
|
|
|
|
|
|
|
|
|
const [width, setWidth] = useState(window.innerWidth);
|
|
@@ -55,6 +58,7 @@ import {BrowserRouter as Router, Route, Link, Switch, Redirect, useHistory} from
|
|
|
<img src = {goodCard.images ? `${urlUpload}/${goodCard.images[0].url}`: `https://images.ua.prom.st/2259265311_korobka-syurpriz-dlya.jpg`}/>
|
|
|
<span>{`${goodCard.price}грн`}</span>
|
|
|
<p>{goodCard.description}</p>
|
|
|
+ <button onClick = {() => onAdd(goodCard.price, id)}>В кошик</button>
|
|
|
</div>
|
|
|
}
|
|
|
</>
|