From 51b81c40af4f4c33a7ac14d904b2bcb4979725fb Mon Sep 17 00:00:00 2001 From: kbe Date: Thu, 14 Aug 2025 16:51:20 +0200 Subject: [PATCH] Add conditional link for logged in user and administrator --- components/ui/header.tsx | 231 +++++++++++++++++++++------------------ 1 file changed, 123 insertions(+), 108 deletions(-) diff --git a/components/ui/header.tsx b/components/ui/header.tsx index 0153a1a..2d5dd9c 100644 --- a/components/ui/header.tsx +++ b/components/ui/header.tsx @@ -7,16 +7,21 @@ import { useState } from "react" interface HeaderProps { className?: string + isLoggedIn?: boolean + isAdmin?: boolean } const navigation = [ - { name: 'Dashboard', href: '/dashboard', current: true }, - { name: 'Projects', href: '/projects', current: false }, - { name: 'Calendar', href: '/calendar', current: false }, - { name: 'Reports', href: '/reports', current: false }, + { 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: '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 [profileOpen, setProfileOpen] = useState(false) @@ -37,72 +42,76 @@ export function Header({ className }: HeaderProps) {
{navigation.map((item) => ( - - {item.name} - + (item.requiresAuth ? (isLoggedIn || isAdmin) : true) && ( + + {item.name} + + ) ))}
- -
-
- - {/* Profile dropdown */} -
-
- -
+ {isLoggedIn && ( +
+
+ - {profileOpen && ( -
- - Your Profile - - - Settings - - - Sign out - + {/* Profile dropdown */} +
+
+
- )} + + {profileOpen && ( +
+ + Your Profile + + + Settings + + + Sign out + +
+ )} +
-
- + )} +
{/* Mobile menu button */} +
+
+ + Your Profile + + + Settings + + + Sign out + +
-
-
User Name
-
user@example.com
-
- -
-
- - Your Profile - - - Settings - - - Sign out - -
+ )}
)}