import { Fragment } from "react"; import { Menu, Transition } from "@headlessui/react"; import { useRouter } from "next/router"; import Image from "next/image"; import Link from "next/link"; import { CheckIcon, ChevronDownIcon, PlusIcon } from "@heroicons/react/24/outline"; // hooks import useUser from "hooks/use-user"; import useTheme from "hooks/use-theme"; import useWorkspaces from "hooks/use-workspaces"; // services import userService from "services/user.service"; import authenticationService from "services/authentication.service"; // components import { Loader } from "components/ui"; // types import { IWorkspace } from "types"; // Static Data const userLinks = (workspaceSlug: string) => [ { name: "Workspace Settings", href: `/${workspaceSlug}/settings`, }, { name: "Workspace Invites", href: "/invitations", }, { name: "My Profile", href: `/${workspaceSlug}/me/profile`, }, ]; export const WorkspaceSidebarDropdown = () => { const router = useRouter(); const { workspaceSlug } = router.query; // fetching user details const { user, mutateUser } = useUser(); // fetching theme context const { collapsed: sidebarCollapse } = useTheme(); // fetching workspaces const { activeWorkspace, workspaces } = useWorkspaces(); const handleWorkspaceNavigation = (workspace: IWorkspace) => { userService .updateUser({ last_workspace_id: workspace?.id, }) .then(() => { mutateUser(); router.push(`/${workspace.slug}/`); }) .catch((err) => console.error(err)); }; const handleSignOut = async () => { await authenticationService .signOut() .then((response) => { console.log("user signed out", response); }) .catch((error) => { console.log("Failed to sign out", error); }) .finally(() => { mutateUser(); router.push("/signin"); }); }; return (
{activeWorkspace?.logo && activeWorkspace.logo !== "" ? ( Workspace Logo ) : ( activeWorkspace?.name?.charAt(0) ?? "..." )}
{!sidebarCollapse && (

{activeWorkspace?.name ? activeWorkspace.name.length > 17 ? `${activeWorkspace.name.substring(0, 17)}...` : activeWorkspace.name : "Loading..."}

)}
{!sidebarCollapse && (
)}
{user?.email} Workspace {workspaces ? (
{workspaces.length > 0 ? ( workspaces.map((workspace) => ( {({ active }) => ( )} )) ) : (

No workspace found!

)} { router.push("/create-workspace"); }} className="flex w-full items-center gap-1 text-sm text-gray-600" > Create Workspace
) : (
)}
{userLinks(workspaceSlug as string).map((link, index) => ( {link.name} ))}
Sign out
); };