2023-03-06 13:08:01 +00:00
|
|
|
import Link from "next/link";
|
|
|
|
import { useRouter } from "next/router";
|
|
|
|
|
|
|
|
// headless ui
|
|
|
|
import { Disclosure, Transition } from "@headlessui/react";
|
|
|
|
// ui
|
|
|
|
import { CustomMenu } from "components/ui";
|
|
|
|
// icons
|
2023-03-30 15:15:15 +00:00
|
|
|
import {
|
|
|
|
ChevronDownIcon,
|
|
|
|
DocumentTextIcon,
|
2023-03-30 19:01:00 +00:00
|
|
|
LinkIcon,
|
2023-03-30 15:15:15 +00:00
|
|
|
StarIcon,
|
|
|
|
TrashIcon,
|
|
|
|
} from "@heroicons/react/24/outline";
|
2023-03-16 08:37:19 +00:00
|
|
|
import {
|
|
|
|
ContrastIcon,
|
|
|
|
LayerDiagonalIcon,
|
|
|
|
PeopleGroupIcon,
|
|
|
|
SettingIcon,
|
|
|
|
ViewListIcon,
|
|
|
|
} from "components/icons";
|
2023-03-06 13:08:01 +00:00
|
|
|
// helpers
|
|
|
|
import { truncateText } from "helpers/string.helper";
|
|
|
|
// types
|
|
|
|
import { IProject } from "types";
|
|
|
|
|
|
|
|
type Props = {
|
|
|
|
project: IProject;
|
|
|
|
sidebarCollapse: boolean;
|
|
|
|
handleDeleteProject: () => void;
|
|
|
|
handleCopyText: () => void;
|
|
|
|
handleAddToFavorites?: () => void;
|
|
|
|
handleRemoveFromFavorites?: () => void;
|
|
|
|
};
|
|
|
|
|
|
|
|
const navigation = (workspaceSlug: string, projectId: string) => [
|
|
|
|
{
|
|
|
|
name: "Issues",
|
|
|
|
href: `/${workspaceSlug}/projects/${projectId}/issues`,
|
|
|
|
icon: LayerDiagonalIcon,
|
|
|
|
},
|
|
|
|
{
|
|
|
|
name: "Cycles",
|
|
|
|
href: `/${workspaceSlug}/projects/${projectId}/cycles`,
|
|
|
|
icon: ContrastIcon,
|
|
|
|
},
|
|
|
|
{
|
|
|
|
name: "Modules",
|
|
|
|
href: `/${workspaceSlug}/projects/${projectId}/modules`,
|
|
|
|
icon: PeopleGroupIcon,
|
|
|
|
},
|
2023-03-16 08:37:19 +00:00
|
|
|
{
|
|
|
|
name: "Views",
|
|
|
|
href: `/${workspaceSlug}/projects/${projectId}/views`,
|
|
|
|
icon: ViewListIcon,
|
|
|
|
},
|
2023-03-23 05:31:06 +00:00
|
|
|
{
|
|
|
|
name: "Pages",
|
|
|
|
href: `/${workspaceSlug}/projects/${projectId}/pages`,
|
2023-03-28 18:50:00 +00:00
|
|
|
icon: DocumentTextIcon,
|
2023-03-23 05:31:06 +00:00
|
|
|
},
|
2023-03-06 13:08:01 +00:00
|
|
|
{
|
|
|
|
name: "Settings",
|
|
|
|
href: `/${workspaceSlug}/projects/${projectId}/settings`,
|
2023-03-15 12:11:52 +00:00
|
|
|
icon: SettingIcon,
|
2023-03-06 13:08:01 +00:00
|
|
|
},
|
|
|
|
];
|
|
|
|
|
|
|
|
export const SingleSidebarProject: React.FC<Props> = ({
|
|
|
|
project,
|
|
|
|
sidebarCollapse,
|
|
|
|
handleDeleteProject,
|
|
|
|
handleCopyText,
|
|
|
|
handleAddToFavorites,
|
|
|
|
handleRemoveFromFavorites,
|
|
|
|
}) => {
|
|
|
|
const router = useRouter();
|
|
|
|
const { workspaceSlug, projectId } = router.query;
|
|
|
|
|
|
|
|
return (
|
|
|
|
<Disclosure key={project?.id} defaultOpen={projectId === project?.id}>
|
|
|
|
{({ open }) => (
|
|
|
|
<>
|
|
|
|
<div className="flex items-center gap-x-1">
|
|
|
|
<Disclosure.Button
|
|
|
|
as="div"
|
|
|
|
className={`flex w-full cursor-pointer select-none items-center rounded-md py-2 text-left text-sm font-medium ${
|
|
|
|
sidebarCollapse ? "justify-center" : "justify-between"
|
|
|
|
}`}
|
|
|
|
>
|
|
|
|
<div className="flex items-center gap-x-2">
|
|
|
|
{project.icon ? (
|
|
|
|
<span className="grid h-7 w-7 flex-shrink-0 place-items-center rounded uppercase">
|
|
|
|
{String.fromCodePoint(parseInt(project.icon))}
|
|
|
|
</span>
|
|
|
|
) : (
|
|
|
|
<span className="grid h-7 w-7 flex-shrink-0 place-items-center rounded bg-gray-700 uppercase text-white">
|
|
|
|
{project?.name.charAt(0)}
|
|
|
|
</span>
|
|
|
|
)}
|
|
|
|
|
|
|
|
{!sidebarCollapse && (
|
|
|
|
<p className="overflow-hidden text-ellipsis text-[0.875rem]">
|
|
|
|
{truncateText(project?.name, 20)}
|
|
|
|
</p>
|
|
|
|
)}
|
|
|
|
</div>
|
|
|
|
{!sidebarCollapse && (
|
|
|
|
<span>
|
|
|
|
<ChevronDownIcon className={`h-4 w-4 duration-300 ${open ? "rotate-180" : ""}`} />
|
|
|
|
</span>
|
|
|
|
)}
|
|
|
|
</Disclosure.Button>
|
|
|
|
|
|
|
|
{!sidebarCollapse && (
|
|
|
|
<CustomMenu ellipsis>
|
|
|
|
<CustomMenu.MenuItem onClick={handleDeleteProject}>
|
2023-03-30 19:01:00 +00:00
|
|
|
<span className="flex items-center justify-start gap-2 ">
|
2023-03-30 15:15:15 +00:00
|
|
|
<TrashIcon className="h-4 w-4" />
|
|
|
|
<span>Delete project</span>
|
|
|
|
</span>
|
2023-03-06 13:08:01 +00:00
|
|
|
</CustomMenu.MenuItem>
|
|
|
|
{handleAddToFavorites && (
|
|
|
|
<CustomMenu.MenuItem onClick={handleAddToFavorites}>
|
2023-03-30 19:01:00 +00:00
|
|
|
<span className="flex items-center justify-start gap-2">
|
2023-03-30 15:15:15 +00:00
|
|
|
<StarIcon className="h-4 w-4" />
|
|
|
|
<span>Add to favorites</span>
|
|
|
|
</span>
|
2023-03-06 13:08:01 +00:00
|
|
|
</CustomMenu.MenuItem>
|
|
|
|
)}
|
|
|
|
{handleRemoveFromFavorites && (
|
|
|
|
<CustomMenu.MenuItem onClick={handleRemoveFromFavorites}>
|
2023-03-30 19:01:00 +00:00
|
|
|
<span className="flex items-center justify-start gap-2">
|
2023-03-30 15:15:15 +00:00
|
|
|
<StarIcon className="h-4 w-4" />
|
|
|
|
<span>Remove from favorites</span>
|
|
|
|
</span>
|
2023-03-06 13:08:01 +00:00
|
|
|
</CustomMenu.MenuItem>
|
|
|
|
)}
|
|
|
|
<CustomMenu.MenuItem onClick={handleCopyText}>
|
2023-03-30 19:01:00 +00:00
|
|
|
<span className="flex items-center justify-start gap-2">
|
|
|
|
<LinkIcon className="h-4 w-4" />
|
2023-03-30 15:15:15 +00:00
|
|
|
<span>Copy project link</span>
|
|
|
|
</span>
|
2023-03-06 13:08:01 +00:00
|
|
|
</CustomMenu.MenuItem>
|
|
|
|
</CustomMenu>
|
|
|
|
)}
|
|
|
|
</div>
|
|
|
|
|
|
|
|
<Transition
|
|
|
|
enter="transition duration-100 ease-out"
|
|
|
|
enterFrom="transform scale-95 opacity-0"
|
|
|
|
enterTo="transform scale-100 opacity-100"
|
|
|
|
leave="transition duration-75 ease-out"
|
|
|
|
leaveFrom="transform scale-100 opacity-100"
|
|
|
|
leaveTo="transform scale-95 opacity-0"
|
|
|
|
>
|
|
|
|
<Disclosure.Panel
|
|
|
|
className={`${sidebarCollapse ? "" : "ml-[2.25rem]"} flex flex-col gap-y-1`}
|
|
|
|
>
|
|
|
|
{navigation(workspaceSlug as string, project?.id).map((item) => {
|
2023-03-16 12:44:07 +00:00
|
|
|
if (
|
|
|
|
(item.name === "Cycles" && !project.cycle_view) ||
|
|
|
|
(item.name === "Modules" && !project.module_view) ||
|
2023-03-29 09:51:08 +00:00
|
|
|
(item.name === "Views" && !project.issue_views_view) ||
|
|
|
|
(item.name === "Pages" && !project.page_view)
|
2023-03-16 12:44:07 +00:00
|
|
|
)
|
|
|
|
return;
|
2023-03-06 13:08:01 +00:00
|
|
|
|
|
|
|
return (
|
|
|
|
<Link key={item.name} href={item.href}>
|
|
|
|
<a
|
2023-03-22 11:28:32 +00:00
|
|
|
className={`group flex items-center rounded-md p-2 text-xs font-medium outline-none ${
|
2023-04-25 06:40:05 +00:00
|
|
|
router.asPath.includes(item.href)
|
2023-05-05 10:15:53 +00:00
|
|
|
? "bg-brand-surface-2 text-brand-base"
|
|
|
|
: "text-brand-secondary hover:bg-brand-surface-2 hover:text-brand-secondary focus:bg-brand-surface-2 focus:text-brand-secondary"
|
2023-03-06 13:08:01 +00:00
|
|
|
} ${sidebarCollapse ? "justify-center" : ""}`}
|
|
|
|
>
|
|
|
|
<div className="grid place-items-center">
|
|
|
|
<item.icon
|
2023-04-28 15:21:47 +00:00
|
|
|
className={`h-5 w-5 flex-shrink-0 text-brand-secondary ${
|
|
|
|
!sidebarCollapse ? "mr-3" : ""
|
|
|
|
}`}
|
2023-04-20 08:11:24 +00:00
|
|
|
color="#858e96"
|
2023-03-06 13:08:01 +00:00
|
|
|
aria-hidden="true"
|
|
|
|
/>
|
|
|
|
</div>
|
|
|
|
{!sidebarCollapse && item.name}
|
|
|
|
</a>
|
|
|
|
</Link>
|
|
|
|
);
|
|
|
|
})}
|
|
|
|
</Disclosure.Panel>
|
|
|
|
</Transition>
|
|
|
|
</>
|
|
|
|
)}
|
|
|
|
</Disclosure>
|
|
|
|
);
|
|
|
|
};
|