Commit 7ad8ab7d authored by Shaphen Pangburn's avatar Shaphen Pangburn

[AFP-48 Shaphen Pangburn]: Capture cart item data in Add to Cart handleSubmit....

[AFP-48 Shaphen Pangburn]: Capture cart item data in Add to Cart handleSubmit. Successfully push new cart item data to existing cart array
parent d6e08307
......@@ -31,17 +31,17 @@ export default class ProductItem extends Component {
handleSubmit(e, product) {
e.preventDefault();
// const newCart = Object.assign({}, this.props.cart);
// const newCartItem = {
// productRef: {
// id: product.sku,
// sku: product.sku,
// upc: product.upc,
// },
// quantity: this.state.orderItemQuantity;
// }
// newCart.cartItems.push(newCartItem);
// this.ptops.addCartItem(newCart);
const newCart = Object.assign([], this.props.cart);
const newCartItem = {
productRef: {
id: product.sku,
sku: product.sku,
upc: product.upc,
},
quantity: parseInt(this.state.orderItemQuantity)
}
newCart.push(newCartItem);
// this.props.addCartItem(newCart);
}
render() {
......
......@@ -14,7 +14,6 @@ export default class ProductMarket extends Component {
componentDidMount() {
this.props.getProducts();
this.props.getPromotions();
// this.props.getUserCart("chef");
}
render() {
......@@ -41,7 +40,7 @@ export default class ProductMarket extends Component {
return (
<div className={prod.productName ? "product-item-container" : "no-item"} key={ prod.sku }>
{ prod.productName ?
<ProductItem item={ prod }/>
<ProductItem item={ prod } cart={ this.props.cart }/>
:
<div className="product-item">
<p id="prod-not-available">This Product is No Longer Available</p>
......
import { connect } from 'react-redux';
import Session from './session';
import {login, logOut} from '../../actions/session_actions'
import {login, logOut} from '../../actions/session_actions';
import { fetchUserCart } from '../../actions/cart_actions';
const mSTP = state => ({
currentUser: state.user
......@@ -8,7 +9,8 @@ const mSTP = state => ({
const mDTP = dispatch => ({
login: (userResponse) => dispatch(login(userResponse)),
logOut: () => dispatch(logOut())
logOut: () => dispatch(logOut()),
getUserCart: userId => dispatch(fetchUserCart(userId))
});
export default connect(mSTP, mDTP)(Session);
\ No newline at end of file
......@@ -23,6 +23,9 @@ export default class Session extends Component {
const userResponse = {idToken: tokenId, userId, email, firstName, lastName, accessToken}
this.props.login(userResponse)
this.setState({logIn: true})
this.props.getUserCart(email)
.then(res => res.json)
.catch(err => err.json)
}
loginFailed = (response) => {
......
import { RECEIVE_USER_CART } from '../actions/cart_actions';
const initialState = {
cart: []
}
const initialState = []
const cartReducer = (state = initialState, action) => {
Object.freeze(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