|
@@ -1,7 +1,9 @@
|
|
|
import jwt_decode from "jwt-decode";
|
|
|
+import { connect } from "react-redux";
|
|
|
+import {actionGoodCard} from "./index";
|
|
|
|
|
|
|
|
|
-function cartReducer(state, { type, id, count, price }) {
|
|
|
+function cartReducer(state, { type, count, id, image, name, description, price,}) {
|
|
|
if(state === undefined){
|
|
|
if(localStorage.authToken && localStorage.basket) {
|
|
|
state = JSON.parse(localStorage.basket);
|
|
@@ -11,12 +13,16 @@ function cartReducer(state, { type, id, count, price }) {
|
|
|
}
|
|
|
}
|
|
|
if (type === "CART_ADD") {
|
|
|
-
|
|
|
state = {
|
|
|
...state,
|
|
|
|
|
|
price: price + (state.price ||0),
|
|
|
- [id]: count + (state[id] || 0),
|
|
|
+ [id]:{ price: price,
|
|
|
+ id: id,
|
|
|
+ description: description,
|
|
|
+ image: image,
|
|
|
+ name, name,
|
|
|
+ count: (count + 1 )|| 0},
|
|
|
};
|
|
|
}
|
|
|
|
|
@@ -33,11 +39,14 @@ function cartReducer(state, { type, id, count, price }) {
|
|
|
|
|
|
|
|
|
|
|
|
-const actionCartAdd = (price, id, count = 1) => ({
|
|
|
+const actionCartAdd = (name, price, id, description, image, count = 1) => ({
|
|
|
type: "CART_ADD",
|
|
|
id,
|
|
|
count,
|
|
|
- price
|
|
|
+ price,
|
|
|
+ name,
|
|
|
+ description,
|
|
|
+ image
|
|
|
|
|
|
});
|
|
|
|