|
| 1 | +import React from 'react'; |
| 2 | +import { Link, useNavigate } from 'react-router-dom'; |
| 3 | +import { useAuth } from '../utils/auth'; |
| 4 | +import { logout } from '../utils/firebase'; |
| 5 | +import { Button } from '@/components/ui/button'; |
| 6 | +import { |
| 7 | + DropdownMenu, |
| 8 | + DropdownMenuContent, |
| 9 | + DropdownMenuItem, |
| 10 | + DropdownMenuLabel, |
| 11 | + DropdownMenuSeparator, |
| 12 | + DropdownMenuTrigger, |
| 13 | +} from "@/components/ui/dropdown-menu" |
| 14 | +import { Avatar, AvatarImage, AvatarFallback } from "@/components/ui/avatar" |
1 | 15 |
|
2 | | -import { Link } from "react-router-dom"; |
3 | | -import { Button } from "@/components/ui/button"; |
4 | | -import { ThemeToggle } from "@/components/ui/theme-toggle"; |
5 | | -import { useAuth } from "../utils/auth"; |
6 | | -import { signOut } from "firebase/auth"; |
7 | | -import { auth } from "../utils/firebase"; |
| 16 | +const Navbar: React.FC = () => { |
| 17 | + const { currentUser } = useAuth(); |
| 18 | + const navigate = useNavigate(); |
8 | 19 |
|
9 | | -const Navbar = () => { |
10 | | - const { currentUser: user } = useAuth(); |
11 | | - |
12 | | - const handleSignOut = async () => { |
13 | | - try { |
14 | | - await signOut(auth); |
15 | | - console.log('User signed out successfully.'); |
16 | | - } catch (error) { |
17 | | - console.error('Sign out error:', error); |
18 | | - } |
| 20 | + const handleLogout = async () => { |
| 21 | + await logout(); |
| 22 | + navigate('/login'); |
19 | 23 | }; |
20 | 24 |
|
21 | 25 | return ( |
22 | | - <nav className="w-full py-4 px-6 flex items-center justify-between bg-background border-b"> |
23 | | - <div className="flex items-center gap-6"> |
24 | | - <Link to="/" className="text-xl font-bold"> |
25 | | - Sober App |
| 26 | + <div className="bg-background border-b"> |
| 27 | + <div className="container flex h-16 items-center justify-between py-4"> |
| 28 | + <Link to="/" className="font-bold text-2xl"> |
| 29 | + PurePath |
26 | 30 | </Link> |
27 | | - <Link to="/community">Community</Link> |
28 | | - <Link to="/progress">Progress</Link> |
29 | | - </div> |
30 | | - <div className="flex items-center gap-2"> |
31 | | - <ThemeToggle /> |
32 | | - {user ? ( |
33 | | - <Button variant="outline" onClick={handleSignOut}>Sign Out</Button> |
34 | | - ) : ( |
35 | | - <> |
36 | | - <Link to="/login"> |
37 | | - <Button variant="outline">Log In</Button> |
38 | | - </Link> |
39 | | - <Link to="/register"> |
40 | | - <Button>Register</Button> |
41 | | - </Link> |
42 | | - </> |
43 | | - )} |
| 31 | + <nav> |
| 32 | + {currentUser ? ( |
| 33 | + <DropdownMenu> |
| 34 | + <DropdownMenuTrigger asChild> |
| 35 | + <Button variant="ghost" className="relative h-8 w-8 rounded-full"> |
| 36 | + <Avatar> |
| 37 | + <AvatarImage src="/placeholder.svg" alt="User" /> |
| 38 | + <AvatarFallback>{currentUser.email?.charAt(0).toUpperCase()}</AvatarFallback> |
| 39 | + </Avatar> |
| 40 | + </Button> |
| 41 | + </DropdownMenuTrigger> |
| 42 | + <DropdownMenuContent align="end"> |
| 43 | + <DropdownMenuLabel>My Account</DropdownMenuLabel> |
| 44 | + <DropdownMenuSeparator /> |
| 45 | + <DropdownMenuItem asChild> |
| 46 | + <Link to="/dashboard">Dashboard</Link> |
| 47 | + </DropdownMenuItem> |
| 48 | + <DropdownMenuItem asChild> |
| 49 | + <Link to="/profile">Profile</Link> |
| 50 | + </DropdownMenuItem> |
| 51 | + <DropdownMenuSeparator /> |
| 52 | + <DropdownMenuItem onClick={handleLogout}> |
| 53 | + Logout |
| 54 | + </DropdownMenuItem> |
| 55 | + </DropdownMenuContent> |
| 56 | + </DropdownMenu> |
| 57 | + ) : ( |
| 58 | + <div> |
| 59 | + <Link to="/login" className="mr-4"> |
| 60 | + Login |
| 61 | + </Link> |
| 62 | + <Link to="/register">Register</Link> |
| 63 | + </div> |
| 64 | + )} |
| 65 | + </nav> |
44 | 66 | </div> |
45 | | - </nav> |
| 67 | + </div> |
46 | 68 | ); |
47 | 69 | }; |
48 | 70 |
|
|
0 commit comments