import { Fragment, useEffect } from "react"; import { Disclosure, Menu, Transition } from "@headlessui/react"; import Link from "next/link"; import { useRouter } from "next/router"; import { signOut, useSession } from "next-auth/react"; import avatarFromInitials from "avatar-from-initials"; import { toast, Toaster } from "react-hot-toast"; import { Bars3Icon, BellIcon, XMarkIcon, UserCircleIcon, ArrowRightOnRectangleIcon, DocumentTextIcon, ChartBarIcon, WrenchIcon, } from "@heroicons/react/24/outline"; import Logo from "./logo"; let user: { id?: number | undefined; name?: string | null; email?: string | null; image?: string | null; }; const navigation = [ { name: "Dashboard", href: "/dashboard", current: false, icon: ChartBarIcon, }, { name: "Documents", href: "/documents", current: false, icon: DocumentTextIcon, }, { name: "Settings", href: "/settings", current: true, icon: WrenchIcon, }, ]; const userNavigation = [ { name: "Your Profile", href: "/settings/profile", icon: UserCircleIcon }, { name: "Sign out", href: "", click: async (e: any) => { e.preventDefault(); const res: any = await toast.promise( signOut({ callbackUrl: "/login" }), { loading: "Logging out...", success: "Your are logged out.", error: "Could not log out :/", }, { style: { minWidth: "200px", }, success: { duration: 10000, }, } ); }, icon: ArrowRightOnRectangleIcon, }, ]; function classNames(...classes: any) { return classes.filter(Boolean).join(" "); } export default function TopNavigation() { const session = useSession(); useEffect(() => { user = { ...session.data?.user }; }); const router = useRouter(); navigation.forEach((element) => { element.current = router.route.endsWith("/" + element.href.split("/")[1]); }); return ( <> {({ open }) => ( <> {navigation.map((item) => ( {item.name} ))} {user?.name || ""} {user?.email} Open user menu {userNavigation.map((item) => ( {({ active }) => ( {item.name} )} ))} {/* Mobile menu button */} Open main menu {open ? ( ) : ( )} {navigation.map((item) => ( {item.name} ))} {user?.name || ""} {user?.email} {userNavigation.map((item) => ( {item.name} ))} > )} {/* */} > ); }
{user?.name || ""}
{user?.email}