File size: 1,781 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
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
import React, { Fragment } from "react";
import "./Checkout.css";
import Subtotal from "./Subtotal";
import { useStateValue } from "./StateProvider";
import CheckoutProduct from "./CheckoutProduct";
import { Link, useHistory } from "react-router-dom";

import FlipMove from "react-flip-move";

function Checkout() {
  const history = useHistory();
  const [{ basket, user, drawer }, dispatch] = useStateValue();

  return (
    <Fragment>
      <Link to="/">
        <div className="checkout__center">
          <img
            src="https://miro.medium.com/max/396/0*bVnfVVG7Y7qXQcO1"
            style={{ height: 70, marginTop: 20 }}
            onClick={() =>
              dispatch({
                type: "SET_DRAWER",
                toggle: false,
              })
            }
          />
        </div>
      </Link>
      <div className="checkout">
        <div className="checkout__left">
          <img
            className="checkout__ad"
            alt=""
            src="https://images-na.ssl-images-amazon.com/images/G/02/UK_CCMP/TM/OCC_Amazon1._CB423492668_.jpg"
          />
          <div>
            <h3>Hello {user?.email}</h3>
            <h2 className="checkout__title">Your Shopping Basket</h2>
          </div>
          <FinalProducts />
        </div>
        <div className="checkout__right">
          <Subtotal />
        </div>
      </div>
    </Fragment>
  );
}

const FinalProducts = () => {
  const [{ basket, user }, dispatch] = useStateValue();

  return (
    <Fragment>
      {basket.map((item) => (
        <CheckoutProduct
          id={item.id}
          price={item.price}
          rating={item.rating}
          image={item.image}
          title={item.title}
        />
      ))}
    </Fragment>
  );
};

export default Checkout;