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'; ...@@ -6,7 +6,8 @@ import { fetchUserCart } from '../../actions/cart_actions';
const mSTP = state => ({ const mSTP = state => ({
products: state.market.products, products: state.market.products,
promotions: state.market.promotions, promotions: state.market.promotions,
user: state.user user: state.user,
cart: state.cart
}); });
const mDTP = dispatch => ({ const mDTP = dispatch => ({
......
...@@ -15,6 +15,7 @@ export default class ProductMarket extends Component { ...@@ -15,6 +15,7 @@ export default class ProductMarket extends Component {
this.props.getProducts(); this.props.getProducts();
this.props.getPromotions(); this.props.getPromotions();
// this.props.getUserCart(this.props.user.emailAddress); // this.props.getUserCart(this.props.user.emailAddress);
this.props.getUserCart("chef");
} }
render() { 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 { combineReducers } from 'redux';
import productsReducer from './products_reducer'; import productsReducer from './products_reducer';
import userReducer from './user_reducer' import userReducer from './user_reducer'
import cartReducer from './cart_reducer';
const rootReducer = combineReducers({ const rootReducer = combineReducers({
market: productsReducer, market: productsReducer,
user: userReducer, user: userReducer,
cart: cartReducer
}); });
export default rootReducer; export default rootReducer;
\ No newline at end of file
import {SET_CURRENT_USER, LOGOUT_USER} from '../actions/session_actions' import {SET_CURRENT_USER, LOGOUT_USER} from '../actions/session_actions'
import { RECEIVE_USER_CART } from '../actions/cart_actions';
const initialState = { const initialState = {
currentUser: null, currentUser: null,
cart: {},
} }
const userReducer = (state = initialState, action) => { const userReducer = (state = initialState, action) => {
Object.freeze(state); Object.freeze(state);
let newState = Object.assign({}, state); let newState = Object.assign({}, state);
...@@ -13,8 +12,6 @@ const userReducer = (state = initialState, action) => { ...@@ -13,8 +12,6 @@ const userReducer = (state = initialState, action) => {
return newState.currentUser = action.user.data; return newState.currentUser = action.user.data;
case LOGOUT_USER: case LOGOUT_USER:
return newState.currentUser = null; return newState.currentUser = null;
case RECEIVE_USER_CART:
return newState.cart = action.cart
default: default:
return state; 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