[WEB-2025] chore: profile page enhancements (#5209)

* chore: user layout and header updated

* chore: user page sidebar improvement

* fix: your work redirection

* fix: profile section mobile navigation dropdown

* chore: profile layout improvement

* chore: profile header improvement

* fix: profile section header improvement

* fix: app sidebar your work active indicator

* chore: profile sidebar improvement

* chore: user menu code refactor

* chore: header code refactor

* chore: user menu code refactor

* fix: build error
This commit is contained in:
Anmol Singh Bhatia 2024-07-24 17:52:12 +05:30 committed by GitHub
parent 58f203dd38
commit 4d978c1a8c
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
8 changed files with 117 additions and 78 deletions

View file

@ -42,7 +42,7 @@ export type TBaseIssue = {
export type TIssue = TBaseIssue & { export type TIssue = TBaseIssue & {
description_html?: string; description_html?: string;
is_subscribed?: boolean; is_subscribed?: boolean;
parent?: Partial<TIssue>; parent?: partial<TIssue>;
issue_reactions?: TIssueReaction[]; issue_reactions?: TIssueReaction[];
issue_attachment?: TIssueAttachment[]; issue_attachment?: TIssueAttachment[];
issue_link?: TIssueLink[]; issue_link?: TIssueLink[];

View file

@ -6,44 +6,53 @@ import { observer } from "mobx-react";
import Link from "next/link"; import Link from "next/link";
import { useParams } from "next/navigation"; import { useParams } from "next/navigation";
import { ChevronDown, PanelRight } from "lucide-react"; import { ChevronDown, PanelRight } from "lucide-react";
import { IUserProfileProjectSegregation } from "@plane/types";
import { Breadcrumbs, CustomMenu } from "@plane/ui"; import { Breadcrumbs, CustomMenu } from "@plane/ui";
import { BreadcrumbLink } from "@/components/common"; import { BreadcrumbLink } from "@/components/common";
// components // components
import { ProfileIssuesFilter } from "@/components/profile";
import { PROFILE_ADMINS_TAB, PROFILE_VIEWER_TAB } from "@/constants/profile"; import { PROFILE_ADMINS_TAB, PROFILE_VIEWER_TAB } from "@/constants/profile";
import { EUserWorkspaceRoles } from "@/constants/workspace";
import { cn } from "@/helpers/common.helper"; import { cn } from "@/helpers/common.helper";
import { useAppTheme, useUser } from "@/hooks/store"; import { useAppTheme, useUser } from "@/hooks/store";
type TUserProfileHeader = { type TUserProfileHeader = {
userProjectsData: IUserProfileProjectSegregation | undefined;
type?: string | undefined; type?: string | undefined;
showProfileIssuesFilter?: boolean;
}; };
export const UserProfileHeader: FC<TUserProfileHeader> = observer((props) => { export const UserProfileHeader: FC<TUserProfileHeader> = observer((props) => {
const { type = undefined } = props; const { userProjectsData, type = undefined, showProfileIssuesFilter } = props;
// router // router
const { workspaceSlug, userId } = useParams(); const { workspaceSlug, userId } = useParams();
// store hooks // store hooks
const { toggleProfileSidebar, profileSidebarCollapsed } = useAppTheme(); const { toggleProfileSidebar, profileSidebarCollapsed } = useAppTheme();
const { const {
membership: { currentWorkspaceRole }, membership: { currentWorkspaceRole },
data: currentUser,
} = useUser(); } = useUser();
// derived values // derived values
const AUTHORIZED_ROLES = [20, 15, 10]; const isAuthorized = !!currentWorkspaceRole && currentWorkspaceRole >= EUserWorkspaceRoles.VIEWER;
if (!currentWorkspaceRole) return null; if (!currentWorkspaceRole) return null;
const isAuthorized = AUTHORIZED_ROLES.includes(currentWorkspaceRole);
const tabsList = isAuthorized ? [...PROFILE_VIEWER_TAB, ...PROFILE_ADMINS_TAB] : PROFILE_VIEWER_TAB; const tabsList = isAuthorized ? [...PROFILE_VIEWER_TAB, ...PROFILE_ADMINS_TAB] : PROFILE_VIEWER_TAB;
const userName = `${userProjectsData?.user_data?.first_name} ${userProjectsData?.user_data?.last_name}`;
const isCurrentUser = currentUser?.id === userId;
const breadcrumbLabel = `${isCurrentUser ? "Your" : userName} Activity`;
return ( return (
<div className="relative z-10 flex h-[3.75rem] w-full flex-shrink-0 flex-row items-center justify-between gap-x-2 gap-y-4 bg-custom-sidebar-background-100 p-4"> <div className="relative z-10 flex h-[3.75rem] w-full flex-shrink-0 flex-row items-center justify-between gap-x-2 gap-y-4 bg-custom-sidebar-background-100 p-4">
<div className="flex w-full flex-grow items-center gap-2 overflow-ellipsis whitespace-nowrap"> <div className="flex w-full flex-grow items-center gap-2 overflow-ellipsis whitespace-nowrap">
<div className="flex w-full justify-between"> <div className="flex w-full justify-between">
<Breadcrumbs> <Breadcrumbs>
<Breadcrumbs.BreadcrumbItem <Breadcrumbs.BreadcrumbItem type="text" link={<BreadcrumbLink label={breadcrumbLabel} disableTooltip />} />
type="text"
link={<BreadcrumbLink href="/profile" label="Activity Overview" />}
/>
</Breadcrumbs> </Breadcrumbs>
<div className="hidden md:flex md:items-center">{showProfileIssuesFilter && <ProfileIssuesFilter />}</div>
<div className="flex gap-4 md:hidden"> <div className="flex gap-4 md:hidden">
<CustomMenu <CustomMenu
maxHeight={"md"} maxHeight={"md"}

View file

@ -2,19 +2,25 @@
import { observer } from "mobx-react"; import { observer } from "mobx-react";
import { useParams, usePathname } from "next/navigation"; import { useParams, usePathname } from "next/navigation";
import useSWR from "swr";
// components // components
import { AppHeader, ContentWrapper } from "@/components/core"; import { AppHeader, ContentWrapper } from "@/components/core";
import { ProfileSidebar } from "@/components/profile"; import { ProfileSidebar } from "@/components/profile";
// constants // constants
import { USER_PROFILE_PROJECT_SEGREGATION } from "@/constants/fetch-keys";
import { PROFILE_ADMINS_TAB, PROFILE_VIEWER_TAB } from "@/constants/profile"; import { PROFILE_ADMINS_TAB, PROFILE_VIEWER_TAB } from "@/constants/profile";
import { EUserWorkspaceRoles } from "@/constants/workspace"; import { EUserWorkspaceRoles } from "@/constants/workspace";
// hooks // hooks
import { useUser } from "@/hooks/store"; import { useUser } from "@/hooks/store";
import useSize from "@/hooks/use-window-size";
// local components // local components
import { UserService } from "@/services/user.service";
import { UserProfileHeader } from "./header"; import { UserProfileHeader } from "./header";
import { ProfileIssuesMobileHeader } from "./mobile-header"; import { ProfileIssuesMobileHeader } from "./mobile-header";
import { ProfileNavbar } from "./navbar"; import { ProfileNavbar } from "./navbar";
const userService = new UserService();
type Props = { type Props = {
children: React.ReactNode; children: React.ReactNode;
}; };
@ -30,6 +36,16 @@ const UseProfileLayout: React.FC<Props> = observer((props) => {
const { const {
membership: { currentWorkspaceRole }, membership: { currentWorkspaceRole },
} = useUser(); } = useUser();
const windowSize = useSize();
const isSmallerScreen = windowSize[0] >= 768;
const { data: userProjectsData } = useSWR(
workspaceSlug && userId ? USER_PROFILE_PROJECT_SEGREGATION(workspaceSlug.toString(), userId.toString()) : null,
workspaceSlug && userId
? () => userService.getUserProfileProjectsSegregation(workspaceSlug.toString(), userId.toString())
: null
);
// derived values // derived values
const isAuthorized = currentWorkspaceRole && AUTHORIZED_ROLES.includes(currentWorkspaceRole); const isAuthorized = currentWorkspaceRole && AUTHORIZED_ROLES.includes(currentWorkspaceRole);
const isAuthorizedPath = const isAuthorizedPath =
@ -43,25 +59,36 @@ const UseProfileLayout: React.FC<Props> = observer((props) => {
<> <>
{/* Passing the type prop from the current route value as we need the header as top most component. {/* Passing the type prop from the current route value as we need the header as top most component.
TODO: We are depending on the route path to handle the mobile header type. If the path changes, this logic will break. */} TODO: We are depending on the route path to handle the mobile header type. If the path changes, this logic will break. */}
<div className="h-full w-full md:flex md:overflow-hidden">
<div className="h-full w-full md:overflow-hidden">
<AppHeader <AppHeader
header={<UserProfileHeader type={currentTab?.label} />} header={
<UserProfileHeader
type={currentTab?.label}
userProjectsData={userProjectsData}
showProfileIssuesFilter={isIssuesTab}
/>
}
mobileHeader={isIssuesTab && <ProfileIssuesMobileHeader />} mobileHeader={isIssuesTab && <ProfileIssuesMobileHeader />}
/> />
<ContentWrapper> <ContentWrapper>
<div className="h-full w-full flex md:overflow-hidden"> <div className="h-full w-full flex flex-row md:flex-col md:overflow-hidden">
<div className="flex w-full flex-col md:h-full md:overflow-hidden"> <div className="flex w-full flex-col md:h-full md:overflow-hidden">
<ProfileNavbar isAuthorized={!!isAuthorized} showProfileIssuesFilter={isIssuesTab} /> <ProfileNavbar isAuthorized={!!isAuthorized} />
{isAuthorized || !isAuthorizedPath ? ( {isAuthorized || !isAuthorizedPath ? (
<div className={`w-full overflow-hidden md:h-full`}>{children}</div> <div className={`w-full overflow-hidden h-full`}>{children}</div>
) : ( ) : (
<div className="grid h-full w-full place-items-center text-custom-text-200"> <div className="grid h-full w-full place-items-center text-custom-text-200">
You do not have the permission to access this page. You do not have the permission to access this page.
</div> </div>
)} )}
</div> </div>
<ProfileSidebar /> {!isSmallerScreen && <ProfileSidebar userProjectsData={userProjectsData} />}
</div> </div>
</ContentWrapper> </ContentWrapper>
</div>
{isSmallerScreen && <ProfileSidebar userProjectsData={userProjectsData} />}
</div>
</> </>
); );
}); });

View file

@ -4,17 +4,15 @@ import Link from "next/link";
import { useParams, usePathname } from "next/navigation"; import { useParams, usePathname } from "next/navigation";
// components // components
import { ProfileIssuesFilter } from "@/components/profile";
// constants // constants
import { PROFILE_ADMINS_TAB, PROFILE_VIEWER_TAB } from "@/constants/profile"; import { PROFILE_ADMINS_TAB, PROFILE_VIEWER_TAB } from "@/constants/profile";
type Props = { type Props = {
isAuthorized: boolean; isAuthorized: boolean;
showProfileIssuesFilter?: boolean;
}; };
export const ProfileNavbar: React.FC<Props> = (props) => { export const ProfileNavbar: React.FC<Props> = (props) => {
const { isAuthorized, showProfileIssuesFilter } = props; const { isAuthorized } = props;
const { workspaceSlug, userId } = useParams(); const { workspaceSlug, userId } = useParams();
const pathname = usePathname(); const pathname = usePathname();
@ -22,13 +20,13 @@ const pathname = usePathname();
const tabsList = isAuthorized ? [...PROFILE_VIEWER_TAB, ...PROFILE_ADMINS_TAB] : PROFILE_VIEWER_TAB; const tabsList = isAuthorized ? [...PROFILE_VIEWER_TAB, ...PROFILE_ADMINS_TAB] : PROFILE_VIEWER_TAB;
return ( return (
<div className="sticky -top-0.5 z-10 hidden md:flex items-center justify-between gap-4 border-b border-custom-border-300 bg-custom-background-100 px-4 sm:px-5 md:static"> <div className="sticky -top-0.5 hidden md:flex items-center justify-between gap-4 border-b border-custom-border-300 bg-custom-background-100 px-4 sm:px-5 md:static">
<div className="flex items-center overflow-x-scroll"> <div className="flex items-center overflow-x-scroll">
{tabsList.map((tab) => ( {tabsList.map((tab) => (
<Link key={tab.route} href={`/${workspaceSlug}/profile/${userId}/${tab.route}`}> <Link key={tab.route} href={`/${workspaceSlug}/profile/${userId}/${tab.route}`}>
<span <span
className={`flex whitespace-nowrap border-b-2 p-4 text-sm font-medium outline-none ${ className={`flex whitespace-nowrap border-b-2 p-4 text-sm font-medium outline-none ${
pathname === `/${workspaceSlug}/profile/${userId}${tab.selected}/` pathname === `/${workspaceSlug}/profile/${userId}${tab.selected}`
? "border-custom-primary-100 text-custom-primary-100" ? "border-custom-primary-100 text-custom-primary-100"
: "border-transparent" : "border-transparent"
}`} }`}
@ -38,7 +36,6 @@ const pathname = usePathname();
</Link> </Link>
))} ))}
</div> </div>
{showProfileIssuesFilter && <ProfileIssuesFilter />}
</div> </div>
); );
}; };

View file

@ -1,50 +1,49 @@
"use client"; "use client";
import { useEffect, useRef } from "react"; import { FC, useEffect, useRef } from "react";
import { observer } from "mobx-react"; import { observer } from "mobx-react";
import Link from "next/link"; import Link from "next/link";
import { useParams } from "next/navigation"; import { useParams } from "next/navigation";
import useSWR from "swr";
// icons // icons
import { ChevronDown, Pencil } from "lucide-react"; import { ChevronDown, Pencil } from "lucide-react";
// headless ui // headless ui
import { Disclosure, Transition } from "@headlessui/react"; import { Disclosure, Transition } from "@headlessui/react";
// types
import { IUserProfileProjectSegregation } from "@plane/types";
// plane ui // plane ui
import { Loader, Tooltip } from "@plane/ui"; import { Loader, Tooltip } from "@plane/ui";
// components // components
import { Logo } from "@/components/common"; import { Logo } from "@/components/common";
// fetch-keys // fetch-keys
import { USER_PROFILE_PROJECT_SEGREGATION } from "@/constants/fetch-keys";
// helpers // helpers
import { cn } from "@/helpers/common.helper";
import { renderFormattedDate } from "@/helpers/date-time.helper"; import { renderFormattedDate } from "@/helpers/date-time.helper";
// hooks // hooks
import { useAppTheme, useProject, useUser } from "@/hooks/store"; import { useAppTheme, useProject, useUser } from "@/hooks/store";
import useOutsideClickDetector from "@/hooks/use-outside-click-detector"; import useOutsideClickDetector from "@/hooks/use-outside-click-detector";
import { usePlatformOS } from "@/hooks/use-platform-os"; import { usePlatformOS } from "@/hooks/use-platform-os";
// services // services
import { UserService } from "@/services/user.service";
// components // components
import { ProfileSidebarTime } from "./time"; import { ProfileSidebarTime } from "./time";
// services // services
const userService = new UserService();
export const ProfileSidebar = observer(() => { type TProfileSidebar = {
userProjectsData: IUserProfileProjectSegregation | undefined;
className?: string;
};
export const ProfileSidebar: FC<TProfileSidebar> = observer((props) => {
const { userProjectsData, className = "" } = props;
// refs // refs
const ref = useRef<HTMLDivElement>(null); const ref = useRef<HTMLDivElement>(null);
// router // router
const { workspaceSlug, userId } = useParams(); const { userId } = useParams();
// store hooks // store hooks
const { data: currentUser } = useUser(); const { data: currentUser } = useUser();
const { profileSidebarCollapsed, toggleProfileSidebar } = useAppTheme(); const { profileSidebarCollapsed, toggleProfileSidebar } = useAppTheme();
const { getProjectById } = useProject(); const { getProjectById } = useProject();
const { isMobile } = usePlatformOS(); 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, () => { useOutsideClickDetector(ref, () => {
if (profileSidebarCollapsed === false) { if (profileSidebarCollapsed === false) {
@ -82,12 +81,15 @@ export const ProfileSidebar = observer(() => {
return ( return (
<div <div
className={`vertical-scrollbar scrollbar-md fixed z-[5] h-full w-full flex-shrink-0 overflow-hidden overflow-y-auto border-l border-custom-border-100 bg-custom-sidebar-background-100 shadow-custom-shadow-sm transition-all md:relative md:w-[300px]`} className={cn(
`vertical-scrollbar scrollbar-md fixed z-[5] h-full w-full flex-shrink-0 overflow-hidden overflow-y-auto border-l border-custom-border-100 bg-custom-sidebar-background-100 shadow-custom-shadow-sm transition-all md:relative md:w-[300px]`,
className
)}
style={profileSidebarCollapsed ? { marginLeft: `${window?.innerWidth || 0}px` } : {}} style={profileSidebarCollapsed ? { marginLeft: `${window?.innerWidth || 0}px` } : {}}
> >
{userProjectsData ? ( {userProjectsData ? (
<> <>
<div className="relative h-32"> <div className="relative h-[110px]">
{currentUser?.id === userId && ( {currentUser?.id === userId && (
<div className="absolute right-3.5 top-3.5 grid h-5 w-5 place-items-center rounded bg-white"> <div className="absolute right-3.5 top-3.5 grid h-5 w-5 place-items-center rounded bg-white">
<Link href="/profile"> <Link href="/profile">
@ -100,7 +102,7 @@ export const ProfileSidebar = observer(() => {
<img <img
src={userProjectsData.user_data?.cover_image ?? "/users/user-profile-cover-default-img.png"} src={userProjectsData.user_data?.cover_image ?? "/users/user-profile-cover-default-img.png"}
alt={userProjectsData.user_data?.display_name} alt={userProjectsData.user_data?.display_name}
className="h-32 w-full object-cover" className="h-[110px] w-full object-cover"
/> />
<div className="absolute -bottom-[26px] left-5 h-[52px] w-[52px] rounded"> <div className="absolute -bottom-[26px] left-5 h-[52px] w-[52px] rounded">
{userProjectsData.user_data?.avatar && userProjectsData.user_data?.avatar !== "" ? ( {userProjectsData.user_data?.avatar && userProjectsData.user_data?.avatar !== "" ? (

View file

@ -34,6 +34,9 @@ export const SidebarUserMenu = observer(() => {
// computed // computed
const workspaceMemberInfo = currentWorkspaceRole || EUserWorkspaceRoles.GUEST; const workspaceMemberInfo = currentWorkspaceRole || EUserWorkspaceRoles.GUEST;
const getHref = (link: any) =>
`/${workspaceSlug}${link.href}${link.key === "your-work" ? `/${currentUser?.id}` : ""}`;
const handleLinkClick = (itemKey: string) => { const handleLinkClick = (itemKey: string) => {
if (window.innerWidth < 768) { if (window.innerWidth < 768) {
toggleSidebar(); toggleSidebar();
@ -67,14 +70,10 @@ export const SidebarUserMenu = observer(() => {
disabled={!sidebarCollapsed} disabled={!sidebarCollapsed}
isMobile={isMobile} isMobile={isMobile}
> >
<Link <Link key={link.key} href={getHref(link)} onClick={() => handleLinkClick(link.key)}>
href={`/${workspaceSlug}${link.href}${link.key === "my-work" ? `/${currentUser?.id}` : ""}`}
onClick={() => handleLinkClick(link.key)}
>
<SidebarNavItem <SidebarNavItem
key={link.key}
className={`${sidebarCollapsed ? "p-0 size-8 aspect-square justify-center mx-auto" : ""}`} className={`${sidebarCollapsed ? "p-0 size-8 aspect-square justify-center mx-auto" : ""}`}
isActive={link.highlight(pathname, `/${workspaceSlug}`)} isActive={link.highlight(pathname, `/${workspaceSlug}`, { userId: currentUser?.id })}
> >
<div className="flex items-center gap-1.5 py-[1px]"> <div className="flex items-center gap-1.5 py-[1px]">
<link.Icon className="size-4 flex-shrink-0" /> <link.Icon className="size-4 flex-shrink-0" />

View file

@ -293,12 +293,16 @@ export const SIDEBAR_WORKSPACE_MENU_ITEMS: {
}, },
]; ];
type TLinkOptions = {
userId: string | undefined;
};
export const SIDEBAR_USER_MENU_ITEMS: { export const SIDEBAR_USER_MENU_ITEMS: {
key: string; key: string;
label: string; label: string;
href: string; href: string;
access: EUserWorkspaceRoles; access: EUserWorkspaceRoles;
highlight: (pathname: string, baseUrl: string) => boolean; highlight: (pathname: string, baseUrl: string, options?: TLinkOptions) => boolean;
Icon: React.FC<Props>; Icon: React.FC<Props>;
}[] = [ }[] = [
{ {
@ -314,7 +318,8 @@ export const SIDEBAR_USER_MENU_ITEMS: {
label: "Your work", label: "Your work",
href: "/profile", href: "/profile",
access: EUserWorkspaceRoles.GUEST, access: EUserWorkspaceRoles.GUEST,
highlight: (pathname: string, baseUrl: string) => pathname.includes(`${baseUrl}/profile/`), highlight: (pathname: string, baseUrl: string, options?: TLinkOptions) =>
options?.userId ? pathname.includes(`${baseUrl}/profile/${options?.userId}`) : false,
Icon: UserActivityIcon, Icon: UserActivityIcon,
}, },
{ {

View file

@ -50,7 +50,7 @@ export const PROFILE_VIEWER_TAB = [
{ {
route: "", route: "",
label: "Summary", label: "Summary",
selected: "", selected: "/",
}, },
]; ];
@ -58,21 +58,21 @@ export const PROFILE_ADMINS_TAB = [
{ {
route: "assigned", route: "assigned",
label: "Assigned", label: "Assigned",
selected: "/assigned", selected: "/assigned/",
}, },
{ {
route: "created", route: "created",
label: "Created", label: "Created",
selected: "/created", selected: "/created/",
}, },
{ {
route: "subscribed", route: "subscribed",
label: "Subscribed", label: "Subscribed",
selected: "/subscribed", selected: "/subscribed/",
}, },
{ {
route: "activity", route: "activity",
label: "Activity", label: "Activity",
selected: "/activity", selected: "/activity/",
}, },
]; ];