Compare commits
2 Commits
7641675180
...
d50555cbc4
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
d50555cbc4 | ||
|
|
51b81c40af |
@@ -3,22 +3,45 @@
|
|||||||
import * as React from "react"
|
import * as React from "react"
|
||||||
import { cn } from "@/lib/utils"
|
import { cn } from "@/lib/utils"
|
||||||
import Link from "next/link"
|
import Link from "next/link"
|
||||||
import { useState } from "react"
|
import { useState, useEffect } from "react"
|
||||||
|
import { usePathname } from "next/navigation"
|
||||||
|
|
||||||
|
|
||||||
interface HeaderProps {
|
interface HeaderProps {
|
||||||
className?: string
|
className?: string
|
||||||
|
isLoggedIn?: boolean
|
||||||
|
isAdmin?: boolean
|
||||||
}
|
}
|
||||||
|
|
||||||
const navigation = [
|
const navigation = [
|
||||||
{ name: 'Dashboard', href: '/dashboard', current: true },
|
{ name: 'Home', href: '/', current: false, requiresAuth: false },
|
||||||
{ name: 'Projects', href: '/projects', current: false },
|
{ name: 'Pricing', href: '/pricing', current: false, requiresAuth: false },
|
||||||
{ name: 'Calendar', href: '/calendar', current: false },
|
{ name: 'FAQ', href: '/faq', current: false, requiresAuth: false },
|
||||||
{ name: 'Reports', href: '/reports', current: false },
|
{ name: 'Dashboard', href: '/dashboard', current: false, requiresAuth: false },
|
||||||
|
{ name: 'Projects', href: '/projects', current: false, requiresAuth: true },
|
||||||
|
{ name: 'Calendar', href: '/calendar', current: false, requiresAuth: false },
|
||||||
|
{ name: 'Reports', href: '/reports', current: false, requiresAuth: true },
|
||||||
]
|
]
|
||||||
|
|
||||||
export function Header({ className }: HeaderProps) {
|
export function Header({ className, isLoggedIn = false, isAdmin = false }: HeaderProps) {
|
||||||
const [mobileMenuOpen, setMobileMenuOpen] = useState(false)
|
const [mobileMenuOpen, setMobileMenuOpen] = useState(false)
|
||||||
const [profileOpen, setProfileOpen] = useState(false)
|
const [profileOpen, setProfileOpen] = useState(false)
|
||||||
|
const [activeNavItem, setActiveNavItem] = useState<string | null>(null)
|
||||||
|
|
||||||
|
// Use usePathname for client-side navigation
|
||||||
|
let pathname = usePathname()
|
||||||
|
|
||||||
|
// Update activeNavItem when pathname changes
|
||||||
|
useEffect(() => {
|
||||||
|
if (pathname) {
|
||||||
|
setActiveNavItem(pathname)
|
||||||
|
}
|
||||||
|
}, [pathname])
|
||||||
|
|
||||||
|
// Only render the header after the pathname is available
|
||||||
|
if (!pathname) {
|
||||||
|
return null
|
||||||
|
}
|
||||||
|
|
||||||
return (
|
return (
|
||||||
<header className={cn("bg-gray-900 shadow-sm", className)}>
|
<header className={cn("bg-gray-900 shadow-sm", className)}>
|
||||||
@@ -36,73 +59,80 @@ export function Header({ className }: HeaderProps) {
|
|||||||
</div>
|
</div>
|
||||||
<div className="hidden md:block">
|
<div className="hidden md:block">
|
||||||
<div className="ml-10 flex items-baseline space-x-4">
|
<div className="ml-10 flex items-baseline space-x-4">
|
||||||
{navigation.map((item) => (
|
{navigation.map((item) => {
|
||||||
<Link
|
const isCurrent = activeNavItem === item.href
|
||||||
key={item.name}
|
return (
|
||||||
href={item.href}
|
(item.requiresAuth ? (isLoggedIn || isAdmin) : true) && (
|
||||||
className={cn(
|
<Link
|
||||||
item.current
|
key={item.name}
|
||||||
? 'bg-gray-800 text-white'
|
href={item.href}
|
||||||
: 'text-gray-300 hover:bg-gray-700 hover:text-white',
|
className={cn(
|
||||||
'rounded-md px-3 py-2 text-sm font-medium transition-colors'
|
isCurrent
|
||||||
)}
|
? 'bg-gray-800 text-white'
|
||||||
aria-current={item.current ? 'page' : undefined}
|
: 'text-gray-300 hover:bg-gray-700 hover:text-white',
|
||||||
>
|
'rounded-md px-3 py-2 text-sm font-medium transition-colors'
|
||||||
{item.name}
|
)}
|
||||||
</Link>
|
aria-current={isCurrent ? 'page' : undefined}
|
||||||
))}
|
>
|
||||||
|
{item.name}
|
||||||
|
</Link>
|
||||||
|
)
|
||||||
|
)
|
||||||
|
})}
|
||||||
</div>
|
</div>
|
||||||
</div>
|
</div>
|
||||||
</div>
|
</div>
|
||||||
|
|
||||||
<div className="hidden md:block">
|
|
||||||
<div className="ml-4 flex items-center md:ml-6">
|
|
||||||
<button
|
|
||||||
type="button"
|
|
||||||
className="relative rounded-full bg-gray-800 p-1 text-gray-400 hover:text-white focus:outline-none focus:ring-2 focus:ring-white focus:ring-offset-2 focus:ring-offset-gray-800"
|
|
||||||
>
|
|
||||||
<span className="absolute -inset-1.5" />
|
|
||||||
<span className="sr-only">View notifications</span>
|
|
||||||
<svg className="h-6 w-6" fill="none" viewBox="0 0 24 24" strokeWidth="1.5" stroke="currentColor">
|
|
||||||
<path strokeLinecap="round" strokeLinejoin="round" d="M14.857 17.082a23.848 23.848 0 005.454-1.31A8.967 8.967 0 0118 9.75v-.7V9A6 6 0 006 9v.75a8.967 8.967 0 01-2.312 6.022c1.733.64 3.56 1.085 5.455 1.31m5.714 0a24.255 24.255 0 01-5.714 0m5.714 0a3 3 0 11-5.714 0" />
|
|
||||||
</svg>
|
|
||||||
</button>
|
|
||||||
|
|
||||||
{/* Profile dropdown */}
|
{isLoggedIn && (
|
||||||
<div className="relative ml-3">
|
<div className="hidden md:block">
|
||||||
<div>
|
<div className="ml-4 flex items-center md:ml-6">
|
||||||
<button
|
<button
|
||||||
type="button"
|
type="button"
|
||||||
className="relative flex max-w-xs items-center rounded-full bg-gray-800 text-sm focus:outline-none focus:ring-2 focus:ring-white focus:ring-offset-2 focus:ring-offset-gray-800"
|
className="relative rounded-full bg-gray-800 p-1 text-gray-400 hover:text-white focus:outline-none focus:ring-2 focus:ring-white focus:ring-offset-2 focus:ring-offset-gray-800"
|
||||||
onClick={() => setProfileOpen(!profileOpen)}
|
>
|
||||||
>
|
<span className="absolute -inset-1.5" />
|
||||||
<span className="absolute -inset-1.5" />
|
<span className="sr-only">View notifications</span>
|
||||||
<span className="sr-only">Open user menu</span>
|
<svg className="h-6 w-6" fill="none" viewBox="0 0 24 24" strokeWidth="1.5" stroke="currentColor">
|
||||||
<img
|
<path strokeLinecap="round" strokeLinejoin="round" d="M14.857 17.082a23.848 23.848 0 005.454-1.31A8.967 8.967 0 0118 9.75v-.7V9A6 6 0 006 9v.75a8.967 8.967 0 01-2.312 6.022c1.733.64 3.56 1.085 5.455 1.31m5.714 0a24.255 24.255 0 01-5.714 0m5.714 0a3 3 0 11-5.714 0" />
|
||||||
className="h-8 w-8 rounded-full"
|
</svg>
|
||||||
src="https://images.unsplash.com/photo-1472099645785-5658abf4ff4e?ixlib=rb-1.2.1&ixid=eyJhcHBfaWQiOjEyMDd9&auto=format&fit=facearea&facepad=2&w=256&h=256&q=80"
|
</button>
|
||||||
alt=""
|
|
||||||
/>
|
|
||||||
</button>
|
|
||||||
</div>
|
|
||||||
|
|
||||||
{profileOpen && (
|
{/* Profile dropdown */}
|
||||||
<div className="absolute right-0 z-10 mt-2 w-48 origin-top-right rounded-md bg-white py-1 shadow-lg ring-1 ring-black ring-opacity-5 focus:outline-none">
|
<div className="relative ml-3">
|
||||||
<Link href="/profile" className="block px-4 py-2 text-sm text-gray-700 hover:bg-gray-100">
|
<div>
|
||||||
Your Profile
|
<button
|
||||||
</Link>
|
type="button"
|
||||||
<Link href="/settings" className="block px-4 py-2 text-sm text-gray-700 hover:bg-gray-100">
|
className="relative flex max-w-xs items-center rounded-full bg-gray-800 text-sm focus:outline-none focus:ring-2 focus:ring-white focus:ring-offset-2 focus:ring-offset-gray-800"
|
||||||
Settings
|
onClick={() => setProfileOpen(!profileOpen)}
|
||||||
</Link>
|
>
|
||||||
<Link href="/logout" className="block px-4 py-2 text-sm text-gray-700 hover:bg-gray-100">
|
<span className="absolute -inset-1.5" />
|
||||||
Sign out
|
<span className="sr-only">Open user menu</span>
|
||||||
</Link>
|
<img
|
||||||
|
className="h-8 w-8 rounded-full"
|
||||||
|
src="https://images.unsplash.com/photo-1472099645785-5658abf4ff4e?ixlib=rb-1.2.1&ixid=eyJhcHBfaWQiOjEyMDd9&auto=format&fit=facearea&facepad=2&w=256&h=256&q=80"
|
||||||
|
alt=""
|
||||||
|
/>
|
||||||
|
</button>
|
||||||
</div>
|
</div>
|
||||||
)}
|
|
||||||
|
{profileOpen && (
|
||||||
|
<div className="absolute right-0 z-10 mt-2 w-48 origin-top-right rounded-md bg-white py-1 shadow-lg ring-1 ring-black ring-opacity-5 focus:outline-none">
|
||||||
|
<Link href="/profile" className="block px-4 py-2 text-sm text-gray-700 hover:bg-gray-100">
|
||||||
|
Your Profile
|
||||||
|
</Link>
|
||||||
|
<Link href="/settings" className="block px-4 py-2 text-sm text-gray-700 hover:bg-gray-100">
|
||||||
|
Settings
|
||||||
|
</Link>
|
||||||
|
<Link href="/logout" className="block px-4 py-2 text-sm text-gray-700 hover:bg-gray-100">
|
||||||
|
Sign out
|
||||||
|
</Link>
|
||||||
|
</div>
|
||||||
|
)}
|
||||||
|
</div>
|
||||||
</div>
|
</div>
|
||||||
</div>
|
</div>
|
||||||
</div>
|
)}
|
||||||
|
|
||||||
<div className="-mr-2 flex md:hidden">
|
<div className="-mr-2 flex md:hidden">
|
||||||
{/* Mobile menu button */}
|
{/* Mobile menu button */}
|
||||||
<button
|
<button
|
||||||
@@ -130,57 +160,66 @@ export function Header({ className }: HeaderProps) {
|
|||||||
{mobileMenuOpen && (
|
{mobileMenuOpen && (
|
||||||
<div className="md:hidden">
|
<div className="md:hidden">
|
||||||
<div className="space-y-1 px-2 pb-3 pt-2 sm:px-3">
|
<div className="space-y-1 px-2 pb-3 pt-2 sm:px-3">
|
||||||
{navigation.map((item) => (
|
{navigation.map((item) => {
|
||||||
<Link
|
const isCurrent = activeNavItem === item.href
|
||||||
key={item.name}
|
return (
|
||||||
href={item.href}
|
(item.requiresAuth ? (isLoggedIn || isAdmin) : true) && (
|
||||||
className={cn(
|
<Link
|
||||||
item.current
|
key={item.name}
|
||||||
? 'bg-gray-900 text-white'
|
href={item.href}
|
||||||
: 'text-gray-300 hover:bg-gray-700 hover:text-white',
|
className={cn(
|
||||||
'block rounded-md px-3 py-2 text-base font-medium transition-colors'
|
isCurrent
|
||||||
)}
|
? 'bg-gray-900 text-white'
|
||||||
aria-current={item.current ? 'page' : undefined}
|
: 'text-gray-300 hover:bg-gray-700 hover:text-white',
|
||||||
>
|
'block rounded-md px-3 py-2 text-base font-medium transition-colors'
|
||||||
{item.name}
|
)}
|
||||||
</Link>
|
aria-current={isCurrent ? 'page' : undefined}
|
||||||
))}
|
>
|
||||||
|
{item.name}
|
||||||
|
</Link>
|
||||||
|
)
|
||||||
|
)
|
||||||
|
})}
|
||||||
</div>
|
</div>
|
||||||
<div className="border-t border-gray-700 pb-3 pt-4">
|
<div className="border-t border-gray-700 pb-3 pt-4">
|
||||||
<div className="flex items-center px-5">
|
{isLoggedIn && (
|
||||||
<div className="flex-shrink-0">
|
<div>
|
||||||
<img
|
<div className="flex items-center px-5">
|
||||||
className="h-10 w-10 rounded-full"
|
<div className="flex-shrink-0">
|
||||||
src="https://images.unsplash.com/photo-1472099645785-5658abf4ff4e?ixlib=rb-1.2.1&ixid=eyJhcHBfaWQiOjEyMDd9&auto=format&fit=facearea&facepad=2&w=256&h=256&q=80"
|
<img
|
||||||
alt=""
|
className="h-10 w-10 rounded-full"
|
||||||
/>
|
src="https://images.unsplash.com/photo-1472099645785-5658abf4ff4e?ixlib=rb-1.2.1&ixid=eyJhcHBfaWQiOjEyMDd9&auto=format&fit=facearea&facepad=2&w=256&h=256&q=80"
|
||||||
|
alt=""
|
||||||
|
/>
|
||||||
|
</div>
|
||||||
|
<div className="ml-3">
|
||||||
|
<div className="text-base font-medium leading-none text-white">User Name</div>
|
||||||
|
<div className="text-sm font-medium leading-none text-gray-400">user@example.com</div>
|
||||||
|
</div>
|
||||||
|
<button
|
||||||
|
type="button"
|
||||||
|
className="relative ml-auto flex-shrink-0 rounded-full bg-gray-800 p-1 text-gray-400 hover:text-white focus:outline-none focus:ring-2 focus:ring-white focus:ring-offset-2 focus:ring-offset-gray-800"
|
||||||
|
>
|
||||||
|
<span className="absolute -inset-1.5" />
|
||||||
|
<span className="sr-only">View notifications</span>
|
||||||
|
<svg className="h-6 w-6" fill="none" viewBox="0 0 24 24" strokeWidth="1.5" stroke="currentColor">
|
||||||
|
<path strokeLinecap="round" strokeLinejoin="round" d="M14.857 17.082a23.848 23.848 0 005.454-1.31A8.967 8.967 0 0118 9.75v-.7V9A6 6 0 006 9v.75a8.967 8.967 0 01-2.312 6.022c1.733.64 3.56 1.085 5.455 1.31m5.714 0a24.255 24.255 0 01-5.714 0m5.714 0a3 3 0 11-5.714 0" />
|
||||||
|
</svg>
|
||||||
|
</button>
|
||||||
|
</div>
|
||||||
|
<div className="mt-3 space-y-1 px-2">
|
||||||
|
<Link href="/profile" className="block rounded-md px-3 py-2 text-base font-medium text-gray-400 hover:bg-gray-700 hover:text-white">
|
||||||
|
Your Profile
|
||||||
|
</Link>
|
||||||
|
<Link href="/settings" className="block rounded-md px-3 py-2 text-base font-medium text-gray-400 hover:bg-gray-700 hover:text-white">
|
||||||
|
Settings
|
||||||
|
</Link>
|
||||||
|
<Link href="/logout" className="block rounded-md px-3 py-2 text-base font-medium text-gray-400 hover:bg-gray-700 hover:text-white">
|
||||||
|
Sign out
|
||||||
|
</Link>
|
||||||
|
</div>
|
||||||
</div>
|
</div>
|
||||||
<div className="ml-3">
|
)}
|
||||||
<div className="text-base font-medium leading-none text-white">User Name</div>
|
|
||||||
<div className="text-sm font-medium leading-none text-gray-400">user@example.com</div>
|
|
||||||
</div>
|
|
||||||
<button
|
|
||||||
type="button"
|
|
||||||
className="relative ml-auto flex-shrink-0 rounded-full bg-gray-800 p-1 text-gray-400 hover:text-white focus:outline-none focus:ring-2 focus:ring-white focus:ring-offset-2 focus:ring-offset-gray-800"
|
|
||||||
>
|
|
||||||
<span className="absolute -inset-1.5" />
|
|
||||||
<span className="sr-only">View notifications</span>
|
|
||||||
<svg className="h-6 w-6" fill="none" viewBox="0 0 24 24" strokeWidth="1.5" stroke="currentColor">
|
|
||||||
<path strokeLinecap="round" strokeLinejoin="round" d="M14.857 17.082a23.848 23.848 0 005.454-1.31A8.967 8.967 0 0118 9.75v-.7V9A6 6 0 006 9v.75a8.967 8.967 0 01-2.312 6.022c1.733.64 3.56 1.085 5.455 1.31m5.714 0a24.255 24.255 0 01-5.714 0m5.714 0a3 3 0 11-5.714 0" />
|
|
||||||
</svg>
|
|
||||||
</button>
|
|
||||||
</div>
|
|
||||||
<div className="mt-3 space-y-1 px-2">
|
|
||||||
<Link href="/profile" className="block rounded-md px-3 py-2 text-base font-medium text-gray-400 hover:bg-gray-700 hover:text-white">
|
|
||||||
Your Profile
|
|
||||||
</Link>
|
|
||||||
<Link href="/settings" className="block rounded-md px-3 py-2 text-base font-medium text-gray-400 hover:bg-gray-700 hover:text-white">
|
|
||||||
Settings
|
|
||||||
</Link>
|
|
||||||
<Link href="/logout" className="block rounded-md px-3 py-2 text-base font-medium text-gray-400 hover:bg-gray-700 hover:text-white">
|
|
||||||
Sign out
|
|
||||||
</Link>
|
|
||||||
</div>
|
|
||||||
</div>
|
</div>
|
||||||
</div>
|
</div>
|
||||||
)}
|
)}
|
||||||
|
|||||||
Reference in New Issue
Block a user