Commit 198d7348 authored by Shaphen Pangburn's avatar Shaphen Pangburn

[AFP-48 Shaphen Pangburn]: Clear global state cart when logging out

parent 39ca21a0
import * as ApiUtil from '../util/cart_api_util';
export const RECEIVE_USER_CART = "RECEIVE_USER_CART";
export const CLEAR_USER_CART = "CLEAR_USER_CART";
const receiveUserCart = cart => ({
type: RECEIVE_USER_CART,
cart
})
export const clearUserCart = () => ({
type: CLEAR_USER_CART
})
export const fetchUserCart = userEmail => dispatch => ApiUtil.fetchUserCart(userEmail)
.then(cart => dispatch(receiveUserCart(cart)));
......
import { connect } from 'react-redux';
import Session from './session';
import {login, logOut} from '../../actions/session_actions';
import { fetchUserCart, createUserCart } from '../../actions/cart_actions';
import { fetchUserCart, createUserCart, clearUserCart } from '../../actions/cart_actions';
const mSTP = state => ({
currentUser: state.user
......@@ -11,7 +11,8 @@ const mDTP = dispatch => ({
login: (userResponse) => dispatch(login(userResponse)),
logOut: () => dispatch(logOut()),
getUserCart: userId => dispatch(fetchUserCart(userId)),
createCart: newCart => dispatch(createUserCart(newCart))
createCart: newCart => dispatch(createUserCart(newCart)),
clearCart: () => dispatch(clearUserCart())
});
export default connect(mSTP, mDTP)(Session);
\ No newline at end of file
......@@ -42,6 +42,7 @@ export default class Session extends Component {
logOutSuccess = (response) => {
this.props.logOut()
this.props.clearCart()
this.setState({logIn: false})
}
......
import { RECEIVE_USER_CART } from '../actions/cart_actions';
import { RECEIVE_USER_CART, CLEAR_USER_CART } from '../actions/cart_actions';
const initialState = []
......@@ -8,6 +8,8 @@ const cartReducer = (state = initialState, action) => {
switch (action.type) {
case RECEIVE_USER_CART:
return newState.cart = action.cart.data.cartItems
case CLEAR_USER_CART:
return []
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