| 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234 |
- "use client";
- import Link from "next/link";
- import Image from "next/image";
- import { LoginLink, LogoutLink, RegisterLink } from "@kinde-oss/kinde-auth-nextjs/server";
- import { useKindeBrowserClient } from "@kinde-oss/kinde-auth-nextjs";
- import { useTheme } from "@/app/providers";
- import {
- NavigationMenu,
- NavigationMenuContent,
- NavigationMenuItem,
- NavigationMenuLink,
- NavigationMenuList,
- NavigationMenuTrigger,
- } from "@/components/ui/navigation-menu";
- import { Button } from "@/components/ui/button";
- import { Sheet, SheetContent, SheetTrigger } from "@/components/ui/sheet";
- import { Menu, Home, Settings, User, LogOut, LogIn, ArrowLeft } from "lucide-react";
- import { DarkModeToggle } from "./dark-mode-toggle";
- import React from "react";
- import { usePathname } from "next/navigation";
- const userMenuItems = [
- {
- title: "Profile",
- href: "/profile",
- description: "Manage your profile settings",
- icon: User,
- },
- {
- title: "Settings",
- href: "/settings",
- description: "Configure your preferences",
- icon: Settings,
- },
- ];
- export default function Header() {
- const { isAuthenticated, getUser, isLoading } = useKindeBrowserClient();
- const { theme } = useTheme();
- const user = getUser();
- const logoSrc = theme === "dark" ? "/vtorio-dark.svg" : "/vtorio.svg";
- const pathname = usePathname();
- // Don't show on dashboard or home page
- const shouldShowBackButton = pathname !== '/dashboard' && pathname !== '/';
- if (isLoading) {
- return (
- <header className="sticky top-0 z-50 w-full border-b bg-background/95 backdrop-blur supports-[backdrop-filter]:bg-background/60">
- <div className="flex h-16 items-center justify-between">
- <div className="flex items-center gap-6 pl-4 md:pl-6">
- <Link href="/" className="flex items-center space-x-2">
- <Image
- src={logoSrc}
- alt="vtor.io"
- width={32}
- height={8}
- className="h-8 w-auto"
- priority
- />
- </Link>
- {shouldShowBackButton && (
- <Link href="/dashboard" className="flex items-center space-x-2 text-sm font-medium hover:text-accent-foreground transition-colors">
- <ArrowLeft className="h-4 w-4" />
- <span>Back to dashboard</span>
- </Link>
- )}
- </div>
- <div className="flex items-center gap-4 pr-4 md:pr-6">
- <div className="h-8 w-20 bg-gray-200 animate-pulse rounded"></div>
- </div>
- </div>
- </header>
- );
- }
- return (
- <header className="sticky top-0 z-50 w-full border-b bg-background/95 backdrop-blur supports-[backdrop-filter]:bg-background/60">
- <div className="flex h-16 items-center justify-between pr-6">
- <div className="flex items-center gap-6 pl-4 md:pl-6">
- <Link href="/" className="flex items-center space-x-2">
- <Image
- src={logoSrc}
- alt="vtor.io"
- width={32}
- height={8}
- className="h-8 w-auto"
- priority
- />
- </Link>
- {shouldShowBackButton && (
- <Link href="/dashboard">
- <Button variant="outline" size="sm" className="flex items-center space-x-2">
- <ArrowLeft className="h-4 w-4" />
- <span>Back to dashboard</span>
- </Button>
- </Link>
- )}
- </div>
- <div className="flex items-center gap-4 pr-0 md:pr-0">
- {isAuthenticated ? (
- <>
- <NavigationMenu className="hidden md:flex">
- <NavigationMenuList>
- <NavigationMenuItem>
- <NavigationMenuTrigger className="h-9">
- <div className="flex items-center gap-2">
- <Image
- className="rounded-full"
- src={user?.picture || "/default-avatar.png"}
- alt="User Avatar"
- width={24}
- height={24}
- />
- <span className="text-sm font-medium">{user?.given_name || user?.email}</span>
- </div>
- </NavigationMenuTrigger>
- <NavigationMenuContent>
- <ul className="grid gap-3 p-6 w-[300px]">
- {userMenuItems.map((item) => (
- <li key={item.title}>
- <NavigationMenuLink asChild>
- <Link
- href={item.href}
- className="block select-none space-y-1 rounded-md p-3 leading-none no-underline outline-none transition-colors hover:bg-accent hover:text-accent-foreground">
- <div className="flex items-center gap-2">
- <item.icon className="h-4 w-4" />
- <div className="text-sm font-medium leading-none">{item.title}</div>
- </div>
- <p className="line-clamp-2 text-sm leading-snug text-muted-foreground">
- {item.description}
- </p>
- </Link>
- </NavigationMenuLink>
- </li>
- ))}
- <li>
- <LogoutLink className="block select-none space-y-1 rounded-md p-3 leading-none no-underline outline-none transition-colors hover:bg-accent hover:text-accent-foreground">
- <div className="flex items-center gap-2">
- <LogOut className="h-4 w-4" />
- <div className="text-sm font-medium leading-none">Logout</div>
- </div>
- <p className="line-clamp-2 text-sm leading-snug text-muted-foreground">
- Sign out of your account
- </p>
- </LogoutLink>
- </li>
- </ul>
- </NavigationMenuContent>
- </NavigationMenuItem>
- </NavigationMenuList>
- </NavigationMenu>
- </>
- ) : (
- <div className="hidden md:flex items-center gap-2">
- <LoginLink>
- <Button variant="ghost" size="sm">
- <LogIn className="h-4 w-4 mr-2" />
- Login
- </Button>
- </LoginLink>
- </div>
- )}
- <DarkModeToggle />
- {/* Mobile Menu */}
- <Sheet>
- <SheetTrigger asChild className="md:hidden">
- <Button variant="ghost" size="icon">
- <Menu className="h-5 w-5" />
- <span className="sr-only">Toggle menu</span>
- </Button>
- </SheetTrigger>
- <SheetContent side="right" className="w-[300px]">
- <div className="flex flex-col space-y-4 mt-8">
- <Link href="/" className="flex items-center space-x-2">
- <Home className="h-4 w-4" />
- <span>Home</span>
- </Link>
- {isAuthenticated ? (
- <>
- <div className="border-t pt-4">
- <div className="flex items-center space-x-2 mb-4">
- <Image
- className="rounded-full"
- src={user?.picture || "/default-avatar.png"}
- alt="User Avatar"
- width={32}
- height={32}
- />
- <span className="font-medium">{user?.given_name || user?.email}</span>
- </div>
- {userMenuItems.map((item) => (
- <Link
- key={item.title}
- href={item.href}
- className="flex items-center space-x-2 py-2">
- <item.icon className="h-4 w-4" />
- <span>{item.title}</span>
- </Link>
- ))}
- <LogoutLink className="flex items-center space-x-2 py-2 text-red-600">
- <LogOut className="h-4 w-4" />
- <span>Logout</span>
- </LogoutLink>
- </div>
- </>
- ) : (
- <div className="border-t pt-4 space-y-2">
- <LoginLink>
- <Button variant="ghost" className="w-full justify-start">
- <LogIn className="h-4 w-4 mr-2" />
- Login
- </Button>
- </LoginLink>
- <RegisterLink>
- <Button className="w-full">Sign Up</Button>
- </RegisterLink>
- </div>
- )}
- </div>
- </SheetContent>
- </Sheet>
- </div>
- </div>
- </header>
- );
- }
|