diff --git a/client/components/Cart.js b/client/components/Cart.js index 415c928..b9ad24d 100644 --- a/client/components/Cart.js +++ b/client/components/Cart.js @@ -1,40 +1,54 @@ -import React from 'react'; +import React, {Component} from 'react'; import {connect} from 'react-redux'; import {Link} from 'react-router-dom'; import {updateCart, updateSessionCart, deleteFromCart, deleteFromSessionCart} from '../store'; import CheckoutForm from './CheckoutForm'; -const Cart = (props) => { - const {userId, sessionCart, userCart, addMe, subtractMe, deleteMe} = props; - const cart = userId ? userCart : sessionCart; - let totalCost = 0; - return cart.products ? ( -
- {cart.products.map(product => { - totalCost = totalCost + product.product_order.quantity * product.price; - return ( -
-

Name: {product.title}

-

Quantity: {product.product_order.quantity} - - - -

-

Current Price: {product.price} coins ; Subtotal: {product.price * product.product_order.quantity} coins

-
- ) - })} - {/* USE STRIPE for payment processing */} -

Total Cost: {totalCost} coins

- - -
- ) : null; -}; +class Cart extends Component { + constructor(props) { + super(props); + this.state = { + coreyPromo: false + } + this.handleChange = this.handleChange.bind(this); + } + + handleChange (e) { + (e.target.value === 'CoreyRulezOmriDroolz') ? this.setState({coreyPromo: true}) : this.setState({coreyPromo: false}); + } + + render() { + const {userId, sessionCart, userCart, addMe, subtractMe, deleteMe} = this.props; + const cart = userId ? userCart : sessionCart; + let totalCost = 0; + return cart.products ? ( +
+ {cart.products.map(product => { + totalCost = totalCost + product.product_order.quantity * product.price; + return ( +
+

Name: {product.title}

+

Quantity: {product.product_order.quantity} + + + +

+

Current Price: {product.price} coins ; Subtotal: {product.price * product.product_order.quantity} coins

+
+ ) + })} + {/* USE STRIPE for payment processing */} +

Total Cost: {this.state.coreyPromo ? totalCost / 2 : totalCost} coins {this.state.coreyPromo ? 'Heck yes, you said it, not me! You save 50%!' : 'You can do better.'}

+ + +
+ ) : null; + } +} const mapState = (state) => ({ userId: state.user.id, diff --git a/client/components/CheckoutForm.js b/client/components/CheckoutForm.js index 8b81f63..f69a0b9 100644 --- a/client/components/CheckoutForm.js +++ b/client/components/CheckoutForm.js @@ -11,7 +11,7 @@ class CheckoutForm extends Component { } render() { - const {user, sessionCart, submitUserOrder, submitCartOrder} = this.props; + const {user, sessionCart, submitUserOrder, submitCartOrder, promoChange} = this.props; const onSubmit = user.id ? (e) => submitUserOrder(e, user.id) : (e) => submitCartOrder(e, sessionCart); return ( @@ -43,6 +43,14 @@ class CheckoutForm extends Component { name="payment" /> +