2024-05-14 08:56:54 +00:00
|
|
|
"use client";
|
|
|
|
|
|
|
|
import { useEffect, FC } from "react";
|
2024-03-19 14:38:35 +00:00
|
|
|
import { observer } from "mobx-react-lite";
|
2023-09-01 11:40:06 +00:00
|
|
|
import Link from "next/link";
|
2024-05-14 08:56:54 +00:00
|
|
|
import { useRouter, useParams, useSearchParams, usePathname } from "next/navigation";
|
2023-12-05 10:37:25 +00:00
|
|
|
import { Briefcase } from "lucide-react";
|
2024-03-19 14:38:35 +00:00
|
|
|
import { Avatar, Button } from "@plane/ui";
|
2024-05-14 08:56:54 +00:00
|
|
|
// components
|
2024-03-19 14:38:35 +00:00
|
|
|
import { ProjectLogo } from "@/components/common";
|
|
|
|
import { IssueFiltersDropdown } from "@/components/issues/filters";
|
2024-05-08 17:31:20 +00:00
|
|
|
// hooks
|
2024-05-14 08:56:54 +00:00
|
|
|
import { useProject, useUser, useIssueFilter } from "@/hooks/store";
|
|
|
|
// types
|
2024-05-08 17:31:20 +00:00
|
|
|
import { TIssueBoardKeys } from "@/types/issue";
|
2024-05-14 08:56:54 +00:00
|
|
|
// components
|
2024-03-19 14:38:35 +00:00
|
|
|
import { NavbarIssueBoardView } from "./issue-board-view";
|
|
|
|
import { NavbarTheme } from "./theme";
|
2023-08-11 11:48:33 +00:00
|
|
|
|
2024-05-14 08:56:54 +00:00
|
|
|
type IssueNavbarProps = {
|
|
|
|
projectSettings: any;
|
|
|
|
workspaceSlug: string;
|
|
|
|
projectId: string;
|
|
|
|
};
|
|
|
|
|
|
|
|
const IssueNavbar: FC<IssueNavbarProps> = observer((props) => {
|
|
|
|
const { projectSettings, workspaceSlug, projectId } = props;
|
|
|
|
const { project_details, views } = projectSettings;
|
|
|
|
const { board, labels, states, priorities, peekId } = useParams<any>();
|
|
|
|
const searchParams = useSearchParams();
|
|
|
|
const pathName = usePathname();
|
|
|
|
// hooks
|
2023-09-01 11:12:30 +00:00
|
|
|
const router = useRouter();
|
2024-05-14 08:56:54 +00:00
|
|
|
// store
|
|
|
|
const { settings, activeLayout, hydrate, setActiveLayout } = useProject();
|
|
|
|
const { data: user } = useUser();
|
|
|
|
const { updateFilters } = useIssueFilter();
|
|
|
|
hydrate(projectSettings);
|
2023-09-01 11:12:30 +00:00
|
|
|
|
|
|
|
useEffect(() => {
|
2024-05-14 08:56:54 +00:00
|
|
|
if (workspaceSlug && projectId && settings) {
|
2023-10-04 12:47:34 +00:00
|
|
|
const viewsAcceptable: string[] = [];
|
2023-12-05 11:56:57 +00:00
|
|
|
let currentBoard: TIssueBoardKeys | null = null;
|
2023-10-04 12:47:34 +00:00
|
|
|
|
2024-05-14 08:56:54 +00:00
|
|
|
if (settings?.views?.list) viewsAcceptable.push("list");
|
|
|
|
if (settings?.views?.kanban) viewsAcceptable.push("kanban");
|
|
|
|
if (settings?.views?.calendar) viewsAcceptable.push("calendar");
|
|
|
|
if (settings?.views?.gantt) viewsAcceptable.push("gantt");
|
|
|
|
if (settings?.views?.spreadsheet) viewsAcceptable.push("spreadsheet");
|
2023-10-04 12:47:34 +00:00
|
|
|
|
|
|
|
if (board) {
|
|
|
|
if (viewsAcceptable.includes(board.toString())) {
|
2023-12-05 11:56:57 +00:00
|
|
|
currentBoard = board.toString() as TIssueBoardKeys;
|
2023-10-04 12:47:34 +00:00
|
|
|
} else {
|
|
|
|
if (viewsAcceptable && viewsAcceptable.length > 0) {
|
2023-12-05 11:56:57 +00:00
|
|
|
currentBoard = viewsAcceptable[0] as TIssueBoardKeys;
|
2023-10-04 12:47:34 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
} else {
|
|
|
|
if (viewsAcceptable && viewsAcceptable.length > 0) {
|
2023-12-05 11:56:57 +00:00
|
|
|
currentBoard = viewsAcceptable[0] as TIssueBoardKeys;
|
2023-10-04 12:47:34 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
if (currentBoard) {
|
2024-05-14 08:56:54 +00:00
|
|
|
if (activeLayout === null || activeLayout !== currentBoard) {
|
2023-12-05 11:56:57 +00:00
|
|
|
let params: any = { board: currentBoard };
|
2023-12-06 10:57:33 +00:00
|
|
|
if (peekId && peekId.length > 0) params = { ...params, peekId: peekId };
|
2023-12-05 11:56:57 +00:00
|
|
|
if (priorities && priorities.length > 0) params = { ...params, priorities: priorities };
|
|
|
|
if (states && states.length > 0) params = { ...params, states: states };
|
|
|
|
if (labels && labels.length > 0) params = { ...params, labels: labels };
|
2024-05-14 08:56:54 +00:00
|
|
|
console.log("params", params);
|
2023-12-05 11:56:57 +00:00
|
|
|
let storeParams: any = {};
|
|
|
|
if (priorities && priorities.length > 0) storeParams = { ...storeParams, priority: priorities.split(",") };
|
|
|
|
if (states && states.length > 0) storeParams = { ...storeParams, state: states.split(",") };
|
|
|
|
if (labels && labels.length > 0) storeParams = { ...storeParams, labels: labels.split(",") };
|
|
|
|
|
2024-05-14 08:56:54 +00:00
|
|
|
if (storeParams) updateFilters(projectId, storeParams);
|
|
|
|
setActiveLayout(currentBoard);
|
|
|
|
router.push(`/${workspaceSlug}/${projectId}?${searchParams}`);
|
2023-10-04 12:47:34 +00:00
|
|
|
}
|
2023-09-01 11:12:30 +00:00
|
|
|
}
|
|
|
|
}
|
2023-12-06 15:01:42 +00:00
|
|
|
}, [
|
|
|
|
board,
|
2024-05-14 08:56:54 +00:00
|
|
|
workspaceSlug,
|
|
|
|
projectId,
|
2023-12-06 15:01:42 +00:00
|
|
|
router,
|
|
|
|
updateFilters,
|
|
|
|
labels,
|
|
|
|
states,
|
|
|
|
priorities,
|
|
|
|
peekId,
|
2024-05-14 08:56:54 +00:00
|
|
|
settings,
|
|
|
|
activeLayout,
|
|
|
|
setActiveLayout,
|
|
|
|
searchParams,
|
2023-12-06 15:01:42 +00:00
|
|
|
]);
|
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">
|
2024-05-14 08:56:54 +00:00
|
|
|
{project_details ? (
|
2024-03-06 13:45:48 +00:00
|
|
|
<span className="h-7 w-7 flex-shrink-0 grid place-items-center">
|
2024-05-14 08:56:54 +00:00
|
|
|
<ProjectLogo logo={project_details.logo_props} className="text-lg" />
|
2024-03-06 13:45:48 +00:00
|
|
|
</span>
|
|
|
|
) : (
|
|
|
|
<span className="grid h-7 w-7 flex-shrink-0 place-items-center rounded uppercase">
|
|
|
|
<Briefcase className="h-4 w-4" />
|
|
|
|
</span>
|
|
|
|
)}
|
2023-12-01 07:55:48 +00:00
|
|
|
<div className="line-clamp-1 max-w-[300px] overflow-hidden text-lg font-medium">
|
2024-05-14 08:56:54 +00:00
|
|
|
{project_details?.name || `...`}
|
2023-08-11 11:48:33 +00:00
|
|
|
</div>
|
|
|
|
</div>
|
|
|
|
|
|
|
|
{/* 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">
|
2024-05-14 08:56:54 +00:00
|
|
|
<NavbarIssueBoardView layouts={views} />
|
2023-08-11 11:48:33 +00:00
|
|
|
</div>
|
|
|
|
|
2023-12-05 11:56:57 +00:00
|
|
|
{/* issue filters */}
|
|
|
|
<div className="relative flex flex-shrink-0 items-center gap-1 transition-all delay-150 ease-in-out">
|
2024-05-14 08:56:54 +00:00
|
|
|
<IssueFiltersDropdown workspaceSlug={workspaceSlug} projectId={projectId} />
|
2023-12-05 11:56:57 +00:00
|
|
|
</div>
|
|
|
|
|
2023-08-11 11:48:33 +00:00
|
|
|
{/* 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
|
|
|
|
2024-05-14 08:56:54 +00:00
|
|
|
{user?.id ? (
|
2023-12-01 07:55:48 +00:00
|
|
|
<div className="flex items-center gap-2 rounded border border-custom-border-200 p-2">
|
2024-05-08 17:31:20 +00:00
|
|
|
<Avatar name={user?.display_name} src={user?.avatar ?? undefined} shape="square" size="sm" />
|
2023-09-01 11:40:06 +00:00
|
|
|
<h6 className="text-xs font-medium">{user.display_name}</h6>
|
|
|
|
</div>
|
|
|
|
) : (
|
|
|
|
<div className="flex-shrink-0">
|
2024-05-14 08:56:54 +00:00
|
|
|
<Link href={`/?next_path=${pathName}`}>
|
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;
|