'use client'; import { useState, useContext } from 'react'; import { usePathname } from 'next/navigation'; import Image from 'next/image'; import { Navbar, NavbarContent, NavbarMenu, NavbarMenuToggle, NavbarBrand, NavbarItem, Link as NextUiLink, ListboxItem, Listbox, } from '@heroui/react'; import { ArrowRightFromLine, ArrowRightToLine, File, Globe, MoveUpRight, PenTool, Settings } from 'lucide-react'; import DropdownAccount from './DropdownAccount'; import DropdownLanguage from './DropdownLanguage'; import { ThemeSwitch } from '@/components/ThemeSwitch'; import { GithubIcon } from '@/components/icons'; import { locales } from '@/config/selection'; import { Link, useRouter } from '@/src/i18n/routing'; import { TokenContext } from '@/utils/TokenProvider'; import UserAvatar from '@/components/UserAvatar'; import { LocaleCodeType } from '@/types/locale'; import Config from '@/config/config'; type NabbarMenuMessages = { projects: string; admin: string; docs: string; roadmap: string; account: string; profileSettings: string; signUp: string; signIn: string; signOut: string; links: string; languages: string; }; type Props = { messages: NabbarMenuMessages; locale: LocaleCodeType; }; export default function HeaderNavbarMenu({ messages, locale }: Props) { const [isMenuOpen, setIsMenuOpen] = useState(false); const context = useContext(TokenContext); const commonLinks = [ { uid: 'projects', href: '/projects', label: messages.projects, isExternal: false, }, ]; if (Config.isDemoSite) { commonLinks.push( { uid: 'docs', href: 'https://kimatata.github.io/unittcms/docs/getstarted/selfhost', label: messages.docs, isExternal: true, }, { uid: 'roadmap', href: 'https://kimatata.github.io/unittcms/docs/roadmap/', label: messages.roadmap, isExternal: true, } ); } const router = useRouter(); const pathname = usePathname(); async function changeLocale(nextLocale: string) { let newPathname; if (pathname.length < 4) { // when root path router.push('/', { locale: nextLocale }); } else { // when not root path, trim first "/en" from pathname = "/en/projects" newPathname = pathname.slice(locale.length + 1); router.push(newPathname, { locale: nextLocale }); } } return ( Logo

UnitTCMS

{commonLinks.map((link) => link.isExternal ? ( {link.label} ) : ( {link.label} ) )} {context.isAdmin() && ( {messages.admin} )}
{}} />
setIsMenuOpen(!isMenuOpen)} />

{messages.links}

{commonLinks.map((link) => link.isExternal ? ( } onPress={() => { window.open(link.href, '_blank'); setIsMenuOpen(false); }} /> ) : ( } onPress={() => { router.push(link.href, { locale: locale }); setIsMenuOpen(false); }} /> ) )}

{messages.account}

{context.isSignedIn() ? ( } onPress={() => { router.push('/account', { locale: locale }); setIsMenuOpen(false); }} /> } onPress={() => { router.push('/account/settings', { locale: locale }); setIsMenuOpen(false); }} /> } onPress={() => { context.setToken({ access_token: '', expires_at: 0, user: null, }); context.removeTokenFromLocalStorage(); router.push(`/account/signin`, { locale: locale }); setIsMenuOpen(false); }} /> ) : ( } title={messages.signIn} onPress={() => { router.push('/account/signin', { locale: locale }); setIsMenuOpen(false); }} /> } onPress={() => { router.push('/account/signup', { locale: locale }); setIsMenuOpen(false); }} /> )}

{messages.languages}

{locales.map((entry) => ( } title={entry.name} onPress={() => { changeLocale(entry.code); setIsMenuOpen(false); }} /> ))}
); }