2023-04-13 09:42:37 +00:00
|
|
|
import React, { useCallback, useEffect, useMemo, useState } from "react";
|
2020-09-24 16:05:18 +00:00
|
|
|
import {
|
|
|
|
|
useRouteMatch,
|
|
|
|
|
useLocation,
|
|
|
|
|
useParams,
|
|
|
|
|
Route,
|
2022-08-22 17:57:07 +00:00
|
|
|
useHistory,
|
2020-09-24 16:05:18 +00:00
|
|
|
} from "react-router-dom";
|
2022-06-15 15:37:41 +00:00
|
|
|
import { getCurrentWorkspace } from "@appsmith/selectors/workspaceSelectors";
|
2020-08-28 18:51:16 +00:00
|
|
|
import { useSelector, useDispatch } from "react-redux";
|
2020-06-17 10:19:56 +00:00
|
|
|
import styled from "styled-components";
|
2020-07-08 10:14:03 +00:00
|
|
|
|
2023-05-19 18:37:06 +00:00
|
|
|
import { Tabs, Tab, TabsList, TabPanel } from "design-system";
|
2022-11-03 16:39:51 +00:00
|
|
|
import MemberSettings from "@appsmith/pages/workspace/Members";
|
2020-08-28 18:51:16 +00:00
|
|
|
import { GeneralSettings } from "./General";
|
2020-09-24 16:05:18 +00:00
|
|
|
import * as Sentry from "@sentry/react";
|
2023-09-11 04:14:32 +00:00
|
|
|
import { getAllApplications } from "@appsmith/actions/applicationActions";
|
2021-10-04 15:34:37 +00:00
|
|
|
import { useMediaQuery } from "react-responsive";
|
2022-08-27 14:27:10 +00:00
|
|
|
import { BackButton, StickyHeader } from "components/utils/helperComponents";
|
2022-08-22 17:57:07 +00:00
|
|
|
import { debounce } from "lodash";
|
2023-10-08 18:48:46 +00:00
|
|
|
import WorkspaceInviteUsersForm from "pages/workspace/WorkspaceInviteUsersForm";
|
2022-08-22 17:57:07 +00:00
|
|
|
import { SettingsPageHeader } from "./SettingsPageHeader";
|
2022-09-02 17:15:08 +00:00
|
|
|
import { navigateToTab } from "@appsmith/pages/workspace/helpers";
|
2022-12-07 05:37:59 +00:00
|
|
|
import {
|
|
|
|
|
isPermitted,
|
|
|
|
|
PERMISSION_TYPE,
|
|
|
|
|
} from "@appsmith/utils/permissionHelpers";
|
2022-12-20 06:49:57 +00:00
|
|
|
import {
|
|
|
|
|
createMessage,
|
|
|
|
|
INVITE_USERS_PLACEHOLDER,
|
2023-03-14 06:11:52 +00:00
|
|
|
SEARCH_USERS,
|
2022-12-20 06:49:57 +00:00
|
|
|
} from "@appsmith/constants/messages";
|
2023-03-31 11:37:09 +00:00
|
|
|
import { APPLICATIONS_URL } from "constants/routes";
|
2023-05-19 18:37:06 +00:00
|
|
|
import FormDialogComponent from "components/editorComponents/form/FormDialogComponent";
|
2023-10-05 06:38:35 +00:00
|
|
|
import { useFeatureFlag } from "utils/hooks/useFeatureFlag";
|
|
|
|
|
import { FEATURE_FLAG } from "@appsmith/entities/FeatureFlag";
|
2022-08-22 17:57:07 +00:00
|
|
|
|
2020-09-24 16:05:18 +00:00
|
|
|
const SentryRoute = Sentry.withSentryRouting(Route);
|
2020-06-17 10:19:56 +00:00
|
|
|
|
2023-10-11 07:35:24 +00:00
|
|
|
interface TabProp {
|
2023-05-19 18:37:06 +00:00
|
|
|
key: string;
|
|
|
|
|
title: string;
|
|
|
|
|
count?: number;
|
|
|
|
|
panelComponent?: JSX.Element;
|
2023-10-11 07:35:24 +00:00
|
|
|
}
|
2023-05-19 18:37:06 +00:00
|
|
|
|
2021-10-04 15:34:37 +00:00
|
|
|
const SettingsWrapper = styled.div<{
|
|
|
|
|
isMobile?: boolean;
|
|
|
|
|
}>`
|
2023-05-19 18:37:06 +00:00
|
|
|
width: ${(props) => (props.isMobile ? "345px" : "978px")};
|
|
|
|
|
margin: var(--ads-v2-spaces-7) auto;
|
2022-08-27 14:27:10 +00:00
|
|
|
height: 100%;
|
2023-05-19 18:37:06 +00:00
|
|
|
padding-left: var(--ads-v2-spaces-7);
|
|
|
|
|
overflow: hidden;
|
|
|
|
|
padding-left: ${(props) =>
|
|
|
|
|
props.isMobile ? "0" : "var(--ads-v2-spaces-7);"};
|
2022-08-27 14:27:10 +00:00
|
|
|
&::-webkit-scrollbar {
|
|
|
|
|
width: 0px;
|
|
|
|
|
}
|
|
|
|
|
.tabs-wrapper {
|
|
|
|
|
height: 100%;
|
|
|
|
|
${({ isMobile }) =>
|
|
|
|
|
!isMobile &&
|
|
|
|
|
`
|
2023-05-19 18:37:06 +00:00
|
|
|
padding: 106px 0 0;
|
2022-08-27 14:27:10 +00:00
|
|
|
`}
|
|
|
|
|
}
|
|
|
|
|
`;
|
|
|
|
|
|
|
|
|
|
const StyledStickyHeader = styled(StickyHeader)<{ isMobile?: boolean }>`
|
2023-05-19 18:37:06 +00:00
|
|
|
/* padding-top: 24px; */
|
2022-08-27 14:27:10 +00:00
|
|
|
${({ isMobile }) =>
|
|
|
|
|
!isMobile &&
|
|
|
|
|
`
|
2023-05-19 18:37:06 +00:00
|
|
|
top: 72px;
|
2022-08-27 14:27:10 +00:00
|
|
|
position: fixed;
|
2023-05-19 18:37:06 +00:00
|
|
|
width: 954px;
|
2022-08-27 14:27:10 +00:00
|
|
|
`}
|
|
|
|
|
`;
|
|
|
|
|
export const TabsWrapper = styled.div`
|
2023-05-19 18:37:06 +00:00
|
|
|
padding-top: var(--ads-v2-spaces-4);
|
|
|
|
|
|
|
|
|
|
.ads-v2-tabs {
|
|
|
|
|
height: 100%;
|
|
|
|
|
overflow: hidden;
|
|
|
|
|
|
|
|
|
|
.tab-panel {
|
|
|
|
|
overflow: auto;
|
|
|
|
|
height: calc(100% - 46px);
|
|
|
|
|
}
|
2022-08-27 14:27:10 +00:00
|
|
|
}
|
2020-09-16 11:50:47 +00:00
|
|
|
`;
|
2022-08-22 17:57:07 +00:00
|
|
|
|
2022-12-07 05:37:59 +00:00
|
|
|
enum TABS {
|
|
|
|
|
GENERAL = "general",
|
|
|
|
|
MEMBERS = "members",
|
|
|
|
|
}
|
|
|
|
|
|
2020-08-28 18:51:16 +00:00
|
|
|
export default function Settings() {
|
2022-06-15 15:37:41 +00:00
|
|
|
const { workspaceId } = useParams<{ workspaceId: string }>();
|
|
|
|
|
const currentWorkspace = useSelector(getCurrentWorkspace).filter(
|
|
|
|
|
(el) => el.id === workspaceId,
|
2020-11-25 12:24:14 +00:00
|
|
|
)[0];
|
2020-08-28 18:51:16 +00:00
|
|
|
const { path } = useRouteMatch();
|
|
|
|
|
const location = useLocation();
|
|
|
|
|
const dispatch = useDispatch();
|
2022-08-22 17:57:07 +00:00
|
|
|
|
|
|
|
|
const [showModal, setShowModal] = useState(false);
|
|
|
|
|
const [searchValue, setSearchValue] = useState("");
|
|
|
|
|
|
|
|
|
|
const [pageTitle, setPageTitle] = useState<string>("");
|
|
|
|
|
|
|
|
|
|
const history = useHistory();
|
|
|
|
|
|
2023-10-05 06:38:35 +00:00
|
|
|
const isGACEnabled = useFeatureFlag(FEATURE_FLAG.license_gac_enabled);
|
|
|
|
|
|
2022-12-07 05:37:59 +00:00
|
|
|
const currentTab = location.pathname.split("/").pop();
|
2023-05-19 18:37:06 +00:00
|
|
|
// const [selectedTab, setSelectedTab] = useState(currentTab);
|
2022-12-07 05:37:59 +00:00
|
|
|
|
2023-04-03 14:26:34 +00:00
|
|
|
const isMemberofTheWorkspace = isPermitted(
|
|
|
|
|
currentWorkspace?.userPermissions || [],
|
|
|
|
|
PERMISSION_TYPE.INVITE_USER_TO_WORKSPACE,
|
|
|
|
|
);
|
|
|
|
|
const hasManageWorkspacePermissions = isPermitted(
|
|
|
|
|
currentWorkspace?.userPermissions,
|
|
|
|
|
PERMISSION_TYPE.MANAGE_WORKSPACE,
|
|
|
|
|
);
|
2023-04-13 09:42:37 +00:00
|
|
|
const shouldRedirect = useMemo(
|
|
|
|
|
() =>
|
|
|
|
|
currentWorkspace &&
|
|
|
|
|
((!isMemberofTheWorkspace && currentTab === TABS.MEMBERS) ||
|
|
|
|
|
(!hasManageWorkspacePermissions && currentTab === TABS.GENERAL)),
|
|
|
|
|
[
|
|
|
|
|
currentWorkspace,
|
|
|
|
|
isMemberofTheWorkspace,
|
|
|
|
|
hasManageWorkspacePermissions,
|
|
|
|
|
currentTab,
|
|
|
|
|
],
|
|
|
|
|
);
|
2023-04-03 14:26:34 +00:00
|
|
|
|
2022-08-22 17:57:07 +00:00
|
|
|
const onButtonClick = () => {
|
|
|
|
|
setShowModal(true);
|
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
useEffect(() => {
|
2023-04-13 09:42:37 +00:00
|
|
|
if (shouldRedirect) {
|
2023-03-31 11:37:09 +00:00
|
|
|
history.replace(APPLICATIONS_URL);
|
|
|
|
|
}
|
2022-08-22 17:57:07 +00:00
|
|
|
if (currentWorkspace) {
|
2022-12-22 17:40:56 +00:00
|
|
|
setPageTitle(`${currentWorkspace?.name}`);
|
2022-08-22 17:57:07 +00:00
|
|
|
}
|
2023-04-13 09:42:37 +00:00
|
|
|
}, [currentWorkspace, shouldRedirect]);
|
2022-08-22 17:57:07 +00:00
|
|
|
|
2020-08-28 18:51:16 +00:00
|
|
|
useEffect(() => {
|
2022-06-15 15:37:41 +00:00
|
|
|
if (!currentWorkspace) {
|
2020-11-25 12:24:14 +00:00
|
|
|
dispatch(getAllApplications());
|
|
|
|
|
}
|
2022-06-15 15:37:41 +00:00
|
|
|
}, [dispatch, currentWorkspace]);
|
2020-08-28 18:51:16 +00:00
|
|
|
|
2022-12-07 05:37:59 +00:00
|
|
|
const GeneralSettingsComponent = (
|
|
|
|
|
<SentryRoute
|
|
|
|
|
component={GeneralSettings}
|
|
|
|
|
location={location}
|
|
|
|
|
path={`${path}/general`}
|
|
|
|
|
/>
|
|
|
|
|
);
|
|
|
|
|
|
|
|
|
|
const MemberSettingsComponent = (
|
|
|
|
|
<SentryRoute
|
|
|
|
|
component={useCallback(
|
|
|
|
|
(props: any) => (
|
|
|
|
|
<MemberSettings {...props} searchValue={searchValue} />
|
|
|
|
|
),
|
|
|
|
|
[location, searchValue],
|
|
|
|
|
)}
|
|
|
|
|
location={location}
|
|
|
|
|
path={`${path}/members`}
|
|
|
|
|
/>
|
2020-07-08 10:14:03 +00:00
|
|
|
);
|
|
|
|
|
|
2022-08-22 17:57:07 +00:00
|
|
|
const onSearch = debounce((search: string) => {
|
|
|
|
|
if (search.trim().length > 0) {
|
|
|
|
|
setSearchValue(search);
|
|
|
|
|
} else {
|
|
|
|
|
setSearchValue("");
|
|
|
|
|
}
|
|
|
|
|
}, 300);
|
|
|
|
|
|
2020-08-28 18:51:16 +00:00
|
|
|
const tabArr: TabProp[] = [
|
2022-12-07 05:37:59 +00:00
|
|
|
isMemberofTheWorkspace && {
|
2022-08-22 17:57:07 +00:00
|
|
|
key: "members",
|
|
|
|
|
title: "Members",
|
2022-12-07 05:37:59 +00:00
|
|
|
panelComponent: MemberSettingsComponent,
|
2020-06-17 10:19:56 +00:00
|
|
|
},
|
2020-06-25 18:48:07 +00:00
|
|
|
{
|
2022-08-22 17:57:07 +00:00
|
|
|
key: "general",
|
|
|
|
|
title: "General Settings",
|
2022-12-07 05:37:59 +00:00
|
|
|
panelComponent: GeneralSettingsComponent,
|
2020-06-25 18:48:07 +00:00
|
|
|
},
|
2022-12-07 05:37:59 +00:00
|
|
|
].filter(Boolean) as TabProp[];
|
2022-08-22 17:57:07 +00:00
|
|
|
|
2023-05-19 18:37:06 +00:00
|
|
|
const pageMenuItems: any[] = [
|
2022-08-22 17:57:07 +00:00
|
|
|
{
|
|
|
|
|
icon: "book-line",
|
|
|
|
|
className: "documentation-page-menu-item",
|
|
|
|
|
onSelect: () => {
|
|
|
|
|
/*console.log("hello onSelect")*/
|
|
|
|
|
},
|
|
|
|
|
text: "Documentation",
|
|
|
|
|
},
|
|
|
|
|
];
|
|
|
|
|
|
2022-12-07 05:37:59 +00:00
|
|
|
const isMembersPage = tabArr.length > 1 && currentTab === TABS.MEMBERS;
|
2023-05-19 18:37:06 +00:00
|
|
|
// const isGeneralPage = tabArr.length === 1 && currentTab === TABS.GENERAL;
|
2022-12-07 05:37:59 +00:00
|
|
|
|
2021-10-04 15:34:37 +00:00
|
|
|
const isMobile: boolean = useMediaQuery({ maxWidth: 767 });
|
2019-12-23 12:16:33 +00:00
|
|
|
return (
|
2022-08-22 17:57:07 +00:00
|
|
|
<>
|
|
|
|
|
<SettingsWrapper data-testid="t--settings-wrapper" isMobile={isMobile}>
|
2022-08-27 14:27:10 +00:00
|
|
|
<StyledStickyHeader isMobile={isMobile}>
|
|
|
|
|
<BackButton goTo="/applications" />
|
|
|
|
|
<SettingsPageHeader
|
|
|
|
|
buttonText="Add users"
|
|
|
|
|
onButtonClick={onButtonClick}
|
|
|
|
|
onSearch={onSearch}
|
|
|
|
|
pageMenuItems={pageMenuItems}
|
2023-10-05 06:38:35 +00:00
|
|
|
searchPlaceholder={createMessage(SEARCH_USERS, !isGACEnabled)}
|
2022-08-27 14:27:10 +00:00
|
|
|
showMoreOptions={false}
|
2022-12-22 17:40:56 +00:00
|
|
|
showSearchNButton={isMembersPage}
|
2022-08-27 14:27:10 +00:00
|
|
|
title={pageTitle}
|
|
|
|
|
/>
|
|
|
|
|
</StyledStickyHeader>
|
|
|
|
|
<TabsWrapper
|
|
|
|
|
className="tabs-wrapper"
|
|
|
|
|
data-testid="t--user-edit-tabs-wrapper"
|
|
|
|
|
>
|
2023-05-19 18:37:06 +00:00
|
|
|
<Tabs
|
|
|
|
|
defaultValue={currentTab}
|
|
|
|
|
onValueChange={(key: string) =>
|
|
|
|
|
navigateToTab(key, location, history)
|
2022-08-22 17:57:07 +00:00
|
|
|
}
|
2023-05-19 18:37:06 +00:00
|
|
|
value={currentTab}
|
|
|
|
|
>
|
|
|
|
|
<TabsList>
|
|
|
|
|
{tabArr.map((tab) => {
|
|
|
|
|
return (
|
|
|
|
|
<Tab
|
|
|
|
|
data-testid={`t--tab-${tab.key}`}
|
|
|
|
|
key={tab.key}
|
|
|
|
|
value={tab.key}
|
|
|
|
|
>
|
|
|
|
|
<div className="tab-item">{tab.title}</div>
|
|
|
|
|
</Tab>
|
|
|
|
|
);
|
|
|
|
|
})}
|
|
|
|
|
</TabsList>
|
|
|
|
|
{tabArr.map((tab) => {
|
|
|
|
|
return (
|
|
|
|
|
<TabPanel className="tab-panel" key={tab.key} value={tab.key}>
|
|
|
|
|
{tab.panelComponent}
|
|
|
|
|
</TabPanel>
|
|
|
|
|
);
|
|
|
|
|
})}
|
|
|
|
|
</Tabs>
|
2022-08-22 17:57:07 +00:00
|
|
|
</TabsWrapper>
|
|
|
|
|
</SettingsWrapper>
|
2023-05-19 18:37:06 +00:00
|
|
|
{currentWorkspace && (
|
|
|
|
|
<FormDialogComponent
|
|
|
|
|
Form={WorkspaceInviteUsersForm}
|
|
|
|
|
hideDefaultTrigger
|
|
|
|
|
isOpen={showModal}
|
|
|
|
|
onClose={() => setShowModal(false)}
|
2023-10-05 06:38:35 +00:00
|
|
|
placeholder={createMessage(INVITE_USERS_PLACEHOLDER, !isGACEnabled)}
|
2023-05-19 18:37:06 +00:00
|
|
|
workspace={currentWorkspace}
|
|
|
|
|
/>
|
|
|
|
|
)}
|
2022-08-22 17:57:07 +00:00
|
|
|
</>
|
2019-12-23 12:16:33 +00:00
|
|
|
);
|
2020-08-28 18:51:16 +00:00
|
|
|
}
|