File size: 6,540 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
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
/* eslint-disable no-unused-vars */
import React, { Fragment } from "react";
import { Link, withRouter } from "react-router-dom";
import { signout, isAuthenticated } from "../auth";
// eslint-disable-next-line
import { itemTotal } from "./cartHelpers";
import DropdownButton from 'react-bootstrap/DropdownButton';
import Dropdown from 'react-bootstrap/Dropdown';

const isActive = (history, path) => {
    if (history.location.pathname === path) {
        return { color: "#ff9900" };
    } else {
        return { color: "white" };
    }
};


const Menu = ({ history }) => (
    <nav className="navbar navbar-expand-md navbar-dark" id="my-nav">
        <Link className="navbar-brand" to="/">TravelYaari</Link>
        <button className="navbar-toggler" type="button" data-toggle="collapse" data-target="#navbarSupportedContent" aria-controls="navbarSupportedContent" aria-expanded="false" aria-label="Toggle navigation">
        <span className="navbar-toggler-icon"></span>
        </button>
        <div className="collapse navbar-collapse" id="navbarSupportedContent">
            <ul className="navbar-nav ml-auto">
            {!isAuthenticated() && (
                <Fragment>
                    <li className="nav-item">
                        <a
                            className="nav-link text-white"
                            href="/#home-popularplace"
                        >
                            Popular Places
                        </a>
                    </li>

                    <li className="nav-item">
                    <a
                            className="nav-link text-white"
                            href="/#homegallery"
                        >
                            Gallery
                        </a>
                    </li>
                </Fragment>
            )}
            {isAuthenticated() && (
                <li className="nav-item">
                <Link
                    className="nav-link"
                    style={isActive(history, "/shop")}
                    to="/Shop"
                >All places
                </Link>
            </li>
            )}
            
            {isAuthenticated() && (
                <li className="nav-item">
                <Link
                    className="nav-link"
                    style={isActive(history, "/gallery")}
                    to="/Gallery"
                >Gallery
                </Link>
            </li>
            )}

            {isAuthenticated() && isAuthenticated().user.role === 0 && (
                <li className="nav-item">
                    <Link
                        className="nav-link"
                        style={isActive(history, "/user/dashboard")}
                        to="/user/dashboard"
                    >
                        Dashboard
                    </Link>
                </li>
            )}

            {isAuthenticated() && isAuthenticated().user.role === 1 && (
                <li className="nav-item">
                    <Link
                        className="nav-link"
                        style={isActive(history, "/admin/dashboard")}
                        to="/admin/dashboard"
                    >
                        Dashboard
                    </Link>
                </li>
            )}

            {!isAuthenticated() && (
                <Fragment>
                    <li className="nav-item">
                        <Link
                            className="nav-link"
                            style={isActive(history, "/signin")}
                            to="/signin"
                        >
                            Signin
                        </Link>
                    </li>

                    <li className="nav-item">
                        <Link
                            className="nav-link"
                            style={isActive(history, "/signup")}
                            to="/signup"
                        >
                            Signup
                        </Link>
                    </li>
                </Fragment>
            )}
            <li className="nav-item">
                <Link
                    className="nav-link"
                    style={isActive(history, "/cart")}
                    to="/cart"
                >
                    Added Place{" "}
                    <sup>
                        <small className="cart-badge">{itemTotal()}</small>
                    </sup>
                </Link>
            </li>

            {isAuthenticated() && (
                <li className="nav-item">
                    <span
                        className="nav-link"
                        style={{ cursor: "pointer", color: "#ffffff" }}
                        onClick={() =>
                            signout(() => {
                                history.push("/");
                            })
                        }
                    >Signout
                    </span>
                </li>
            )}
            {isAuthenticated() && (
                <li className="nav-item">
                <Dropdown className="m-0 p-0">
                <Dropdown.Toggle  id="dropdown-basic" className="font-weight-bold">
                More
                </Dropdown.Toggle>
                <Dropdown.Menu style={{background:'#4caf50',border:'none'}}>
                <Dropdown.Item as ="button"><Link
                            className="nav-link text-white dropdownid"
                            style={isActive(history, "/about")}
                            to="/about"
                        >
                            about Us
                        </Link></Dropdown.Item>
                <Dropdown.Item href="#/action-2"><Link
                            className="nav-link dropdownid"
                            style={isActive(history, "/team")}
                            to="/team"
                        >
                            Our Team
                        </Link></Dropdown.Item>
                <Dropdown.Item href="#/action-3"><Link
                            className="nav-link dropdownid"
                            style={isActive(history, "/contact")}
                            to="/contact"
                        >Contact Us
                        </Link></Dropdown.Item>
                </Dropdown.Menu>
                </Dropdown>
            </li>
            )}
            
        </ul>
    </div>
</nav>
);

export default withRouter(Menu);