Commit 56cd049f authored by Shaphen Pangburn's avatar Shaphen Pangburn

[AFP-48 Shaphen Pangburn]: add user login notice logic to product details modal

parent 50ed5394
...@@ -5,6 +5,24 @@ export default class ProductDetails extends Component { ...@@ -5,6 +5,24 @@ export default class ProductDetails extends Component {
super(props) super(props)
this.state = {} this.state = {}
} }
handleSubmit(e, product) {
e.preventDefault();
const newCart = Object.assign({}, {
userId: this.props.user.currentUser.email,
cartItems: JSON.parse(JSON.stringify(this.props.cart)) // JSON.parse/stringify will deep-dup the object
})
const newCartItem = {
productRef: {
id: product.sku,
sku: product.sku,
upc: product.upc,
},
quantity: parseInt(this.state.orderItemQuantity)
}
newCart.cartItems.push(newCartItem);
this.props.addToCart(newCart, this.props.user.currentUser.email);
}
render() { render() {
return ( return (
...@@ -46,16 +64,19 @@ export default class ProductDetails extends Component { ...@@ -46,16 +64,19 @@ export default class ProductDetails extends Component {
: :
<p id="prod-details-original-price">Price: ${ this.props.product.price }</p> <p id="prod-details-original-price">Price: ${ this.props.product.price }</p>
} }
<input <form className="details-add-cart-and-quantity" onSubmit={ e => this.handleSubmit(e, this.props.product) }>
type="number" <input
className="prod-details-quantity" type="number"
disabled={ !this.props.user?.currentUser } className="prod-details-quantity"
placeholder="Quantity" disabled={ !this.props.user?.currentUser }
/> placeholder="Quantity"
<button className="prod-details-add-to-cart" disabled={ !this.props.user?.currentUser }> />
Add to Cart <button className="prod-details-add-to-cart" disabled={ !this.props.user?.currentUser }>
</button> Add to Cart
</div> </button>
{ this.props.user?.currentUser ? "" :<p id="details-please-log-in-notice">Log in to Add to Cart</p>}
</form>
</div>
</div> </div>
</div> </div>
) )
......
...@@ -132,6 +132,7 @@ export default class ProductItem extends Component { ...@@ -132,6 +132,7 @@ export default class ProductItem extends Component {
product={ this.props.item } product={ this.props.item }
discount={ discount } discount={ discount }
user={ this.props.user } user={ this.props.user }
addToCart={ this.props.addToCart }
/> />
</Modal> </Modal>
</div> </div>
......
...@@ -296,11 +296,31 @@ ...@@ -296,11 +296,31 @@
} }
#product-details-condenser { #product-details-condenser {
position: relative;
height: 48%; height: 48%;
width: 100%; width: 100%;
margin: 148px 0px 0px 20px; margin: 148px 0px 0px 20px;
} }
#details-please-log-in-notice {
display: none;
position: absolute;
text-align: center;
width: 190px;
bottom: 86px;
left: 3px;
padding: 3px 10px;
border-radius: 5px;
background-color: rgb(248, 76, 76);
animation: fadeInUp;
animation-duration: 0.5s;
}
.details-add-cart-and-quantity:hover #details-please-log-in-notice {
display: block;
}
#prod-details-shipping { #prod-details-shipping {
height: 95px; height: 95px;
display: flex; display: flex;
...@@ -334,6 +354,10 @@ ...@@ -334,6 +354,10 @@
width: 100%; width: 100%;
} }
.details-add-to-cart-and-quantity {
position: relative;
}
.prod-details-quantity { .prod-details-quantity {
border: 1px dotted rgba(0,0,0,0.3); border: 1px dotted rgba(0,0,0,0.3);
border-radius: 5px; border-radius: 5px;
......
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