header.tsx 8.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215
  1. "use client";
  2. import Link from "next/link";
  3. import Image from "next/image";
  4. import { LoginLink, LogoutLink, RegisterLink } from "@kinde-oss/kinde-auth-nextjs/server";
  5. import { useKindeBrowserClient } from "@kinde-oss/kinde-auth-nextjs";
  6. import { useTheme } from "@/app/providers";
  7. import {
  8. NavigationMenu,
  9. NavigationMenuContent,
  10. NavigationMenuItem,
  11. NavigationMenuLink,
  12. NavigationMenuList,
  13. NavigationMenuTrigger,
  14. } from "@/components/ui/navigation-menu";
  15. import { Button } from "@/components/ui/button";
  16. import { Sheet, SheetContent, SheetTrigger } from "@/components/ui/sheet";
  17. import { Menu, Home, Settings, User, LogOut, LogIn } from "lucide-react";
  18. import { DarkModeToggle } from "./dark-mode-toggle";
  19. import React from "react";
  20. const userMenuItems = [
  21. {
  22. title: "Profile",
  23. href: "/profile",
  24. description: "Manage your profile settings",
  25. icon: User,
  26. },
  27. {
  28. title: "Settings",
  29. href: "/settings",
  30. description: "Configure your preferences",
  31. icon: Settings,
  32. },
  33. ];
  34. export default function Header() {
  35. const { isAuthenticated, getUser, isLoading } = useKindeBrowserClient();
  36. const { theme } = useTheme();
  37. const user = getUser();
  38. const logoSrc = theme === "dark" ? "/vtorio-dark.svg" : "/vtorio.svg";
  39. if (isLoading) {
  40. return (
  41. <header className="sticky top-0 z-50 w-full border-b bg-background/95 backdrop-blur supports-[backdrop-filter]:bg-background/60">
  42. <div className="flex h-16 items-center justify-between">
  43. <div className="flex items-center gap-6 pl-4 md:pl-6">
  44. <Link href="/dashboard" className="flex items-center space-x-2">
  45. <Image
  46. src={logoSrc}
  47. alt="vtor.io"
  48. width={32}
  49. height={8}
  50. className="h-8 w-auto"
  51. priority
  52. />
  53. </Link>
  54. </div>
  55. <div className="flex items-center gap-4 pr-4 md:pr-6">
  56. <div className="h-8 w-20 bg-gray-200 animate-pulse rounded"></div>
  57. </div>
  58. </div>
  59. </header>
  60. );
  61. }
  62. return (
  63. <header className="sticky top-0 z-50 w-full border-b bg-background/95 backdrop-blur supports-[backdrop-filter]:bg-background/60">
  64. <div className="flex h-16 items-center justify-between pr-6">
  65. <div className="flex items-center gap-6 pl-4 md:pl-6">
  66. <Link href="/dashboard" className="flex items-center space-x-2">
  67. <Image
  68. src={logoSrc}
  69. alt="vtor.io"
  70. width={32}
  71. height={8}
  72. className="h-8 w-auto"
  73. priority
  74. />
  75. </Link>
  76. </div>
  77. <div className="flex items-center gap-4 pr-0 md:pr-0">
  78. {isAuthenticated ? (
  79. <>
  80. <NavigationMenu className="hidden md:flex">
  81. <NavigationMenuList>
  82. <NavigationMenuItem>
  83. <NavigationMenuTrigger className="h-9">
  84. <div className="flex items-center gap-2">
  85. <Image
  86. className="rounded-full"
  87. src={user?.picture || "/default-avatar.png"}
  88. alt="User Avatar"
  89. width={24}
  90. height={24}
  91. />
  92. <span className="text-sm font-medium">{user?.given_name || user?.email}</span>
  93. </div>
  94. </NavigationMenuTrigger>
  95. <NavigationMenuContent>
  96. <ul className="grid gap-3 p-6 w-[300px]">
  97. {userMenuItems.map((item) => (
  98. <li key={item.title}>
  99. <NavigationMenuLink asChild>
  100. <Link
  101. href={item.href}
  102. 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">
  103. <div className="flex items-center gap-2">
  104. <item.icon className="h-4 w-4" />
  105. <div className="text-sm font-medium leading-none">{item.title}</div>
  106. </div>
  107. <p className="line-clamp-2 text-sm leading-snug text-muted-foreground">
  108. {item.description}
  109. </p>
  110. </Link>
  111. </NavigationMenuLink>
  112. </li>
  113. ))}
  114. <li>
  115. <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">
  116. <div className="flex items-center gap-2">
  117. <LogOut className="h-4 w-4" />
  118. <div className="text-sm font-medium leading-none">Logout</div>
  119. </div>
  120. <p className="line-clamp-2 text-sm leading-snug text-muted-foreground">
  121. Sign out of your account
  122. </p>
  123. </LogoutLink>
  124. </li>
  125. </ul>
  126. </NavigationMenuContent>
  127. </NavigationMenuItem>
  128. </NavigationMenuList>
  129. </NavigationMenu>
  130. </>
  131. ) : (
  132. <div className="hidden md:flex items-center gap-2">
  133. <LoginLink>
  134. <Button variant="ghost" size="sm">
  135. <LogIn className="h-4 w-4 mr-2" />
  136. Login
  137. </Button>
  138. </LoginLink>
  139. </div>
  140. )}
  141. <DarkModeToggle />
  142. {/* Mobile Menu */}
  143. <Sheet>
  144. <SheetTrigger asChild className="md:hidden">
  145. <Button variant="ghost" size="icon">
  146. <Menu className="h-5 w-5" />
  147. <span className="sr-only">Toggle menu</span>
  148. </Button>
  149. </SheetTrigger>
  150. <SheetContent side="right" className="w-[300px]">
  151. <div className="flex flex-col space-y-4 mt-8">
  152. <Link href="/" className="flex items-center space-x-2">
  153. <Home className="h-4 w-4" />
  154. <span>Home</span>
  155. </Link>
  156. {isAuthenticated ? (
  157. <>
  158. <div className="border-t pt-4">
  159. <div className="flex items-center space-x-2 mb-4">
  160. <Image
  161. className="rounded-full"
  162. src={user?.picture || "/default-avatar.png"}
  163. alt="User Avatar"
  164. width={32}
  165. height={32}
  166. />
  167. <span className="font-medium">{user?.given_name || user?.email}</span>
  168. </div>
  169. {userMenuItems.map((item) => (
  170. <Link
  171. key={item.title}
  172. href={item.href}
  173. className="flex items-center space-x-2 py-2">
  174. <item.icon className="h-4 w-4" />
  175. <span>{item.title}</span>
  176. </Link>
  177. ))}
  178. <LogoutLink className="flex items-center space-x-2 py-2 text-red-600">
  179. <LogOut className="h-4 w-4" />
  180. <span>Logout</span>
  181. </LogoutLink>
  182. </div>
  183. </>
  184. ) : (
  185. <div className="border-t pt-4 space-y-2">
  186. <LoginLink>
  187. <Button variant="ghost" className="w-full justify-start">
  188. <LogIn className="h-4 w-4 mr-2" />
  189. Login
  190. </Button>
  191. </LoginLink>
  192. <RegisterLink>
  193. <Button className="w-full">Sign Up</Button>
  194. </RegisterLink>
  195. </div>
  196. )}
  197. </div>
  198. </SheetContent>
  199. </Sheet>
  200. </div>
  201. </div>
  202. </header>
  203. );
  204. }