Add a sign-up and login button in the navbar
This commit is contained in:
@@ -6,23 +6,27 @@ import Link from "next/link"
|
||||
import { useState, useEffect } from "react"
|
||||
import { usePathname } from "next/navigation"
|
||||
|
||||
|
||||
interface HeaderProps {
|
||||
className?: string
|
||||
isLoggedIn?: boolean
|
||||
isAdmin?: boolean
|
||||
}
|
||||
|
||||
const navigation = [
|
||||
const leftNavigation = [
|
||||
{ name: 'Home', href: '/', current: false, requiresAuth: false },
|
||||
{ name: 'Pricing', href: '/pricing', current: false, requiresAuth: false },
|
||||
{ name: 'FAQ', href: '/faq', current: false, requiresAuth: false },
|
||||
{ name: 'Dashboard', href: '/dashboard', current: false, requiresAuth: false },
|
||||
{ name: 'Dashboard', href: '/dashboard', current: false, requiresAuth: true },
|
||||
{ name: 'Projects', href: '/projects', current: false, requiresAuth: true },
|
||||
{ name: 'Calendar', href: '/calendar', current: false, requiresAuth: false },
|
||||
{ name: 'Calendar', href: '/calendar', current: false, requiresAuth: true },
|
||||
{ name: 'Reports', href: '/reports', current: false, requiresAuth: true },
|
||||
]
|
||||
|
||||
const rightNavigation = [
|
||||
{ name: 'Sign-up', href: '/sign-up', current: false, requiresAuth: false },
|
||||
{ name: 'Login', href: '/login', current: false, requiresAuth: false },
|
||||
]
|
||||
|
||||
export function Header({ className, isLoggedIn = false, isAdmin = false }: HeaderProps) {
|
||||
const [mobileMenuOpen, setMobileMenuOpen] = useState(false)
|
||||
const [profileOpen, setProfileOpen] = useState(false)
|
||||
@@ -59,7 +63,7 @@ export function Header({ className, isLoggedIn = false, isAdmin = false }: Heade
|
||||
</div>
|
||||
<div className="hidden md:block">
|
||||
<div className="ml-10 flex items-baseline space-x-4">
|
||||
{navigation.map((item) => {
|
||||
{leftNavigation.map((item) => {
|
||||
const isCurrent = activeNavItem === item.href
|
||||
return (
|
||||
(item.requiresAuth ? (isLoggedIn || isAdmin) : true) && (
|
||||
@@ -83,55 +87,75 @@ export function Header({ className, isLoggedIn = false, isAdmin = false }: Heade
|
||||
</div>
|
||||
</div>
|
||||
|
||||
{isLoggedIn && (
|
||||
<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 */}
|
||||
<div className="relative ml-3">
|
||||
<div>
|
||||
<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"
|
||||
onClick={() => setProfileOpen(!profileOpen)}
|
||||
>
|
||||
<span className="absolute -inset-1.5" />
|
||||
<span className="sr-only">Open user menu</span>
|
||||
<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>
|
||||
|
||||
{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 className="hidden md:block">
|
||||
<div className="ml-4 flex items-center md:ml-6">
|
||||
{!isLoggedIn && (
|
||||
<div className="hidden md:block">
|
||||
<div className="ml-10 flex items-baseline space-x-4">
|
||||
<div>
|
||||
{rightNavigation.map((item) => (
|
||||
<Link
|
||||
key={item.name}
|
||||
href={item.href}
|
||||
className='rounded-md px-3 py-2 text-sm font-medium transition-colors text-gray-300 hover:bg-gray-700 hover:text-white'
|
||||
>
|
||||
{item.name}
|
||||
</Link>
|
||||
))}
|
||||
</div>
|
||||
)}
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
)}
|
||||
|
||||
{isLoggedIn && (
|
||||
<div>
|
||||
<button
|
||||
type="button"
|
||||
className="mx-4 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 */}
|
||||
<div className="relative ml-3">
|
||||
<div>
|
||||
<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"
|
||||
onClick={() => setProfileOpen(!profileOpen)}
|
||||
>
|
||||
<span className="absolute -inset-1.5" />
|
||||
<span className="sr-only">Open user menu</span>
|
||||
<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>
|
||||
|
||||
{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 className="-mr-2 flex md:hidden">
|
||||
{/* Mobile menu button */}
|
||||
@@ -160,7 +184,7 @@ export function Header({ className, isLoggedIn = false, isAdmin = false }: Heade
|
||||
{mobileMenuOpen && (
|
||||
<div className="md:hidden">
|
||||
<div className="space-y-1 px-2 pb-3 pt-2 sm:px-3">
|
||||
{navigation.map((item) => {
|
||||
{leftNavigation.map((item) => {
|
||||
const isCurrent = activeNavItem === item.href
|
||||
return (
|
||||
(item.requiresAuth ? (isLoggedIn || isAdmin) : true) && (
|
||||
|
||||
Reference in New Issue
Block a user