2023-11-28 05:59:01 +00:00
|
|
|
import { mutate } from "swr";
|
2023-11-23 09:14:06 +00:00
|
|
|
import Link from "next/link";
|
2023-11-28 05:59:01 +00:00
|
|
|
import { useRouter } from "next/router";
|
2023-11-23 09:14:06 +00:00
|
|
|
import { observer } from "mobx-react-lite";
|
2023-11-28 05:59:01 +00:00
|
|
|
import { useTheme } from "next-themes";
|
2023-11-29 08:18:07 +00:00
|
|
|
import { Activity, ChevronLeft, CircleUser, KeyRound, LogOut, MoveLeft, Plus, Settings2, UserPlus } from "lucide-react";
|
2023-11-23 09:14:06 +00:00
|
|
|
// mobx store
|
|
|
|
import { useMobxStore } from "lib/mobx/store-provider";
|
|
|
|
// ui
|
2023-11-29 08:18:07 +00:00
|
|
|
import { Tooltip } from "@plane/ui";
|
2023-11-28 05:59:01 +00:00
|
|
|
// hooks
|
2023-11-24 07:53:46 +00:00
|
|
|
import useToast from "hooks/use-toast";
|
2023-11-29 08:18:07 +00:00
|
|
|
import { useState } from "react";
|
2023-11-23 09:14:06 +00:00
|
|
|
|
2023-11-29 08:18:07 +00:00
|
|
|
const PROFILE_ACTION_LINKS = [
|
|
|
|
{
|
|
|
|
key: "profile",
|
|
|
|
label: "Profile",
|
|
|
|
href: `/profile`,
|
|
|
|
Icon: CircleUser,
|
|
|
|
},
|
|
|
|
{
|
|
|
|
key: "change-password",
|
|
|
|
label: "Change password",
|
|
|
|
href: `/profile/change-password`,
|
|
|
|
Icon: KeyRound,
|
|
|
|
},
|
|
|
|
{
|
|
|
|
key: "activity",
|
|
|
|
label: "Activity",
|
|
|
|
href: `/profile/activity`,
|
|
|
|
Icon: Activity,
|
|
|
|
},
|
|
|
|
{
|
|
|
|
key: "preferences",
|
|
|
|
label: "Preferences",
|
|
|
|
href: `/profile/preferences`,
|
|
|
|
Icon: Settings2,
|
|
|
|
},
|
|
|
|
];
|
|
|
|
|
|
|
|
const WORKSPACE_ACTION_LINKS = [
|
2023-11-23 09:14:06 +00:00
|
|
|
{
|
|
|
|
key: "create-workspace",
|
|
|
|
Icon: Plus,
|
2023-11-29 08:18:07 +00:00
|
|
|
label: "Create workspace",
|
2023-11-23 09:14:06 +00:00
|
|
|
href: "/create-workspace",
|
|
|
|
},
|
|
|
|
{
|
|
|
|
key: "invitations",
|
|
|
|
Icon: UserPlus,
|
2023-11-29 08:18:07 +00:00
|
|
|
label: "Invitations",
|
2023-11-23 09:14:06 +00:00
|
|
|
href: "/invitations",
|
|
|
|
},
|
|
|
|
];
|
|
|
|
|
|
|
|
export const ProfileLayoutSidebar = observer(() => {
|
2023-11-28 05:59:01 +00:00
|
|
|
// states
|
2023-11-29 08:18:07 +00:00
|
|
|
const [isSigningOut, setIsSigningOut] = useState(false);
|
|
|
|
// router
|
2023-11-24 07:53:46 +00:00
|
|
|
const router = useRouter();
|
2023-11-29 08:18:07 +00:00
|
|
|
// next themes
|
2023-11-24 07:53:46 +00:00
|
|
|
const { setTheme } = useTheme();
|
2023-11-29 08:18:07 +00:00
|
|
|
// toast
|
2023-11-24 07:53:46 +00:00
|
|
|
const { setToastAlert } = useToast();
|
|
|
|
|
2023-11-23 09:14:06 +00:00
|
|
|
const {
|
|
|
|
theme: { sidebarCollapsed, toggleSidebar },
|
|
|
|
workspace: { workspaces },
|
2023-11-29 08:18:07 +00:00
|
|
|
user: { currentUser, currentUserSettings, signOut },
|
2023-11-23 09:14:06 +00:00
|
|
|
} = useMobxStore();
|
|
|
|
|
2023-11-24 07:53:46 +00:00
|
|
|
// redirect url for normal mode
|
|
|
|
const redirectWorkspaceSlug =
|
|
|
|
currentUserSettings?.workspace?.last_workspace_slug ||
|
|
|
|
currentUserSettings?.workspace?.fallback_workspace_slug ||
|
|
|
|
"";
|
|
|
|
|
|
|
|
const handleSignOut = async () => {
|
2023-11-29 08:18:07 +00:00
|
|
|
setIsSigningOut(true);
|
|
|
|
|
2023-11-25 17:34:56 +00:00
|
|
|
await signOut()
|
2023-11-24 07:53:46 +00:00
|
|
|
.then(() => {
|
|
|
|
mutate("CURRENT_USER_DETAILS", null);
|
|
|
|
setTheme("system");
|
|
|
|
router.push("/");
|
|
|
|
})
|
|
|
|
.catch(() =>
|
|
|
|
setToastAlert({
|
|
|
|
type: "error",
|
|
|
|
title: "Error!",
|
|
|
|
message: "Failed to sign out. Please try again.",
|
|
|
|
})
|
2023-11-29 08:18:07 +00:00
|
|
|
)
|
|
|
|
.finally(() => setIsSigningOut(false));
|
2023-11-24 07:53:46 +00:00
|
|
|
};
|
|
|
|
|
2023-11-23 09:14:06 +00:00
|
|
|
return (
|
|
|
|
<div
|
2023-12-10 10:18:10 +00:00
|
|
|
className={`fixed inset-y-0 z-20 flex h-full flex-shrink-0 flex-grow-0 flex-col border-r border-custom-sidebar-border-200 bg-custom-sidebar-background-100 duration-300 md:relative ${
|
2023-11-23 09:14:06 +00:00
|
|
|
sidebarCollapsed ? "" : "md:w-[280px]"
|
|
|
|
} ${sidebarCollapsed ? "left-0" : "-left-full md:left-0"}`}
|
|
|
|
>
|
2023-12-10 10:18:10 +00:00
|
|
|
<div className="flex h-full w-full flex-col gap-y-4">
|
2023-12-01 10:20:01 +00:00
|
|
|
<Link href={`/${redirectWorkspaceSlug}`}>
|
|
|
|
<div
|
2023-12-10 10:18:10 +00:00
|
|
|
className={`flex flex-shrink-0 items-center gap-2 truncate px-4 pt-4 ${
|
2023-12-01 10:20:01 +00:00
|
|
|
sidebarCollapsed ? "justify-center" : ""
|
|
|
|
}`}
|
|
|
|
>
|
2023-12-10 10:18:10 +00:00
|
|
|
<span className="grid h-5 w-5 flex-shrink-0 place-items-center">
|
2023-12-01 10:20:01 +00:00
|
|
|
<ChevronLeft className="h-5 w-5" strokeWidth={1} />
|
|
|
|
</span>
|
|
|
|
{!sidebarCollapsed && (
|
2023-12-10 10:18:10 +00:00
|
|
|
<h4 className="truncate text-lg font-semibold text-custom-text-200">Profile settings</h4>
|
2023-12-01 10:20:01 +00:00
|
|
|
)}
|
|
|
|
</div>
|
2023-11-29 15:03:08 +00:00
|
|
|
</Link>
|
2023-12-10 10:18:10 +00:00
|
|
|
<div className="flex flex-shrink-0 flex-col overflow-x-hidden px-4">
|
2023-11-24 07:53:46 +00:00
|
|
|
{!sidebarCollapsed && (
|
2023-12-10 10:18:10 +00:00
|
|
|
<h6 className="rounded px-1.5 text-sm font-semibold text-custom-sidebar-text-400">Your account</h6>
|
2023-11-24 07:53:46 +00:00
|
|
|
)}
|
2023-12-10 10:18:10 +00:00
|
|
|
<div className="mt-2 h-full space-y-1.5 overflow-y-auto">
|
2023-11-29 08:18:07 +00:00
|
|
|
{PROFILE_ACTION_LINKS.map((link) => {
|
|
|
|
if (link.key === "change-password" && currentUser?.is_password_autoset) return null;
|
2023-11-24 07:53:46 +00:00
|
|
|
|
2023-11-29 08:18:07 +00:00
|
|
|
return (
|
2023-12-01 09:46:36 +00:00
|
|
|
<Link key={link.key} href={link.href} className="block w-full">
|
|
|
|
<Tooltip tooltipContent={link.label} position="right" className="ml-2" disabled={!sidebarCollapsed}>
|
|
|
|
<div
|
|
|
|
className={`group flex w-full items-center gap-2.5 rounded-md px-3 py-2 text-sm font-medium outline-none ${
|
|
|
|
router.pathname === link.href
|
|
|
|
? "bg-custom-primary-100/10 text-custom-primary-100"
|
|
|
|
: "text-custom-sidebar-text-200 hover:bg-custom-sidebar-background-80"
|
|
|
|
} ${sidebarCollapsed ? "justify-center" : ""}`}
|
|
|
|
>
|
|
|
|
{<link.Icon className="h-4 w-4" />}
|
|
|
|
{!sidebarCollapsed && link.label}
|
|
|
|
</div>
|
|
|
|
</Tooltip>
|
2023-11-29 08:18:07 +00:00
|
|
|
</Link>
|
|
|
|
);
|
|
|
|
})}
|
|
|
|
</div>
|
2023-11-23 09:14:06 +00:00
|
|
|
</div>
|
2023-11-29 08:18:07 +00:00
|
|
|
<div className="flex flex-col overflow-x-hidden px-4">
|
|
|
|
{!sidebarCollapsed && (
|
2023-12-10 10:18:10 +00:00
|
|
|
<h6 className="rounded px-1.5 text-sm font-semibold text-custom-sidebar-text-400">Workspaces</h6>
|
2023-11-29 08:18:07 +00:00
|
|
|
)}
|
|
|
|
{workspaces && workspaces.length > 0 && (
|
2023-12-10 10:18:10 +00:00
|
|
|
<div className="mt-2 h-full space-y-1.5 overflow-y-auto">
|
2023-11-23 09:14:06 +00:00
|
|
|
{workspaces.map((workspace) => (
|
|
|
|
<Link
|
|
|
|
key={workspace.id}
|
|
|
|
href={`/${workspace.slug}`}
|
2023-12-10 10:18:10 +00:00
|
|
|
className={`flex flex-grow cursor-pointer select-none items-center truncate text-left text-sm font-medium ${
|
2023-11-23 09:14:06 +00:00
|
|
|
sidebarCollapsed ? "justify-center" : `justify-between`
|
|
|
|
}`}
|
|
|
|
>
|
2023-11-29 15:02:10 +00:00
|
|
|
<span
|
2023-12-10 10:18:10 +00:00
|
|
|
className={`flex w-full flex-grow items-center gap-x-2 truncate rounded-md px-3 py-1 hover:bg-custom-sidebar-background-80 ${
|
2023-11-23 09:14:06 +00:00
|
|
|
sidebarCollapsed ? "justify-center" : ""
|
|
|
|
}`}
|
|
|
|
>
|
|
|
|
<span
|
2023-12-10 10:18:10 +00:00
|
|
|
className={`relative flex h-6 w-6 flex-shrink-0 items-center justify-center p-2 text-xs uppercase ${
|
2023-11-23 09:14:06 +00:00
|
|
|
!workspace?.logo && "rounded bg-custom-primary-500 text-white"
|
|
|
|
}`}
|
|
|
|
>
|
|
|
|
{workspace?.logo && workspace.logo !== "" ? (
|
|
|
|
<img
|
|
|
|
src={workspace.logo}
|
2023-12-10 10:18:10 +00:00
|
|
|
className="absolute left-0 top-0 h-full w-full rounded object-cover"
|
2023-11-23 09:14:06 +00:00
|
|
|
alt="Workspace Logo"
|
|
|
|
/>
|
|
|
|
) : (
|
|
|
|
workspace?.name?.charAt(0) ?? "..."
|
|
|
|
)}
|
|
|
|
</span>
|
|
|
|
{!sidebarCollapsed && (
|
2023-12-10 10:18:10 +00:00
|
|
|
<p className="truncate text-sm text-custom-sidebar-text-200">{workspace.name}</p>
|
2023-11-23 09:14:06 +00:00
|
|
|
)}
|
2023-11-29 15:02:10 +00:00
|
|
|
</span>
|
2023-11-23 09:14:06 +00:00
|
|
|
</Link>
|
|
|
|
))}
|
|
|
|
</div>
|
2023-11-29 08:18:07 +00:00
|
|
|
)}
|
|
|
|
<div className="mt-1.5">
|
|
|
|
{WORKSPACE_ACTION_LINKS.map((link) => (
|
2023-12-01 09:46:36 +00:00
|
|
|
<Link className="block w-full" key={link.key} href={link.href}>
|
|
|
|
<Tooltip tooltipContent={link.label} position="right" className="ml-2" disabled={!sidebarCollapsed}>
|
|
|
|
<div
|
2023-12-10 10:18:10 +00:00
|
|
|
className={`group flex w-full items-center gap-2.5 rounded-md px-3 py-2 text-sm font-medium text-custom-sidebar-text-200 outline-none hover:bg-custom-sidebar-background-80 focus:bg-custom-sidebar-background-80 ${
|
2023-12-01 09:46:36 +00:00
|
|
|
sidebarCollapsed ? "justify-center" : ""
|
|
|
|
}`}
|
|
|
|
>
|
|
|
|
{<link.Icon className="h-4 w-4" />}
|
|
|
|
{!sidebarCollapsed && link.label}
|
|
|
|
</div>
|
|
|
|
</Tooltip>
|
2023-11-29 08:18:07 +00:00
|
|
|
</Link>
|
|
|
|
))}
|
2023-11-23 09:14:06 +00:00
|
|
|
</div>
|
2023-11-29 08:18:07 +00:00
|
|
|
</div>
|
2023-12-10 10:18:10 +00:00
|
|
|
<div className="flex flex-shrink-0 flex-grow items-end px-6 py-2">
|
2023-11-29 08:18:07 +00:00
|
|
|
<div
|
|
|
|
className={`flex w-full ${
|
|
|
|
sidebarCollapsed ? "flex-col justify-center gap-2" : "items-center justify-between gap-2"
|
2023-11-23 09:14:06 +00:00
|
|
|
}`}
|
|
|
|
>
|
2023-11-29 08:18:07 +00:00
|
|
|
<button
|
|
|
|
type="button"
|
|
|
|
onClick={handleSignOut}
|
2023-12-10 10:18:10 +00:00
|
|
|
className="flex items-center justify-center gap-2 text-sm font-medium text-red-500"
|
2023-11-29 08:18:07 +00:00
|
|
|
disabled={isSigningOut}
|
|
|
|
>
|
|
|
|
<LogOut className="h-3.5 w-3.5" />
|
|
|
|
{!sidebarCollapsed && <span>{isSigningOut ? "Signing out..." : "Sign out"}</span>}
|
|
|
|
</button>
|
|
|
|
<button
|
|
|
|
type="button"
|
2023-12-10 10:18:10 +00:00
|
|
|
className="grid place-items-center rounded-md p-1.5 text-custom-text-200 outline-none hover:bg-custom-background-90 hover:text-custom-text-100 md:hidden"
|
2023-11-29 08:18:07 +00:00
|
|
|
onClick={() => toggleSidebar()}
|
|
|
|
>
|
|
|
|
<MoveLeft className="h-3.5 w-3.5" />
|
|
|
|
</button>
|
|
|
|
<button
|
|
|
|
type="button"
|
2023-12-10 10:18:10 +00:00
|
|
|
className={`ml-auto hidden place-items-center rounded-md p-1.5 text-custom-text-200 outline-none hover:bg-custom-background-90 hover:text-custom-text-100 md:grid ${
|
2023-11-29 08:18:07 +00:00
|
|
|
sidebarCollapsed ? "w-full" : ""
|
|
|
|
}`}
|
|
|
|
onClick={() => toggleSidebar()}
|
|
|
|
>
|
|
|
|
<MoveLeft className={`h-3.5 w-3.5 duration-300 ${sidebarCollapsed ? "rotate-180" : ""}`} />
|
|
|
|
</button>
|
|
|
|
</div>
|
2023-11-23 09:14:06 +00:00
|
|
|
</div>
|
|
|
|
</div>
|
|
|
|
</div>
|
|
|
|
);
|
|
|
|
});
|