File size: 2,137 Bytes
1e92f2d
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
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
import React, { useState, useEffect } from 'react';
import { Link } from 'react-router-dom';
import Layout from './Layout';
import { getCart } from './cartHelpers';
import Card from './Card';
import Checkout from './Checkout';

const Cart = () => {
    const [items, setItems] = useState([]);
    const [run, setRun] = useState(false);

    useEffect(() => {
        setItems(getCart());
    }, [run]);

    const showItems = items => {
        return (
            <div>
                <h3 className="h3 my-2 p-2 text-center text-info border-info rounded border">You have {`${items.length}`} Dream destination.</h3>
                {items.map((product, i) => (
                    <Card
                        key={i}
                        product={product}
                        showAddToCartButton={false}
                        cartUpdate={true}
                        showRemoveProductButton={true}
                        setRun={setRun}
                        run={run}
                    />
                ))}
            </div>
        );
    };

    const noItemsMessage = () => (
        <h3 className ="border border-warning p-3 my-4 h3 rounded shadow text-center">
            Your Wishlist is empty. <br /><br /> <Link to="/shop" className="text-info font-weight-bold h4">Look for places to visit</Link>
        </h3>
    );

    return (
        <Layout
            title=""
            description=""
            className=""
        >
            <div className="row my-2">
           
                <div className="col-4 offset-1">
                <div className="cart-product-details">{items.length > 0 ? showItems(items) : noItemsMessage()}</div>
                </div>
                <div className="col-5 offset-1">
                <div className="my-4 card p-3">
                    <h2 className="my-2 p-3 border rounded shadow text-warning text-center">Your cart summary</h2>
                    <hr />
                    <Checkout products={items} setRun={setRun} run={run} />
                    </div>
                </div>
            </div>
        </Layout>
    );
};

export default Cart;