import { useEffect, useRef } from "react"; import { observer } from "mobx-react-lite"; import Link from "next/link"; import { useRouter } from "next/router"; import useSWR from "swr"; // ui import { Disclosure, Transition } from "@headlessui/react"; // icons import { ChevronDown, Pencil } from "lucide-react"; // plane ui import { Loader, Tooltip } from "@plane/ui"; // fetch-keys import { USER_PROFILE_PROJECT_SEGREGATION } from "constants/fetch-keys"; // helpers import { renderFormattedDate } from "helpers/date-time.helper"; // hooks import { useApplication, useProject, useUser } from "hooks/store"; import useOutsideClickDetector from "hooks/use-outside-click-detector"; import { usePlatformOS } from "hooks/use-platform-os"; // services import { UserService } from "services/user.service"; // components import { ProfileSidebarTime } from "./time"; import { ProjectLogo } from "components/project"; // services const userService = new UserService(); export const ProfileSidebar = observer(() => { // refs const ref = useRef(null); // router const router = useRouter(); const { workspaceSlug, userId } = router.query; // store hooks const { currentUser } = useUser(); const { theme: themeStore } = useApplication(); const { getProjectById } = useProject(); const { isMobile } = usePlatformOS(); const { data: userProjectsData } = useSWR( workspaceSlug && userId ? USER_PROFILE_PROJECT_SEGREGATION(workspaceSlug.toString(), userId.toString()) : null, workspaceSlug && userId ? () => userService.getUserProfileProjectsSegregation(workspaceSlug.toString(), userId.toString()) : null ); useOutsideClickDetector(ref, () => { if (themeStore.profileSidebarCollapsed === false) { if (window.innerWidth < 768) { themeStore.toggleProfileSidebar(); } } }); const userDetails = [ { label: "Joined on", value: renderFormattedDate(userProjectsData?.user_data.date_joined ?? ""), }, { label: "Timezone", value: , }, ]; useEffect(() => { const handleToggleProfileSidebar = () => { if (window && window.innerWidth < 768) { themeStore.toggleProfileSidebar(true); } if (window && themeStore.profileSidebarCollapsed && window.innerWidth >= 768) { themeStore.toggleProfileSidebar(false); } }; window.addEventListener("resize", handleToggleProfileSidebar); handleToggleProfileSidebar(); return () => window.removeEventListener("resize", handleToggleProfileSidebar); }, [themeStore]); return (
{userProjectsData ? ( <>
{currentUser?.id === userId && (
)} {userProjectsData.user_data?.display_name}
{userProjectsData.user_data?.avatar && userProjectsData.user_data?.avatar !== "" ? ( {userProjectsData.user_data?.display_name} ) : (
{userProjectsData.user_data?.first_name?.[0]}
)}

{userProjectsData.user_data?.first_name} {userProjectsData.user_data?.last_name}

({userProjectsData.user_data?.display_name})
{userDetails.map((detail) => (
{detail.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} Issues
Assigned
{project.assigned_issues} Issues
Due
{project.pending_issues} Issues
Completed
{project.completed_issues} Issues
)} ); })}
) : (
)}
); });