-
Notifications
You must be signed in to change notification settings - Fork 0
/
Subtotal.js
48 lines (43 loc) · 1.26 KB
/
Subtotal.js
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
import React from "react";
import "./Subtotal.css";
import CurrencyFormat from "react-currency-format";
import { useStateValue } from "./StateProvider";
import { getBasketTotal } from './reducer';
function Subtotal() {
const [{ basket }, dispatch] = useStateValue();
console.log(basket);
// const TotalPrice = () => {
// let price = 0;
// basket.forEach((item) => {
// price += item.price;
// });
// return price === 0 ? 0 : "$" + price.toFixed(2);
// };
return (
<div className="subtotal">
<CurrencyFormat
renderText={(value) => {
return (
<>
<p>
{/* part of the homework */}
Subtotal ({basket?.length} items):{" "}
<strong>0</strong>
</p>
<small className="subtotal__gift">
<input type="checkbox" /> This order contains a gift
</small>
</>
);
}}
decimalScale={2}
value={getBasketTotal(basket)} // part of the homework
displayType={"text"}
thousandSeparator={true}
prefix={"$"}
/>
<button>Proceed to Checkout</button>
</div>
);
}
export default Subtotal;