2023-03-06 13:08:01 +00:00
|
|
|
import Link from "next/link";
|
|
|
|
import { useRouter } from "next/router";
|
|
|
|
|
2023-07-13 14:14:53 +00:00
|
|
|
import { mutate } from "swr";
|
|
|
|
|
2023-07-31 11:40:23 +00:00
|
|
|
// react-beautiful-dnd
|
|
|
|
import { DraggableProvided, DraggableStateSnapshot } from "react-beautiful-dnd";
|
2023-03-06 13:08:01 +00:00
|
|
|
// headless ui
|
|
|
|
import { Disclosure, Transition } from "@headlessui/react";
|
2023-07-13 14:14:53 +00:00
|
|
|
// services
|
|
|
|
import projectService from "services/project.service";
|
|
|
|
// hooks
|
|
|
|
import useToast from "hooks/use-toast";
|
2023-03-06 13:08:01 +00:00
|
|
|
// ui
|
2023-07-20 09:44:57 +00:00
|
|
|
import { CustomMenu, Tooltip } from "components/ui";
|
2023-03-06 13:08:01 +00:00
|
|
|
// icons
|
2023-07-31 11:40:23 +00:00
|
|
|
import { EllipsisVerticalIcon, LinkIcon, StarIcon, TrashIcon } from "@heroicons/react/24/outline";
|
2023-07-20 09:44:57 +00:00
|
|
|
import {
|
|
|
|
ArchiveOutlined,
|
|
|
|
ArticleOutlined,
|
|
|
|
ContrastOutlined,
|
|
|
|
DatasetOutlined,
|
|
|
|
ExpandMoreOutlined,
|
|
|
|
FilterNoneOutlined,
|
|
|
|
PhotoFilterOutlined,
|
|
|
|
SettingsOutlined,
|
|
|
|
} from "@mui/icons-material";
|
2023-03-06 13:08:01 +00:00
|
|
|
// helpers
|
|
|
|
import { truncateText } from "helpers/string.helper";
|
2023-07-06 10:38:49 +00:00
|
|
|
import { renderEmoji } from "helpers/emoji.helper";
|
2023-03-06 13:08:01 +00:00
|
|
|
// types
|
|
|
|
import { IProject } from "types";
|
2023-07-13 14:14:53 +00:00
|
|
|
// fetch-keys
|
|
|
|
import { PROJECTS_LIST } from "constants/fetch-keys";
|
2023-03-06 13:08:01 +00:00
|
|
|
|
|
|
|
type Props = {
|
|
|
|
project: IProject;
|
|
|
|
sidebarCollapse: boolean;
|
2023-08-01 06:54:34 +00:00
|
|
|
provided?: DraggableProvided;
|
|
|
|
snapshot?: DraggableStateSnapshot;
|
2023-03-06 13:08:01 +00:00
|
|
|
handleDeleteProject: () => void;
|
|
|
|
handleCopyText: () => void;
|
2023-07-13 14:14:53 +00:00
|
|
|
shortContextMenu?: boolean;
|
2023-03-06 13:08:01 +00:00
|
|
|
};
|
|
|
|
|
|
|
|
const navigation = (workspaceSlug: string, projectId: string) => [
|
|
|
|
{
|
|
|
|
name: "Issues",
|
|
|
|
href: `/${workspaceSlug}/projects/${projectId}/issues`,
|
2023-07-20 09:44:57 +00:00
|
|
|
Icon: FilterNoneOutlined,
|
2023-03-06 13:08:01 +00:00
|
|
|
},
|
|
|
|
{
|
|
|
|
name: "Cycles",
|
|
|
|
href: `/${workspaceSlug}/projects/${projectId}/cycles`,
|
2023-07-20 09:44:57 +00:00
|
|
|
Icon: ContrastOutlined,
|
2023-03-06 13:08:01 +00:00
|
|
|
},
|
|
|
|
{
|
|
|
|
name: "Modules",
|
|
|
|
href: `/${workspaceSlug}/projects/${projectId}/modules`,
|
2023-07-20 09:44:57 +00:00
|
|
|
Icon: DatasetOutlined,
|
2023-03-06 13:08:01 +00:00
|
|
|
},
|
2023-03-16 08:37:19 +00:00
|
|
|
{
|
|
|
|
name: "Views",
|
|
|
|
href: `/${workspaceSlug}/projects/${projectId}/views`,
|
2023-07-20 09:44:57 +00:00
|
|
|
Icon: PhotoFilterOutlined,
|
2023-03-16 08:37:19 +00:00
|
|
|
},
|
2023-03-23 05:31:06 +00:00
|
|
|
{
|
|
|
|
name: "Pages",
|
|
|
|
href: `/${workspaceSlug}/projects/${projectId}/pages`,
|
2023-07-20 09:44:57 +00:00
|
|
|
Icon: ArticleOutlined,
|
2023-03-23 05:31:06 +00:00
|
|
|
},
|
2023-03-06 13:08:01 +00:00
|
|
|
{
|
|
|
|
name: "Settings",
|
|
|
|
href: `/${workspaceSlug}/projects/${projectId}/settings`,
|
2023-07-20 09:44:57 +00:00
|
|
|
Icon: SettingsOutlined,
|
2023-03-06 13:08:01 +00:00
|
|
|
},
|
|
|
|
];
|
|
|
|
|
|
|
|
export const SingleSidebarProject: React.FC<Props> = ({
|
|
|
|
project,
|
|
|
|
sidebarCollapse,
|
2023-07-31 11:40:23 +00:00
|
|
|
provided,
|
|
|
|
snapshot,
|
2023-03-06 13:08:01 +00:00
|
|
|
handleDeleteProject,
|
|
|
|
handleCopyText,
|
2023-07-13 14:14:53 +00:00
|
|
|
shortContextMenu = false,
|
2023-03-06 13:08:01 +00:00
|
|
|
}) => {
|
|
|
|
const router = useRouter();
|
|
|
|
const { workspaceSlug, projectId } = router.query;
|
|
|
|
|
2023-07-13 14:14:53 +00:00
|
|
|
const { setToastAlert } = useToast();
|
|
|
|
|
|
|
|
const handleAddToFavorites = () => {
|
|
|
|
if (!workspaceSlug) return;
|
|
|
|
|
|
|
|
mutate<IProject[]>(
|
|
|
|
PROJECTS_LIST(workspaceSlug as string, { is_favorite: "all" }),
|
|
|
|
(prevData) =>
|
|
|
|
(prevData ?? []).map((p) => (p.id === project.id ? { ...p, is_favorite: true } : p)),
|
|
|
|
false
|
|
|
|
);
|
|
|
|
|
|
|
|
projectService
|
|
|
|
.addProjectToFavorites(workspaceSlug as string, {
|
|
|
|
project: project.id,
|
|
|
|
})
|
|
|
|
.catch(() =>
|
|
|
|
setToastAlert({
|
|
|
|
type: "error",
|
|
|
|
title: "Error!",
|
|
|
|
message: "Couldn't remove the project from favorites. Please try again.",
|
|
|
|
})
|
|
|
|
);
|
|
|
|
};
|
|
|
|
|
|
|
|
const handleRemoveFromFavorites = () => {
|
|
|
|
if (!workspaceSlug) return;
|
|
|
|
|
|
|
|
mutate<IProject[]>(
|
|
|
|
PROJECTS_LIST(workspaceSlug as string, { is_favorite: "all" }),
|
|
|
|
(prevData) =>
|
|
|
|
(prevData ?? []).map((p) => (p.id === project.id ? { ...p, is_favorite: false } : p)),
|
|
|
|
false
|
|
|
|
);
|
|
|
|
|
|
|
|
projectService.removeProjectFromFavorites(workspaceSlug as string, project.id).catch(() =>
|
|
|
|
setToastAlert({
|
|
|
|
type: "error",
|
|
|
|
title: "Error!",
|
|
|
|
message: "Couldn't remove the project from favorites. Please try again.",
|
|
|
|
})
|
|
|
|
);
|
|
|
|
};
|
|
|
|
|
2023-03-06 13:08:01 +00:00
|
|
|
return (
|
2023-08-01 06:54:34 +00:00
|
|
|
<Disclosure key={project.id} defaultOpen={projectId === project.id}>
|
2023-03-06 13:08:01 +00:00
|
|
|
{({ open }) => (
|
|
|
|
<>
|
2023-07-31 11:40:23 +00:00
|
|
|
<div
|
2023-08-02 06:39:53 +00:00
|
|
|
className={`group relative text-custom-sidebar-text-10 px-2 py-1 w-full flex items-center hover:bg-custom-sidebar-background-80 rounded-md ${
|
2023-08-01 06:54:34 +00:00
|
|
|
snapshot?.isDragging ? "opacity-60" : ""
|
2023-07-31 11:40:23 +00:00
|
|
|
}`}
|
|
|
|
>
|
2023-08-01 06:54:34 +00:00
|
|
|
{provided && (
|
2023-08-02 06:39:53 +00:00
|
|
|
<Tooltip
|
|
|
|
tooltipContent={
|
|
|
|
project.sort_order === null
|
|
|
|
? "Join the project to rearrange"
|
|
|
|
: "Drag to rearrange"
|
|
|
|
}
|
|
|
|
position="top-right"
|
2023-08-01 06:54:34 +00:00
|
|
|
>
|
2023-08-02 06:39:53 +00:00
|
|
|
<button
|
|
|
|
type="button"
|
|
|
|
className={`absolute top-1/2 -translate-y-1/2 -left-4 hidden rounded p-0.5 ${
|
|
|
|
sidebarCollapse ? "" : "group-hover:!flex"
|
|
|
|
} ${project.sort_order === null ? "opacity-60 cursor-not-allowed" : ""}`}
|
|
|
|
{...provided?.dragHandleProps}
|
|
|
|
>
|
|
|
|
<EllipsisVerticalIcon className="h-4" />
|
|
|
|
<EllipsisVerticalIcon className="-ml-5 h-4" />
|
|
|
|
</button>
|
|
|
|
</Tooltip>
|
2023-08-01 06:54:34 +00:00
|
|
|
)}
|
2023-07-13 13:05:43 +00:00
|
|
|
<Tooltip
|
2023-08-01 06:54:34 +00:00
|
|
|
tooltipContent={`${project.name}`}
|
2023-07-13 13:05:43 +00:00
|
|
|
position="right"
|
|
|
|
className="ml-2"
|
|
|
|
disabled={!sidebarCollapse}
|
2023-03-06 13:08:01 +00:00
|
|
|
>
|
2023-07-13 13:05:43 +00:00
|
|
|
<Disclosure.Button
|
|
|
|
as="div"
|
2023-08-02 08:51:26 +00:00
|
|
|
className={`flex items-center flex-grow truncate cursor-pointer select-none text-left text-sm font-medium ${
|
2023-08-01 06:54:34 +00:00
|
|
|
sidebarCollapse ? "justify-center" : `justify-between`
|
2023-07-13 13:05:43 +00:00
|
|
|
}`}
|
|
|
|
>
|
2023-08-02 11:15:34 +00:00
|
|
|
<div
|
|
|
|
className={`flex items-center flex-grow w-full truncate gap-x-2 ${
|
|
|
|
sidebarCollapse ? "justify-center" : ""
|
|
|
|
}`}
|
|
|
|
>
|
2023-07-13 13:05:43 +00:00
|
|
|
{project.emoji ? (
|
|
|
|
<span className="grid h-7 w-7 flex-shrink-0 place-items-center rounded uppercase">
|
|
|
|
{renderEmoji(project.emoji)}
|
2023-05-19 11:05:51 +00:00
|
|
|
</span>
|
2023-07-13 13:05:43 +00:00
|
|
|
) : project.icon_prop ? (
|
2023-08-02 08:51:26 +00:00
|
|
|
<div className="h-7 w-7 flex-shrink-0 grid place-items-center">
|
2023-07-26 12:21:26 +00:00
|
|
|
{renderEmoji(project.icon_prop)}
|
2023-07-13 13:05:43 +00:00
|
|
|
</div>
|
|
|
|
) : (
|
|
|
|
<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>
|
|
|
|
)}
|
2023-03-06 13:08:01 +00:00
|
|
|
|
2023-07-13 13:05:43 +00:00
|
|
|
{!sidebarCollapse && (
|
2023-08-02 08:51:26 +00:00
|
|
|
<p className={`truncate ${open ? "" : "text-custom-sidebar-text-200"}`}>
|
|
|
|
{project.name}
|
2023-07-13 13:05:43 +00:00
|
|
|
</p>
|
|
|
|
)}
|
|
|
|
</div>
|
2023-03-06 13:08:01 +00:00
|
|
|
{!sidebarCollapse && (
|
2023-07-20 09:44:57 +00:00
|
|
|
<ExpandMoreOutlined
|
|
|
|
fontSize="small"
|
2023-08-02 08:51:26 +00:00
|
|
|
className={`flex-shrink-0 ${
|
2023-08-01 06:54:34 +00:00
|
|
|
open ? "rotate-180" : ""
|
|
|
|
} !hidden group-hover:!block text-custom-sidebar-text-200 duration-300`}
|
2023-07-13 13:05:43 +00:00
|
|
|
/>
|
2023-03-06 13:08:01 +00:00
|
|
|
)}
|
2023-07-13 13:05:43 +00:00
|
|
|
</Disclosure.Button>
|
|
|
|
</Tooltip>
|
2023-03-06 13:08:01 +00:00
|
|
|
|
|
|
|
{!sidebarCollapse && (
|
2023-08-02 08:51:26 +00:00
|
|
|
<CustomMenu className="hidden group-hover:block flex-shrink-0" ellipsis>
|
2023-07-13 14:14:53 +00:00
|
|
|
{!shortContextMenu && (
|
|
|
|
<CustomMenu.MenuItem onClick={handleDeleteProject}>
|
|
|
|
<span className="flex items-center justify-start gap-2 ">
|
|
|
|
<TrashIcon className="h-4 w-4" />
|
|
|
|
<span>Delete project</span>
|
|
|
|
</span>
|
|
|
|
</CustomMenu.MenuItem>
|
|
|
|
)}
|
|
|
|
{!project.is_favorite && (
|
2023-03-06 13:08:01 +00:00
|
|
|
<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>
|
|
|
|
)}
|
2023-07-13 14:14:53 +00:00
|
|
|
{project.is_favorite && (
|
2023-03-06 13:08:01 +00:00
|
|
|
<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>
|
2023-07-13 06:04:37 +00:00
|
|
|
{project.archive_in > 0 && (
|
|
|
|
<CustomMenu.MenuItem
|
|
|
|
onClick={() =>
|
|
|
|
router.push(`/${workspaceSlug}/projects/${project?.id}/archived-issues/`)
|
|
|
|
}
|
|
|
|
>
|
|
|
|
<div className="flex items-center justify-start gap-2">
|
2023-07-20 09:44:57 +00:00
|
|
|
<ArchiveOutlined fontSize="small" />
|
2023-07-13 06:04:37 +00:00
|
|
|
<span>Archived Issues</span>
|
|
|
|
</div>
|
|
|
|
</CustomMenu.MenuItem>
|
|
|
|
)}
|
2023-03-06 13:08:01 +00:00
|
|
|
</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"
|
|
|
|
>
|
2023-08-02 11:15:34 +00:00
|
|
|
<Disclosure.Panel className={`space-y-2 mt-1 ${sidebarCollapse ? "" : "ml-[2.25rem]"}`}>
|
2023-03-06 13:08:01 +00:00
|
|
|
{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}>
|
2023-07-13 13:05:43 +00:00
|
|
|
<a className="block w-full">
|
|
|
|
<Tooltip
|
|
|
|
tooltipContent={`${project?.name}: ${item.name}`}
|
|
|
|
position="right"
|
|
|
|
className="ml-2"
|
|
|
|
disabled={!sidebarCollapse}
|
|
|
|
>
|
|
|
|
<div
|
2023-07-20 09:44:57 +00:00
|
|
|
className={`group flex items-center rounded-md px-2 py-1.5 gap-2.5 text-xs font-medium outline-none ${
|
2023-07-10 07:17:00 +00:00
|
|
|
router.asPath.includes(item.href)
|
2023-07-13 13:05:43 +00:00
|
|
|
? "bg-custom-primary-100/10 text-custom-primary-100"
|
|
|
|
: "text-custom-sidebar-text-200 hover:bg-custom-sidebar-background-80 focus:bg-custom-sidebar-background-80"
|
|
|
|
} ${sidebarCollapse ? "justify-center" : ""}`}
|
|
|
|
>
|
2023-07-20 09:44:57 +00:00
|
|
|
<item.Icon
|
|
|
|
sx={{
|
|
|
|
fontSize: 18,
|
|
|
|
}}
|
|
|
|
/>
|
2023-07-13 13:05:43 +00:00
|
|
|
{!sidebarCollapse && item.name}
|
|
|
|
</div>
|
|
|
|
</Tooltip>
|
2023-03-06 13:08:01 +00:00
|
|
|
</a>
|
|
|
|
</Link>
|
|
|
|
);
|
|
|
|
})}
|
|
|
|
</Disclosure.Panel>
|
|
|
|
</Transition>
|
|
|
|
</>
|
|
|
|
)}
|
|
|
|
</Disclosure>
|
|
|
|
);
|
|
|
|
};
|