-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge branch 'refs/heads/dev' into main
- Loading branch information
Showing
5 changed files
with
168 additions
and
105 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,53 @@ | ||
"use client"; | ||
|
||
import { FC } from "react"; | ||
import Link from "next/link"; | ||
import { usePathname } from "next/navigation"; | ||
import { SignedIn, SignedOut, UserButton } from "@clerk/nextjs"; | ||
import { NavbarContent, NavbarItem } from "@nextui-org/react"; | ||
|
||
interface DesktopNavbarContentProps { | ||
isLoaded: boolean; | ||
menuItems: { name: string; href: string; testId: string }[]; | ||
} | ||
|
||
const DesktopNavbarContent: FC<DesktopNavbarContentProps> = ({ | ||
isLoaded, | ||
menuItems, | ||
}) => { | ||
const pathname = usePathname(); | ||
|
||
return ( | ||
<NavbarContent className="hidden sm:flex gap-4" justify="end"> | ||
{isLoaded && ( | ||
<> | ||
{menuItems.map((link, index) => ( | ||
<NavbarItem | ||
data-testid={`navbar-item-${link.testId}`} | ||
key={`${link.name}-${index}`} | ||
isActive={pathname.includes(link.href)} | ||
> | ||
<Link className="w-full" href={link.href}> | ||
{link.name} | ||
</Link> | ||
</NavbarItem> | ||
))} | ||
<NavbarItem | ||
data-testid="navbar-login" | ||
isActive={pathname.includes("/sign-in")} | ||
className="min-w-[32px]" | ||
> | ||
<SignedIn> | ||
<UserButton /> | ||
</SignedIn> | ||
<SignedOut> | ||
<Link href={"/sign-in"}>Login</Link> | ||
</SignedOut> | ||
</NavbarItem> | ||
</> | ||
)} | ||
</NavbarContent> | ||
); | ||
}; | ||
|
||
export default DesktopNavbarContent; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,25 @@ | ||
import { FC } from "react"; | ||
import Link from "next/link"; | ||
import { NavbarBrand, NavbarContent } from "@nextui-org/react"; | ||
import { merriweather } from "@/app/fonts"; | ||
|
||
interface LogoProps { | ||
setIsMenuOpen: (isOpen: boolean) => void; | ||
} | ||
const Logo: FC<LogoProps> = ({ setIsMenuOpen }) => { | ||
return ( | ||
<NavbarContent> | ||
<NavbarBrand data-testid="navbar-brand"> | ||
<Link href={"/"} onClick={() => setIsMenuOpen(false)}> | ||
<h1 | ||
className={`sm:flex font-extrabold text-xl ${merriweather.className}`} | ||
> | ||
Aaron Curtis Yoga | ||
</h1> | ||
</Link> | ||
</NavbarBrand> | ||
</NavbarContent> | ||
); | ||
}; | ||
|
||
export default Logo; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,70 @@ | ||
"use client"; | ||
|
||
import { FC, useEffect, useState } from "react"; | ||
import { useUser } from "@clerk/nextjs"; | ||
import { Navbar } from "@nextui-org/react"; | ||
import DesktopNavbarContent from "@/_components/Header/DesktopNavbarContent"; | ||
import Logo from "@/_components/Header/Logo"; | ||
import MobileNavbarContent from "@/_components/Header/MobileNavbarContent"; | ||
import { | ||
adminLinks, | ||
authenticatedLinks, | ||
unauthenticatedLinks, | ||
} from "@/_lib/constants"; | ||
|
||
const Header: FC = () => { | ||
const { isSignedIn, isLoaded, user } = useUser(); | ||
const [isMenuOpen, setIsMenuOpen] = useState(false); | ||
const [menuItems, setMenuItems] = useState([...unauthenticatedLinks]); | ||
|
||
useEffect(() => { | ||
if (!isLoaded) return; | ||
|
||
if (isSignedIn) { | ||
const isAdmin = user?.publicMetadata.role === "admin"; | ||
setMenuItems(() => [ | ||
...unauthenticatedLinks, | ||
...authenticatedLinks, | ||
...(isAdmin ? adminLinks : []), | ||
]); | ||
} else { | ||
setMenuItems([...unauthenticatedLinks]); | ||
} | ||
}, [isLoaded, user, isSignedIn]); | ||
|
||
return ( | ||
<Navbar | ||
data-testid="navbar" | ||
onMenuOpenChange={setIsMenuOpen} | ||
isMenuOpen={isMenuOpen} | ||
isBordered | ||
maxWidth="xl" | ||
classNames={{ | ||
item: [ | ||
"flex", | ||
"relative", | ||
"h-full", | ||
"items-center", | ||
"data-[active=true]:after:content-['']", | ||
"data-[active=true]:after:absolute", | ||
"data-[active=true]:after:bottom-0", | ||
"data-[active=true]:after:left-0", | ||
"data-[active=true]:after:right-0", | ||
"data-[active=true]:after:h-[2px]", | ||
"data-[active=true]:after:rounded-[2px]", | ||
"data-[active=true]:after:bg-primary", | ||
], | ||
}} | ||
> | ||
<Logo setIsMenuOpen={setIsMenuOpen} /> | ||
<MobileNavbarContent | ||
isMenuOpen={isMenuOpen} | ||
menuItems={menuItems} | ||
setIsMenuOpen={setIsMenuOpen} | ||
/> | ||
<DesktopNavbarContent isLoaded={isLoaded} menuItems={menuItems} /> | ||
</Navbar> | ||
); | ||
}; | ||
|
||
export default Header; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters