File size: 1,582 Bytes
f5071ca
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
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
import React from 'react'
import CurrencyFormat from "react-currency-format"
import { useStateValue } from '../../context/StateProvider'
import './Subtotal.css'
import { getCartTotal } from '../../context/reducer'
import { useHistory } from 'react-router-dom'

function Subtotal() {
    const history = useHistory()
    const [{ cart }] = useStateValue()
    return (
        <div className="subtotal">
            <div className="subtotal__head">
                <img
                    src="https://images-eu.ssl-images-amazon.com/images/G/31/checkout/assets/TM_desktop._CB443006202_.png"
                    alt=""
                />
            </div>

            <div className="subtotal__body">
                <CurrencyFormat
                    renderText={value => (
                        <>
                            <p>
                                Subtotal ({cart.length} items) : <strong>{`${value}`}</strong>
                            </p>
                            <small className="subtotal__gift">
                                <input type="checkbox" /> This order contains a gift
                        </small>
                        </>
                    )}
                    decimalScale={2}
                    value={getCartTotal(cart)}
                    displayType={"text"}
                    thousandSeparator={true}
                    prefix={"₹"}
                />
                <button onClick={e => history.push('/payment')}>Proceed to Checkout</button>
            </div>
        </div>

    )
}

export default Subtotal