diff options
| author | Randy Ridge <randyridge@gmail.com> | 2018-09-14 20:01:25 -0400 |
|---|---|---|
| committer | GitHub <noreply@github.com> | 2018-09-14 20:01:25 -0400 |
| commit | 908180c77cd38011eeedcae949613da2a3391e5e (patch) | |
| tree | b59bf1aae819a04d453cde72f6e601f5561a740f /stepped-solutions/46/frontend/components | |
| parent | 1f6667d233a4a2e9df977204d83a8f749c050c75 (diff) | |
| parent | b3bebda57ba187b7fa10398054b54c05d3fd3555 (diff) | |
Merge branch 'master' into randyridge/our
Diffstat (limited to 'stepped-solutions/46/frontend/components')
| -rwxr-xr-x | stepped-solutions/46/frontend/components/CartItem.js | 53 |
1 files changed, 53 insertions, 0 deletions
diff --git a/stepped-solutions/46/frontend/components/CartItem.js b/stepped-solutions/46/frontend/components/CartItem.js new file mode 100755 index 0000000..b0ce62e --- /dev/null +++ b/stepped-solutions/46/frontend/components/CartItem.js @@ -0,0 +1,53 @@ +import React from 'react'; +import styled from 'styled-components'; +import PropTypes from 'prop-types'; +import formatMoney from '../lib/formatMoney'; +import RemoveFromCart from './RemoveFromCart'; + +const CartItemStyles = styled.li` + padding: 1rem 0; + border-bottom: 1px solid ${props => props.theme.lightgrey}; + display: grid; + align-items: center; + grid-template-columns: auto 1fr auto; + img { + margin-right: 10px; + } + h3, + p { + margin: 0; + } +`; + +const CartItem = ({ cartItem }) => { + // first check if that item exists + if (!cartItem.item) + return ( + <CartItemStyles> + <p>This Item has been removed</p> + <RemoveFromCart id={cartItem.id} /> + </CartItemStyles> + ); + return ( + <CartItemStyles> + <img width="100" src={cartItem.item.image} alt={cartItem.item.title} /> + <div className="cart-item-details"> + <h3>{cartItem.item.title}</h3> + <p> + {formatMoney(cartItem.item.price * cartItem.quantity)} + {' - '} + <em> + {cartItem.quantity} × {formatMoney(cartItem.item.price)} each + </em> + </p> + </div> + <RemoveFromCart id={cartItem.id} /> + </CartItemStyles> + ); +}; + +CartItem.propTypes = { + cartItem: PropTypes.object.isRequired, +}; + +export default CartItem; |
