"use client"; import { useEffect, useRef, useState } from "react"; import { observer } from "mobx-react"; import Link from "next/link"; import { usePathname } from "next/navigation"; // icons import { ChevronLeft, LogOut, MoveLeft, Activity, Bell, CircleUser, KeyRound, Settings2, CirclePlus, Mails, } from "lucide-react"; // plane imports import { PROFILE_ACTION_LINKS } from "@plane/constants"; import { useOutsideClickDetector } from "@plane/hooks"; import { useTranslation } from "@plane/i18n"; import { TOAST_TYPE, setToast } from "@plane/propel/toast"; import { Tooltip } from "@plane/propel/tooltip"; import { cn, getFileURL } from "@plane/utils"; // components import { SidebarNavItem } from "@/components/sidebar/sidebar-navigation"; // hooks import { useAppTheme } from "@/hooks/store/use-app-theme"; import { useWorkspace } from "@/hooks/store/use-workspace"; import { useUser, useUserSettings } from "@/hooks/store/user"; import { usePlatformOS } from "@/hooks/use-platform-os"; const WORKSPACE_ACTION_LINKS = [ { key: "create_workspace", Icon: CirclePlus, i18n_label: "create_workspace", href: "/create-workspace", }, { key: "invitations", Icon: Mails, i18n_label: "workspace_invites", href: "/invitations", }, ]; const ProjectActionIcons = ({ type, size, className = "" }: { type: string; size?: number; className?: string }) => { const icons = { profile: CircleUser, security: KeyRound, activity: Activity, preferences: Settings2, notifications: Bell, "api-tokens": KeyRound, }; if (type === undefined) return null; const Icon = icons[type as keyof typeof icons]; if (!Icon) return null; return ; }; export const ProfileLayoutSidebar = observer(() => { // states const [isSigningOut, setIsSigningOut] = useState(false); // router const pathname = usePathname(); // store hooks const { sidebarCollapsed, toggleSidebar } = useAppTheme(); const { data: currentUser, signOut } = useUser(); const { data: currentUserSettings } = useUserSettings(); const { workspaces } = useWorkspace(); const { isMobile } = usePlatformOS(); const { t } = useTranslation(); const workspacesList = Object.values(workspaces ?? {}); // redirect url for normal mode const redirectWorkspaceSlug = currentUserSettings?.workspace?.last_workspace_slug || currentUserSettings?.workspace?.fallback_workspace_slug || ""; const ref = useRef(null); useOutsideClickDetector(ref, () => { if (sidebarCollapsed === false) { if (window.innerWidth < 768) { toggleSidebar(); } } }); useEffect(() => { const handleResize = () => { if (window.innerWidth <= 768) { toggleSidebar(true); } }; handleResize(); window.addEventListener("resize", handleResize); return () => { window.removeEventListener("resize", handleResize); }; }, [toggleSidebar]); const handleItemClick = () => { if (window.innerWidth < 768) { toggleSidebar(); } }; const handleSignOut = async () => { setIsSigningOut(true); await signOut() .catch(() => setToast({ type: TOAST_TYPE.ERROR, title: t("sign_out.toast.error.title"), message: t("sign_out.toast.error.message"), }) ) .finally(() => setIsSigningOut(false)); }; return ( {!sidebarCollapsed && ( {t("profile_settings")} )} {!sidebarCollapsed && ( {t("your_account")} )} {PROFILE_ACTION_LINKS.map((link) => { if (link.key === "change-password" && currentUser?.is_password_autoset) return null; return ( {!sidebarCollapsed && {t(link.i18n_label)}} ); })} {!sidebarCollapsed && ( {t("workspaces")} )} {workspacesList && workspacesList.length > 0 && ( {workspacesList.map((workspace) => ( {workspace?.logo_url && workspace.logo_url !== "" ? ( ) : ( (workspace?.name?.charAt(0) ?? "...") )} {!sidebarCollapsed && ( {workspace.name} )} ))} )} {WORKSPACE_ACTION_LINKS.map((link) => ( {} {!sidebarCollapsed && t(link.i18n_label)} ))} {!sidebarCollapsed && {isSigningOut ? `${t("signing_out")}...` : t("sign_out")}} toggleSidebar()} > toggleSidebar()} > ); });
{t(link.i18n_label)}
{workspace.name}