import { mutate } from "swr"; import Link from "next/link"; import { useRouter } from "next/router"; import { observer } from "mobx-react-lite"; import { useTheme } from "next-themes"; import { Activity, ChevronLeft, CircleUser, KeyRound, LogOut, MoveLeft, Plus, Settings2, UserPlus } from "lucide-react"; // mobx store import { useMobxStore } from "lib/mobx/store-provider"; // ui import { Tooltip } from "@plane/ui"; // hooks import useToast from "hooks/use-toast"; import { useState } from "react"; const PROFILE_ACTION_LINKS = [ { key: "profile", label: "Profile", href: `/profile`, Icon: CircleUser, }, { key: "change-password", label: "Change password", href: `/profile/change-password`, Icon: KeyRound, }, { key: "activity", label: "Activity", href: `/profile/activity`, Icon: Activity, }, { key: "preferences", label: "Preferences", href: `/profile/preferences`, Icon: Settings2, }, ]; const WORKSPACE_ACTION_LINKS = [ { key: "create-workspace", Icon: Plus, label: "Create workspace", href: "/create-workspace", }, { key: "invitations", Icon: UserPlus, label: "Invitations", href: "/invitations", }, ]; export const ProfileLayoutSidebar = observer(() => { // states const [isSigningOut, setIsSigningOut] = useState(false); // router const router = useRouter(); // next themes const { setTheme } = useTheme(); // toast const { setToastAlert } = useToast(); const { theme: { sidebarCollapsed, toggleSidebar }, workspace: { workspaces }, user: { currentUser, currentUserSettings, signOut }, } = useMobxStore(); // redirect url for normal mode const redirectWorkspaceSlug = currentUserSettings?.workspace?.last_workspace_slug || currentUserSettings?.workspace?.fallback_workspace_slug || ""; const handleSignOut = async () => { setIsSigningOut(true); await signOut() .then(() => { mutate("CURRENT_USER_DETAILS", null); setTheme("system"); router.push("/"); }) .catch(() => setToastAlert({ type: "error", title: "Error!", message: "Failed to sign out. Please try again.", }) ) .finally(() => setIsSigningOut(false)); }; return (
{!sidebarCollapsed && (

Profile settings

)}
{!sidebarCollapsed && (
Your account
)}
{PROFILE_ACTION_LINKS.map((link) => { if (link.key === "change-password" && currentUser?.is_password_autoset) return null; return (
{} {!sidebarCollapsed && link.label}
); })}
{!sidebarCollapsed && (
Workspaces
)} {workspaces && workspaces.length > 0 && (
{workspaces.map((workspace) => ( {workspace?.logo && workspace.logo !== "" ? ( Workspace Logo ) : ( workspace?.name?.charAt(0) ?? "..." )} {!sidebarCollapsed && (

{workspace.name}

)}
))}
)}
{WORKSPACE_ACTION_LINKS.map((link) => (
{} {!sidebarCollapsed && link.label}
))}
); });