"use client"; import { FC, useEffect, useRef } from "react"; import { observer } from "mobx-react"; import Link from "next/link"; import { useParams } from "next/navigation"; // icons import { ChevronDown, Pencil } from "lucide-react"; // headless ui import { Disclosure, Transition } from "@headlessui/react"; // plane helpers import { useOutsideClickDetector } from "@plane/hooks"; // types import { useTranslation } from "@plane/i18n"; import { Tooltip } from "@plane/propel/tooltip"; import { IUserProfileProjectSegregation } from "@plane/types"; // plane ui import { Loader } from "@plane/ui"; import { cn, renderFormattedDate, getFileURL } from "@plane/utils"; // components import { Logo } from "@/components/common/logo"; // helpers // hooks import { useAppTheme } from "@/hooks/store/use-app-theme"; import { useProject } from "@/hooks/store/use-project"; import { useUser } from "@/hooks/store/user"; import { usePlatformOS } from "@/hooks/use-platform-os"; // components import { ProfileSidebarTime } from "./time"; type TProfileSidebar = { userProjectsData: IUserProfileProjectSegregation | undefined; className?: string; }; export const ProfileSidebar: FC = observer((props) => { const { userProjectsData, className = "" } = props; // refs const ref = useRef(null); // router const { userId, workspaceSlug } = useParams(); // store hooks const { data: currentUser } = useUser(); const { profileSidebarCollapsed, toggleProfileSidebar } = useAppTheme(); const { getProjectById } = useProject(); const { isMobile } = usePlatformOS(); const { t } = useTranslation(); // derived values const userData = userProjectsData?.user_data; useOutsideClickDetector(ref, () => { if (profileSidebarCollapsed === false) { if (window.innerWidth < 768) { toggleProfileSidebar(); } } }); const userDetails = [ { i18n_label: "profile.details.joined_on", value: renderFormattedDate(userData?.date_joined ?? ""), }, { i18n_label: "profile.details.time_zone", value: , }, ]; useEffect(() => { const handleToggleProfileSidebar = () => { if (window && window.innerWidth < 768) { toggleProfileSidebar(true); } if (window && profileSidebarCollapsed && window.innerWidth >= 768) { toggleProfileSidebar(false); } }; window.addEventListener("resize", handleToggleProfileSidebar); handleToggleProfileSidebar(); return () => window.removeEventListener("resize", handleToggleProfileSidebar); }, []); return (
{userProjectsData ? ( <>
{currentUser?.id === userId && (
)} {userData?.display_name}
{userData?.avatar_url && userData?.avatar_url !== "" ? ( {userData?.display_name} ) : (
{userData?.first_name?.[0]}
)}

{userData?.first_name} {userData?.last_name}

({userData?.display_name})
{userDetails.map((detail) => (
{t(detail.i18n_label)}
{detail.value}
))}
{userProjectsData.project_data.map((project, index) => { const projectDetails = getProjectById(project.id); const totalIssues = project.created_issues + project.assigned_issues + project.pending_issues + project.completed_issues; const completedIssuePercentage = project.assigned_issues === 0 ? 0 : Math.round((project.completed_issues / project.assigned_issues) * 100); if (!projectDetails) return null; return ( {({ open }) => (
{projectDetails.name}
{project.assigned_issues > 0 && (
{completedIssuePercentage}%
)}
{totalIssues > 0 && (
)}
Created
{project.created_issues} {t("issues")}
Assigned
{project.assigned_issues} {t("issues")}
Due
{project.pending_issues} {t("issues")}
Completed
{project.completed_issues} {t("issues")}
)} ); })}
) : (
)}
); });