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