-
Notifications
You must be signed in to change notification settings - Fork 1.3k
/
Copy pathNavBar.js
174 lines (168 loc) · 5.26 KB
/
NavBar.js
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
import React, { useState } from "react";
import { NavLink as RouterNavLink } from "react-router-dom";
import { FontAwesomeIcon } from "@fortawesome/react-fontawesome";
import {
Collapse,
Container,
Navbar,
NavbarToggler,
NavbarBrand,
Nav,
NavItem,
NavLink,
Button,
UncontrolledDropdown,
DropdownToggle,
DropdownMenu,
DropdownItem,
} from "reactstrap";
import { useAuth0 } from "@auth0/auth0-react";
const NavBar = () => {
const [isOpen, setIsOpen] = useState(false);
const {
user,
isAuthenticated,
loginWithRedirect,
logout,
} = useAuth0();
const toggle = () => setIsOpen(!isOpen);
const logoutWithRedirect = () =>
logout({
logoutParams: {
returnTo: window.location.origin,
}
});
return (
<div className="nav-container">
<Navbar color="light" light expand="md" container={false}>
<Container>
<NavbarBrand className="logo" />
<NavbarToggler onClick={toggle} />
<Collapse isOpen={isOpen} navbar>
<Nav className="mr-auto" navbar>
<NavItem>
<NavLink
tag={RouterNavLink}
to="/"
exact
activeClassName="router-link-exact-active"
>
Home
</NavLink>
</NavItem>
{isAuthenticated && (
<NavItem>
<NavLink
tag={RouterNavLink}
to="/external-api"
exact
activeClassName="router-link-exact-active"
>
External API
</NavLink>
</NavItem>
)}
</Nav>
<Nav className="d-none d-md-block" navbar>
{!isAuthenticated && (
<NavItem>
<Button
id="qsLoginBtn"
color="primary"
className="btn-margin"
onClick={() => loginWithRedirect()}
>
Log in
</Button>
</NavItem>
)}
{isAuthenticated && (
<UncontrolledDropdown nav inNavbar>
<DropdownToggle nav caret id="profileDropDown">
<img
src={user.picture}
alt="Profile"
className="nav-user-profile rounded-circle"
width="50"
/>
</DropdownToggle>
<DropdownMenu>
<DropdownItem header>{user.name}</DropdownItem>
<DropdownItem
tag={RouterNavLink}
to="/profile"
className="dropdown-profile"
activeClassName="router-link-exact-active"
>
<FontAwesomeIcon icon="user" className="mr-3" /> Profile
</DropdownItem>
<DropdownItem
id="qsLogoutBtn"
onClick={() => logoutWithRedirect()}
>
<FontAwesomeIcon icon="power-off" className="mr-3" /> Log
out
</DropdownItem>
</DropdownMenu>
</UncontrolledDropdown>
)}
</Nav>
{!isAuthenticated && (
<Nav className="d-md-none" navbar>
<NavItem>
<Button
id="qsLoginBtn"
color="primary"
block
onClick={() => loginWithRedirect({})}
>
Log in
</Button>
</NavItem>
</Nav>
)}
{isAuthenticated && (
<Nav
className="d-md-none justify-content-between"
navbar
style={{ minHeight: 170 }}
>
<NavItem>
<span className="user-info">
<img
src={user.picture}
alt="Profile"
className="nav-user-profile d-inline-block rounded-circle mr-3"
width="50"
/>
<h6 className="d-inline-block">{user.name}</h6>
</span>
</NavItem>
<NavItem>
<FontAwesomeIcon icon="user" className="mr-3" />
<RouterNavLink
to="/profile"
activeClassName="router-link-exact-active"
>
Profile
</RouterNavLink>
</NavItem>
<NavItem>
<FontAwesomeIcon icon="power-off" className="mr-3" />
<RouterNavLink
to="#"
id="qsLogoutBtn"
onClick={() => logoutWithRedirect()}
>
Log out
</RouterNavLink>
</NavItem>
</Nav>
)}
</Collapse>
</Container>
</Navbar>
</div>
);
};
export default NavBar;