2022-03-21 15:35:24 +00:00
|
|
|
import React, { useContext } from "react";
|
2021-04-12 13:32:25 +00:00
|
|
|
import { Tab, Tabs, TabList } from "react-tabs";
|
2022-03-21 15:35:24 +00:00
|
|
|
import { InjectedRouter } from "react-router";
|
2021-04-12 13:32:25 +00:00
|
|
|
import PATHS from "router/paths";
|
2022-03-21 15:35:24 +00:00
|
|
|
import { AppContext } from "context/app";
|
2021-03-08 16:48:29 +00:00
|
|
|
|
2025-02-27 15:48:08 +00:00
|
|
|
import TabNav from "components/TabNav";
|
2022-07-26 12:05:57 +00:00
|
|
|
import MainContent from "components/MainContent";
|
2025-02-27 15:48:08 +00:00
|
|
|
import TabText from "components/TabText";
|
2022-07-26 12:05:57 +00:00
|
|
|
import classnames from "classnames";
|
2021-10-19 18:13:18 +00:00
|
|
|
|
2021-03-08 16:48:29 +00:00
|
|
|
interface ISettingSubNavItem {
|
|
|
|
|
name: string;
|
|
|
|
|
pathname: string;
|
2023-04-27 15:53:30 +00:00
|
|
|
exclude?: boolean;
|
2021-03-08 16:48:29 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
interface ISettingsWrapperProp {
|
2021-04-12 13:32:25 +00:00
|
|
|
children: JSX.Element;
|
2021-03-08 16:48:29 +00:00
|
|
|
location: {
|
2021-04-12 13:32:25 +00:00
|
|
|
pathname: string;
|
|
|
|
|
};
|
2022-03-21 15:35:24 +00:00
|
|
|
router: InjectedRouter; // v3
|
2021-03-08 16:48:29 +00:00
|
|
|
}
|
|
|
|
|
|
2023-04-28 20:13:13 +00:00
|
|
|
const baseClass = "admin-wrapper";
|
2021-03-08 16:48:29 +00:00
|
|
|
|
2023-04-28 20:13:13 +00:00
|
|
|
const AdminWrapper = ({
|
2021-10-22 15:34:45 +00:00
|
|
|
children,
|
|
|
|
|
location: { pathname },
|
2022-03-21 15:35:24 +00:00
|
|
|
router,
|
2021-10-22 15:34:45 +00:00
|
|
|
}: ISettingsWrapperProp): JSX.Element => {
|
2022-07-26 12:05:57 +00:00
|
|
|
const { isPremiumTier, isSandboxMode } = useContext(AppContext);
|
2021-06-08 17:21:50 +00:00
|
|
|
|
2023-04-27 15:53:30 +00:00
|
|
|
const settingsSubNav: ISettingSubNavItem[] = [
|
|
|
|
|
{
|
|
|
|
|
name: "Organization settings",
|
2023-08-11 13:32:02 +00:00
|
|
|
pathname: PATHS.ADMIN_ORGANIZATION,
|
2023-04-27 15:53:30 +00:00
|
|
|
exclude: isSandboxMode,
|
|
|
|
|
},
|
|
|
|
|
{
|
|
|
|
|
name: "Integrations",
|
|
|
|
|
pathname: PATHS.ADMIN_INTEGRATIONS,
|
|
|
|
|
},
|
|
|
|
|
{
|
|
|
|
|
name: "Users",
|
|
|
|
|
pathname: PATHS.ADMIN_USERS,
|
|
|
|
|
exclude: isSandboxMode,
|
|
|
|
|
},
|
|
|
|
|
{
|
2021-06-07 23:17:16 +00:00
|
|
|
name: "Teams",
|
|
|
|
|
pathname: PATHS.ADMIN_TEAMS,
|
2023-04-27 15:53:30 +00:00
|
|
|
exclude: !isPremiumTier,
|
|
|
|
|
},
|
|
|
|
|
];
|
|
|
|
|
|
|
|
|
|
const filteredSettingsSubNav = settingsSubNav.filter((navItem) => {
|
|
|
|
|
return !navItem.exclude;
|
|
|
|
|
});
|
2021-06-07 23:17:16 +00:00
|
|
|
|
2021-03-08 16:48:29 +00:00
|
|
|
const navigateToNav = (i: number): void => {
|
2023-04-27 15:53:30 +00:00
|
|
|
const navPath = filteredSettingsSubNav[i].pathname;
|
2022-03-21 15:35:24 +00:00
|
|
|
router.push(navPath);
|
2021-03-08 16:48:29 +00:00
|
|
|
};
|
|
|
|
|
|
2023-04-27 15:53:30 +00:00
|
|
|
const getTabIndex = (path: string): number => {
|
|
|
|
|
return filteredSettingsSubNav.findIndex((navItem) => {
|
|
|
|
|
// tab stays highlighted for paths that start with same pathname
|
|
|
|
|
return path.startsWith(navItem.pathname);
|
|
|
|
|
});
|
|
|
|
|
};
|
|
|
|
|
|
2022-07-26 12:05:57 +00:00
|
|
|
// we add a conditional sandbox-mode class here as we will need to make some
|
|
|
|
|
// styling changes on the settings page to have the sticky elements work
|
|
|
|
|
// with the sandbox mode expiry message
|
|
|
|
|
const classNames = classnames(baseClass, { "sandbox-mode": isSandboxMode });
|
|
|
|
|
|
2021-03-08 16:48:29 +00:00
|
|
|
return (
|
2022-07-26 12:05:57 +00:00
|
|
|
<MainContent className={classNames}>
|
2025-09-29 17:10:41 +00:00
|
|
|
<>
|
|
|
|
|
<h1>Settings</h1>
|
|
|
|
|
<TabNav>
|
2022-07-26 12:05:57 +00:00
|
|
|
<Tabs
|
|
|
|
|
selectedIndex={getTabIndex(pathname)}
|
|
|
|
|
onSelect={(i) => navigateToNav(i)}
|
|
|
|
|
>
|
|
|
|
|
<TabList>
|
2023-04-27 15:53:30 +00:00
|
|
|
{filteredSettingsSubNav.map((navItem) => {
|
2022-07-26 12:05:57 +00:00
|
|
|
// Bolding text when the tab is active causes a layout shift
|
|
|
|
|
// so we add a hidden pseudo element with the same text string
|
|
|
|
|
return (
|
|
|
|
|
<Tab key={navItem.name} data-text={navItem.name}>
|
2025-02-27 15:48:08 +00:00
|
|
|
<TabText>{navItem.name}</TabText>
|
2022-07-26 12:05:57 +00:00
|
|
|
</Tab>
|
|
|
|
|
);
|
|
|
|
|
})}
|
|
|
|
|
</TabList>
|
|
|
|
|
</Tabs>
|
2025-02-27 15:48:08 +00:00
|
|
|
</TabNav>
|
2022-07-26 12:05:57 +00:00
|
|
|
{children}
|
2025-09-29 17:10:41 +00:00
|
|
|
</>
|
2022-07-26 12:05:57 +00:00
|
|
|
</MainContent>
|
2021-03-08 16:48:29 +00:00
|
|
|
);
|
|
|
|
|
};
|
|
|
|
|
|
2023-04-28 20:13:13 +00:00
|
|
|
export default AdminWrapper;
|