Press n or j to go to the next uncovered block, b, p or k for the previous block.
| 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 | import { Link, useNavigate } from "react-router-dom";
import { useAuth } from "../contexts/AuthContext";
export const Navbar: React.FC = () => {
const { isAuthenticated, logout } = useAuth();
const navigate = useNavigate();
const handleLogout = () => {
logout();
navigate("/login");
};
return (
<nav className="navbar" data-testid="navbar">
<div className="nav-brand">
<Link to="/dashboard">Testing Demo App</Link>
</div>
{isAuthenticated && (
<div className="nav-links">
<Link to="/dashboard" data-testid="nav-dashboard">
Dashboard
</Link>
<Link to="/products" data-testid="nav-products">
Products
</Link>
<button
onClick={handleLogout}
className="logout-button"
data-testid="logout-button"
>
Logout
</button>
</div>
)}
</nav>
);
};
|