source: frontend/src/Nav.tsx@ 3727852

main
Last change on this file since 3727852 was 4022db1, checked in by Filip Gavrilovski <filipgavrilovski28@…>, 6 months ago

add logo and favicon

  • Property mode set to 100644
File size: 2.5 KB
Line 
1import { Link } from "react-router-dom";
2import axiosInstance from "./api/axiosInstance";
3import Logo from "./assets/logo-finkwave.png";
4import { useAuth } from "./context/authContext";
5
6const Nav = () => {
7 const { user, setUser, isAuthLoading } = useAuth();
8
9 const handleLogout = async (e: React.MouseEvent<HTMLButtonElement>) => {
10 e.preventDefault();
11 try {
12 await axiosInstance.post("/auth/logout");
13 setUser(undefined);
14 } catch (error) {
15 console.error("Logout failed:", error);
16 }
17 };
18
19 return (
20 <div className="bg-gray-800 p-4 flex justify-between items-center">
21 <Link to="/" className="text-white text-lg font-semibold">
22 <img src={Logo} alt="Finkwave Logo" className="h-12 w-auto" />
23 </Link>
24
25 <div className="flex items-center space-x-4">
26 {!isAuthLoading && (
27 <div className="flex items-center space-x-3">
28 {user ? (
29 <div className="flex items-center space-x-3">
30 <div className="flex items-center space-x-2 bg-slate-700 rounded-lg px-3 py-2">
31 <div className="w-8 h-8 bg-blue-500 rounded-full flex items-center justify-center">
32 <span className="text-white text-sm font-semibold">
33 {user.username.charAt(0).toUpperCase()}
34 </span>
35 </div>
36 <div className="text-white">
37 <p className="text-sm font-medium">{user.username}</p>
38 <p className="text-xs text-gray-300 capitalize">
39 {user.role}
40 </p>
41 </div>
42 </div>
43 <button
44 onClick={(e: React.MouseEvent<HTMLButtonElement>) =>
45 handleLogout(e)
46 }
47 className="bg-red-500 hover:bg-red-600 text-white px-4 py-2 rounded-lg text-sm
48 font-medium transition-colors duration-200 flex items-center space-x-1 cursor-pointer"
49 >
50 Logout
51 </button>
52 </div>
53 ) : (
54 <div className="flex items-center space-x-4">
55 <Link
56 to="/login"
57 className="bg-blue-500 hover:bg-blue-600 text-white px-4 py-2 rounded-lg text-sm
58 font-medium transition-colors duration-200 cursor-pointer"
59 >
60 Login
61 </Link>
62 <Link
63 to="/register"
64 className="bg-green-500 hover:bg-green-600 text-white px-4 py-2 rounded-lg text-sm
65 font-medium transition-colors duration-200 cursor-pointer"
66 >
67 Register
68 </Link>
69 </div>
70 )}
71 </div>
72 )}
73 </div>
74 </div>
75 );
76};
77
78export default Nav;
Note: See TracBrowser for help on using the repository browser.