-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathSubtotal.js
More file actions
43 lines (41 loc) · 1.34 KB
/
Copy pathSubtotal.js
File metadata and controls
43 lines (41 loc) · 1.34 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
import React from 'react'
import './subtotal.css'
import CurrencyFormat from 'react-currency-format'
import {useStateValue} from './StateProvider';
import {useNavigate} from 'react-router-dom'
function Subtotal() {
const[{basket},dispatch] = useStateValue();
const navigate = useNavigate();
const findTotal = () => {
let total=0;
basket.map((ind) => {
let price=ind.price;
total+=price;
})
return total;
}
return (
<div className='subtotal'>
<CurrencyFormat
renderText={(value) => (
<>
<p>
Subtotal ({basket.length} items) : <strong>{value}</strong>
</p>
<small className='subtotal_gift'>
<input type="checkbox" />
This Contains a gift
</small>
</>
)}
decimalScale={2}
value={findTotal()}
displayType={"text"}
thousandSeperator={true}
prefix={"$"}
/>
<button onClick={(e) => navigate('/paymentPage')}>Proceed to Checkout</button>
</div>
)
}
export default Subtotal