import { useRouter } from "next/router"; import Link from "next/link"; import useSWR from "swr"; import { Disclosure, Transition } from "@headlessui/react"; import { observer } from "mobx-react-lite"; // hooks import { useApplication, useUser } from "hooks/store"; // services import { UserService } from "services/user.service"; // components import { ProfileSidebarTime } from "./time"; // ui import { Loader, Tooltip } from "@plane/ui"; // icons import { ChevronDown, Pencil } from "lucide-react"; // helpers import { renderFormattedDate } from "helpers/date-time.helper"; import { renderEmoji } from "helpers/emoji.helper"; // fetch-keys import { USER_PROFILE_PROJECT_SEGREGATION } from "constants/fetch-keys"; import useOutsideClickDetector from "hooks/use-outside-click-detector"; import { useEffect, useRef } from "react"; // services const userService = new UserService(); export const ProfileSidebar = observer(() => { // router const router = useRouter(); const { workspaceSlug, userId } = router.query; // store hooks const { currentUser } = useUser(); const { theme: themStore } = useApplication(); const ref = useRef(null); 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 (themStore.profileSidebarCollapsed === false) { if (window.innerWidth < 768) { themStore.toggleProfileSidebar(); } } }); const userDetails = [ { label: "Joined on", value: renderFormattedDate(userProjectsData?.user_data.date_joined ?? ""), }, { label: "Timezone", value: , }, ]; useEffect(() => { const handleToggleProfileSidebar = () => { if (window && window.innerWidth < 768) { themStore.toggleProfileSidebar(true); } if (window && themStore.profileSidebarCollapsed && window.innerWidth >= 768) { themStore.toggleProfileSidebar(false); } }; window.addEventListener("resize", handleToggleProfileSidebar); handleToggleProfileSidebar(); return () => window.removeEventListener("resize", handleToggleProfileSidebar); }, [themStore]); 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 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); return ( {({ open }) => (
{project.emoji ? (
{renderEmoji(project.emoji)}
) : project.icon_prop ? (
{renderEmoji(project.icon_prop)}
) : (
{project?.name.charAt(0)}
)}
{project.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
)} ); })}
) : (
)}
); });