import React from "react"; import { useRouter } from "next/router"; import useSWR from "swr"; // icon import { PlusIcon } from "lucide-react"; // constant import { WORKSPACE_VIEWS_LIST } from "constants/fetch-keys"; // service import workspaceService from "services/workspace.service"; type Props = { handleAddView: () => void; }; export const WorkspaceViewsNavigation: React.FC = ({ handleAddView }) => { const router = useRouter(); const { workspaceSlug, globalViewId } = router.query; const { data: workspaceViews } = useSWR( workspaceSlug ? WORKSPACE_VIEWS_LIST(workspaceSlug.toString()) : null, workspaceSlug ? () => workspaceService.getAllViews(workspaceSlug.toString()) : null ); const isSelected = (pathName: string) => router.pathname.includes(pathName); React.useEffect(() => { const activeTabElement = document.getElementById("active-tab-global-view"); if (activeTabElement) activeTabElement.scrollIntoView({ behavior: "smooth", inline: "center" }); }, [globalViewId, workspaceViews]); const tabsList = [ { key: "all", label: "All Issues", selected: isSelected("workspace-views/all-issues"), onClick: () => router.replace(`/${workspaceSlug}/workspace-views/all-issues`), }, { key: "assigned", label: "Assigned", selected: isSelected("workspace-views/assigned"), onClick: () => router.replace(`/${workspaceSlug}/workspace-views/assigned`), }, { key: "created", label: "Created", selected: isSelected("workspace-views/created"), onClick: () => router.replace(`/${workspaceSlug}/workspace-views/created`), }, { key: "subscribed", label: "Subscribed", selected: isSelected("workspace-views/subscribed"), onClick: () => router.replace(`/${workspaceSlug}/workspace-views/subscribed`), }, ]; return (
{tabsList.map((tab) => ( ))} {workspaceViews && workspaceViews.length > 0 && workspaceViews?.map((view) => ( ))}
); };