-
Notifications
You must be signed in to change notification settings - Fork 138
Expand file tree
/
Copy pathOrderSummary.jsx
More file actions
executable file
·63 lines (57 loc) · 2.37 KB
/
Copy pathOrderSummary.jsx
File metadata and controls
executable file
·63 lines (57 loc) · 2.37 KB
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
54
55
56
57
58
59
60
61
62
63
import axios from 'axios';
import dayjs from 'dayjs';
import { formatMoney } from '../../utils/money';
import { DeliveryOptions } from './DeliveryOptions';
export function OrderSummary({ cart, deliveryOptions, loadCart }) {
return (
<div className="order-summary">
{deliveryOptions.length > 0 && cart.map((cartItem) => {
const selectedDeliveryOption = deliveryOptions
.find((deliveryOption) => {
return deliveryOption.id === cartItem.deliveryOptionId;
});
const deleteCartItem = async () => {
await axios.delete(`/api/cart-items/${cartItem.productId}`);
await loadCart();
};
return (
<div key={cartItem.productId} className="cart-item-container"
data-testid="cart-item-container">
<div className="delivery-date">
Delivery date: {dayjs(selectedDeliveryOption.estimatedDeliveryTimeMs).format('dddd, MMMM D')}
</div>
<div className="cart-item-details-grid">
<img className="product-image"
src={cartItem.product.image}
data-testid="cart-item-image" />
<div className="cart-item-details">
<div className="product-name"
data-testid="cart-item-name">
{cartItem.product.name}
</div>
<div className="product-price"
data-testid="cart-item-price">
{formatMoney(cartItem.product.priceCents)}
</div>
<div className="product-quantity">
<span data-testid="cart-item-quantity">
Quantity: <span className="quantity-label">{cartItem.quantity}</span>
</span>
<span className="update-quantity-link link-primary">
Update
</span>
<span className="delete-quantity-link link-primary"
data-testid="cart-item-delete-quantity-link"
onClick={deleteCartItem}>
Delete
</span>
</div>
</div>
<DeliveryOptions cartItem={cartItem} deliveryOptions={deliveryOptions} loadCart={loadCart} />
</div>
</div>
);
})}
</div>
);
}