2023-09-01 11:12:30 +00:00
|
|
|
import { useEffect } from "react";
|
2023-09-01 11:40:06 +00:00
|
|
|
|
|
|
|
import Link from "next/link";
|
2023-09-01 11:12:30 +00:00
|
|
|
import { useRouter } from "next/router";
|
2023-09-01 11:40:06 +00:00
|
|
|
|
|
|
|
// mobx
|
|
|
|
import { observer } from "mobx-react-lite";
|
2023-08-11 11:48:33 +00:00
|
|
|
// components
|
2023-12-01 07:55:48 +00:00
|
|
|
// import { NavbarSearch } from "./search";
|
2023-08-11 11:48:33 +00:00
|
|
|
import { NavbarIssueBoardView } from "./issue-board-view";
|
|
|
|
import { NavbarTheme } from "./theme";
|
2023-09-01 11:40:06 +00:00
|
|
|
// ui
|
2023-12-05 10:37:25 +00:00
|
|
|
import { Avatar, Button } from "@plane/ui";
|
|
|
|
import { Briefcase } from "lucide-react";
|
2023-09-01 11:12:30 +00:00
|
|
|
// lib
|
2023-08-11 11:48:33 +00:00
|
|
|
import { useMobxStore } from "lib/mobx/store-provider";
|
2023-09-01 11:12:30 +00:00
|
|
|
// store
|
2023-08-11 11:48:33 +00:00
|
|
|
import { RootStore } from "store/root";
|
|
|
|
|
2023-08-16 07:45:57 +00:00
|
|
|
const renderEmoji = (emoji: string | { name: string; color: string }) => {
|
|
|
|
if (!emoji) return;
|
|
|
|
|
|
|
|
if (typeof emoji === "object")
|
|
|
|
return (
|
|
|
|
<span style={{ color: emoji.color }} className="material-symbols-rounded text-lg">
|
|
|
|
{emoji.name}
|
|
|
|
</span>
|
|
|
|
);
|
|
|
|
else return isNaN(parseInt(emoji)) ? emoji : String.fromCodePoint(parseInt(emoji));
|
|
|
|
};
|
|
|
|
|
2023-08-11 11:48:33 +00:00
|
|
|
const IssueNavbar = observer(() => {
|
2023-09-01 11:40:06 +00:00
|
|
|
const { project: projectStore, user: userStore }: RootStore = useMobxStore();
|
2023-09-01 11:12:30 +00:00
|
|
|
// router
|
|
|
|
const router = useRouter();
|
|
|
|
const { workspace_slug, project_slug, board } = router.query;
|
|
|
|
|
2023-09-01 11:40:06 +00:00
|
|
|
const user = userStore?.currentUser;
|
|
|
|
|
2023-09-01 11:12:30 +00:00
|
|
|
useEffect(() => {
|
|
|
|
if (workspace_slug && project_slug) {
|
|
|
|
projectStore.fetchProjectSettings(workspace_slug.toString(), project_slug.toString());
|
|
|
|
}
|
|
|
|
}, [projectStore, workspace_slug, project_slug]);
|
|
|
|
|
|
|
|
useEffect(() => {
|
2023-10-04 12:47:34 +00:00
|
|
|
if (workspace_slug && project_slug && projectStore?.deploySettings) {
|
|
|
|
const viewsAcceptable: string[] = [];
|
|
|
|
let currentBoard: string | null = null;
|
|
|
|
|
|
|
|
if (projectStore?.deploySettings?.views?.list) viewsAcceptable.push("list");
|
|
|
|
if (projectStore?.deploySettings?.views?.kanban) viewsAcceptable.push("kanban");
|
|
|
|
if (projectStore?.deploySettings?.views?.calendar) viewsAcceptable.push("calendar");
|
|
|
|
if (projectStore?.deploySettings?.views?.gantt) viewsAcceptable.push("gantt");
|
|
|
|
if (projectStore?.deploySettings?.views?.spreadsheet) viewsAcceptable.push("spreadsheet");
|
|
|
|
|
|
|
|
if (board) {
|
|
|
|
if (viewsAcceptable.includes(board.toString())) {
|
|
|
|
currentBoard = board.toString();
|
|
|
|
} else {
|
|
|
|
if (viewsAcceptable && viewsAcceptable.length > 0) {
|
|
|
|
currentBoard = viewsAcceptable[0];
|
|
|
|
}
|
|
|
|
}
|
|
|
|
} else {
|
|
|
|
if (viewsAcceptable && viewsAcceptable.length > 0) {
|
|
|
|
currentBoard = viewsAcceptable[0];
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
if (currentBoard) {
|
|
|
|
if (projectStore?.activeBoard === null || projectStore?.activeBoard !== currentBoard) {
|
|
|
|
projectStore.setActiveBoard(currentBoard);
|
|
|
|
router.push({
|
|
|
|
pathname: `/${workspace_slug}/${project_slug}`,
|
|
|
|
query: {
|
|
|
|
board: currentBoard,
|
|
|
|
},
|
|
|
|
});
|
|
|
|
}
|
2023-09-01 11:12:30 +00:00
|
|
|
}
|
|
|
|
}
|
2023-10-04 12:47:34 +00:00
|
|
|
}, [board, workspace_slug, project_slug, router, projectStore, projectStore?.deploySettings]);
|
2023-08-11 11:48:33 +00:00
|
|
|
|
|
|
|
return (
|
2023-12-01 07:55:48 +00:00
|
|
|
<div className="relative flex w-full items-center gap-4 px-5">
|
2023-08-11 11:48:33 +00:00
|
|
|
{/* project detail */}
|
2023-12-01 07:55:48 +00:00
|
|
|
<div className="flex flex-shrink-0 items-center gap-2">
|
|
|
|
<div className="flex h-4 w-4 items-center justify-center">
|
2023-12-05 10:37:25 +00:00
|
|
|
{projectStore.project ? (
|
|
|
|
projectStore.project?.emoji ? (
|
|
|
|
<span className="grid h-7 w-7 flex-shrink-0 place-items-center rounded uppercase">
|
|
|
|
{renderEmoji(projectStore.project.emoji)}
|
|
|
|
</span>
|
|
|
|
) : projectStore.project?.icon_prop ? (
|
|
|
|
<div className="h-7 w-7 flex-shrink-0 grid place-items-center">
|
|
|
|
{renderEmoji(projectStore.project.icon_prop)}
|
|
|
|
</div>
|
|
|
|
) : (
|
|
|
|
<span className="grid h-7 w-7 flex-shrink-0 place-items-center rounded bg-gray-700 uppercase text-white">
|
|
|
|
{projectStore.project?.name.charAt(0)}
|
|
|
|
</span>
|
|
|
|
)
|
2023-08-16 07:45:57 +00:00
|
|
|
) : (
|
2023-12-05 10:37:25 +00:00
|
|
|
<span className="grid h-7 w-7 flex-shrink-0 place-items-center rounded uppercase">
|
|
|
|
<Briefcase className="h-4 w-4" />
|
|
|
|
</span>
|
2023-08-16 07:45:57 +00:00
|
|
|
)}
|
2023-08-11 11:48:33 +00:00
|
|
|
</div>
|
2023-12-01 07:55:48 +00:00
|
|
|
<div className="line-clamp-1 max-w-[300px] overflow-hidden text-lg font-medium">
|
2023-09-01 11:12:30 +00:00
|
|
|
{projectStore?.project?.name || `...`}
|
2023-08-11 11:48:33 +00:00
|
|
|
</div>
|
|
|
|
</div>
|
|
|
|
|
|
|
|
{/* issue search bar */}
|
2023-12-01 07:55:48 +00:00
|
|
|
<div className="w-full">{/* <NavbarSearch /> */}</div>
|
2023-08-11 11:48:33 +00:00
|
|
|
|
|
|
|
{/* issue views */}
|
2023-12-01 07:55:48 +00:00
|
|
|
<div className="relative flex flex-shrink-0 items-center gap-1 transition-all delay-150 ease-in-out">
|
2023-08-11 11:48:33 +00:00
|
|
|
<NavbarIssueBoardView />
|
|
|
|
</div>
|
|
|
|
|
|
|
|
{/* theming */}
|
2023-12-01 07:55:48 +00:00
|
|
|
<div className="relative flex-shrink-0">
|
2023-08-11 11:48:33 +00:00
|
|
|
<NavbarTheme />
|
2023-09-01 11:12:30 +00:00
|
|
|
</div>
|
2023-09-01 11:40:06 +00:00
|
|
|
|
|
|
|
{user ? (
|
2023-12-01 07:55:48 +00:00
|
|
|
<div className="flex items-center gap-2 rounded border border-custom-border-200 p-2">
|
2023-12-05 10:37:25 +00:00
|
|
|
<Avatar name={user?.display_name} src={user?.avatar} size={24} shape="square" className="!text-base" />
|
2023-09-01 11:40:06 +00:00
|
|
|
<h6 className="text-xs font-medium">{user.display_name}</h6>
|
|
|
|
</div>
|
|
|
|
) : (
|
|
|
|
<div className="flex-shrink-0">
|
2023-10-04 13:51:04 +00:00
|
|
|
<Link href={`/login/?next_path=${router.asPath}`}>
|
2023-12-05 10:37:25 +00:00
|
|
|
<Button variant="outline-primary">Sign in</Button>
|
2023-09-01 11:40:06 +00:00
|
|
|
</Link>
|
|
|
|
</div>
|
|
|
|
)}
|
2023-08-11 11:48:33 +00:00
|
|
|
</div>
|
|
|
|
);
|
|
|
|
});
|
|
|
|
|
|
|
|
export default IssueNavbar;
|