blob: b0ce62ef373a927f2b286e1d196e131400cd0ef2 (
plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
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;
|