import { Fragment, useEffect, useState } from "react"; import Link from "next/link"; import { useRouter } from "next/router"; import { getUser } from "@documenso/lib/api"; import Logo from "./logo"; import { Disclosure, Menu, Transition } from "@headlessui/react"; import { ArrowRightOnRectangleIcon, Bars3Icon, BellIcon, ChartBarIcon, DocumentTextIcon, UserCircleIcon, WrenchIcon, XMarkIcon, } from "@heroicons/react/24/outline"; import avatarFromInitials from "avatar-from-initials"; import { signOut, useSession } from "next-auth/react"; import { toast } from "react-hot-toast"; const navigation = [ { name: "Dashboard", href: "/dashboard", current: false, icon: ChartBarIcon, }, { name: "Documents", href: "/documents", current: false, icon: DocumentTextIcon, }, { name: "Settings", href: "/settings/profile", 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(" "); } type UserType = { id?: number | undefined; name?: string | null; email?: string | null; image?: string | null; }; export default function TopNavigation() { const router = useRouter(); const session = useSession(); const [user, setUser] = useState({ email: "", name: "", }); useEffect(() => { getUser().then((res) => { res.json().then((j: any) => { setUser(j); }); }); }, [session]); navigation.forEach((element) => { element.current = router.route.endsWith("/" + element.href.split("/")[1]) || router.route.includes(element.href.split("/")[1]); }); return ( <> {({ open, close }) => ( <> {navigation.map((item) => ( {item.name} ))} { document?.getElementById("mb")?.click(); }} className="hidden cursor-pointer px-3 hover:bg-gray-200 sm:ml-6 sm:flex sm:items-center"> {user?.name || ""} {user?.email} Open user menu {userNavigation.map((item) => ( {({ active }) => ( {item.name} )} ))} {/* Mobile menu button */} Open main menu {open ? ( ) : ( )} {navigation.map((item) => ( { close(); }}> {item.name} ))} {user?.name || ""} {user?.email} {userNavigation.map((item) => ( { close(); } : item.click } href={item.href} className="block px-4 py-2 text-base font-medium text-gray-500 hover:bg-gray-100 hover:text-gray-800"> {item.name} ))} > )} {/* */} > ); }
{user?.name || ""}
{user?.email}