Spaces:
Sleeping
Sleeping
File size: 5,422 Bytes
15225f7 | 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 | import { useState } from 'react'
import { Link, useLocation, useNavigate } from 'react-router-dom'
import { useAuth } from '../contexts/AuthContext'
import {
Zap,
Menu,
X,
LayoutDashboard,
Grid3X3,
Calculator,
FileText,
Users,
LogOut,
DollarSign
} from 'lucide-react'
export default function Navbar() {
const [isOpen, setIsOpen] = useState(false)
const { user, signOut } = useAuth()
const location = useLocation()
const navigate = useNavigate()
const handleSignOut = async () => {
await signOut()
navigate('/')
}
const isActive = (path) => location.pathname === path
const navLinks = user ? [
{ path: '/dashboard', label: 'Dashboard', icon: LayoutDashboard },
{ path: '/grid', label: 'Grid View', icon: Grid3X3 },
{ path: '/roi', label: 'ROI Calculator', icon: Calculator },
{ path: '/audit', label: 'Audit Logs', icon: FileText },
] : [
{ path: '/', label: 'Home', icon: null },
{ path: '/pricing', label: 'Pricing', icon: DollarSign },
{ path: '/about', label: 'About', icon: Users },
]
return (
<nav className="bg-white/95 backdrop-blur shadow-md sticky top-0 z-50">
<div className="max-w-7xl mx-auto px-4 sm:px-6 lg:px-8">
<div className="flex justify-between h-16">
{/* Logo */}
<Link to={user ? '/dashboard' : '/'} className="flex items-center gap-2 hover-lift">
<div className="w-9 h-9 rounded-full bg-gradient-to-br from-primary-500 to-accent-500 flex items-center justify-center glow-ring">
<Zap className="w-5 h-5 text-white" />
</div>
<span className="font-display font-bold text-xl text-dark-800">
Opti<span className="gradient-text">Q</span>
</span>
</Link>
{/* Desktop Navigation */}
<div className="hidden md:flex items-center gap-6">
{navLinks.map((link) => (
<Link
key={link.path}
to={link.path}
className={`flex items-center gap-2 px-3 py-2 rounded-lg transition-colors hover-lift ${
isActive(link.path)
? 'bg-primary-50 text-primary-600 font-medium'
: 'text-dark-600 hover:text-primary-600 hover:bg-dark-50'
}`}
>
{link.icon && <link.icon className="w-4 h-4" />}
{link.label}
</Link>
))}
{user ? (
<div className="flex items-center gap-4 ml-4 pl-4 border-l border-dark-200">
<span className="text-sm text-dark-500">
{user.displayName || user.email}
</span>
<button
onClick={handleSignOut}
className="flex items-center gap-2 px-3 py-2 text-dark-600 hover:text-red-600 rounded-lg hover:bg-red-50 transition-colors hover-lift"
>
<LogOut className="w-4 h-4" />
Sign Out
</button>
</div>
) : (
<div className="flex items-center gap-3 ml-4">
<Link to="/login" className="btn-outline btn text-sm py-2">
Log In
</Link>
<Link to="/signup" className="btn-primary btn text-sm py-2">
Get Started
</Link>
</div>
)}
</div>
{/* Mobile menu button */}
<div className="md:hidden flex items-center">
<button
onClick={() => setIsOpen(!isOpen)}
className="p-2 rounded-lg text-dark-600 hover:bg-dark-100"
>
{isOpen ? <X className="w-6 h-6" /> : <Menu className="w-6 h-6" />}
</button>
</div>
</div>
{/* Mobile Navigation */}
{isOpen && (
<div className="md:hidden pb-4">
<div className="flex flex-col gap-2">
{navLinks.map((link) => (
<Link
key={link.path}
to={link.path}
onClick={() => setIsOpen(false)}
className={`flex items-center gap-2 px-4 py-3 rounded-lg ${
isActive(link.path)
? 'bg-primary-50 text-primary-600 font-medium'
: 'text-dark-600 hover:bg-dark-50'
}`}
>
{link.icon && <link.icon className="w-5 h-5" />}
{link.label}
</Link>
))}
{user ? (
<button
onClick={handleSignOut}
className="flex items-center gap-2 px-4 py-3 text-red-600 hover:bg-red-50 rounded-lg mt-2"
>
<LogOut className="w-5 h-5" />
Sign Out
</button>
) : (
<div className="flex flex-col gap-2 mt-4 pt-4 border-t border-dark-200">
<Link to="/login" className="btn-outline btn text-center">
Log In
</Link>
<Link to="/signup" className="btn-primary btn text-center">
Get Started
</Link>
</div>
)}
</div>
</div>
)}
</div>
</nav>
)
}
|