import { Fragment } from "react"; import { useRouter } from "next/router"; import Link from "next/link"; // next-themes import { useTheme } from "next-themes"; // headless ui import { Menu, Transition } from "@headlessui/react"; // hooks import useUser from "hooks/use-user"; import useThemeHook from "hooks/use-theme"; import useWorkspaces from "hooks/use-workspaces"; import useToast from "hooks/use-toast"; // services import userService from "services/user.service"; import authenticationService from "services/authentication.service"; // components import { Avatar, Loader } from "components/ui"; // icons import { CheckIcon, PlusIcon } from "@heroicons/react/24/outline"; // helpers import { truncateText } from "helpers/string.helper"; // 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; const { user, mutateUser } = useUser(); const { collapsed: sidebarCollapse } = useThemeHook(); const { setTheme } = useTheme(); const { setToastAlert } = useToast(); const { activeWorkspace, workspaces } = useWorkspaces(); const handleWorkspaceNavigation = (workspace: IWorkspace) => { userService .updateUser({ last_workspace_id: workspace?.id, }) .then(() => { mutateUser(); router.push(`/${workspace.slug}/`); }) .catch(() => setToastAlert({ type: "error", title: "Error!", message: "Failed to navigate to the workspace. Please try again.", }) ); }; const handleSignOut = async () => { await authenticationService .signOut() .then(() => { mutateUser(undefined); router.push("/"); setTheme("dark"); }) .catch(() => setToastAlert({ type: "error", title: "Error!", message: "Failed to sign out. Please try again.", }) ); }; return (
); };