Commit e0b90111 authored by Shaphen Pangburn's avatar Shaphen Pangburn

[AFP-48 Shaphen Pangburn]: Abstract out cart to its own piece of state and...

[AFP-48 Shaphen Pangburn]: Abstract out cart to its own piece of state and Successfully populate with items from backend
parent e12270d3
......@@ -6,7 +6,8 @@ import { fetchUserCart } from '../../actions/cart_actions';
const mSTP = state => ({
products: state.market.products,
promotions: state.market.promotions,
user: state.user
user: state.user,
cart: state.cart
});
const mDTP = dispatch => ({
......
......@@ -15,6 +15,7 @@ export default class ProductMarket extends Component {
this.props.getProducts();
this.props.getPromotions();
// this.props.getUserCart(this.props.user.emailAddress);
this.props.getUserCart("chef");
}
render() {
......
import { RECEIVE_USER_CART } from '../actions/cart_actions';
const initialState = {}
const cartReducer = (state = initialState, action) => {
Object.freeze(state);
let newState = Object.assign({}, state);
switch (action.type) {
case RECEIVE_USER_CART:
return newState.cart = action.cart.data.cartItems
default:
return state;
}
}
export default cartReducer;
\ No newline at end of file
import { combineReducers } from 'redux';
import productsReducer from './products_reducer';
import userReducer from './user_reducer'
import cartReducer from './cart_reducer';
const rootReducer = combineReducers({
market: productsReducer,
user: userReducer,
cart: cartReducer
});
export default rootReducer;
\ No newline at end of file
import {SET_CURRENT_USER, LOGOUT_USER} from '../actions/session_actions'
import { RECEIVE_USER_CART } from '../actions/cart_actions';
const initialState = {
currentUser: null,
cart: {},
}
const userReducer = (state = initialState, action) => {
Object.freeze(state);
let newState = Object.assign({}, state);
......@@ -13,8 +12,6 @@ const userReducer = (state = initialState, action) => {
return newState.currentUser = action.user.data;
case LOGOUT_USER:
return newState.currentUser = null;
case RECEIVE_USER_CART:
return newState.cart = action.cart
default:
return state;
}
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment