## Description ### Fixes - [x] https://github.com/appsmithorg/appsmith/issues/19383 - [x] https://github.com/appsmithorg/appsmith/issues/19384 - [x] https://github.com/appsmithorg/appsmith/issues/19385 - [x] https://github.com/appsmithorg/appsmith/issues/19386 - [x] https://github.com/appsmithorg/appsmith/issues/19387 - [x] https://github.com/appsmithorg/appsmith/issues/19388 - [x] https://github.com/appsmithorg/appsmith/issues/19389 - [x] https://github.com/appsmithorg/appsmith/issues/19390 - [x] https://github.com/appsmithorg/appsmith/issues/19391 - [x] https://github.com/appsmithorg/appsmith/issues/19392 - [x] https://github.com/appsmithorg/appsmith/issues/19393 - [x] https://github.com/appsmithorg/appsmith/issues/19394 - [x] https://github.com/appsmithorg/appsmith/issues/19395 - [x] https://github.com/appsmithorg/appsmith/issues/19396 - [x] https://github.com/appsmithorg/appsmith/issues/19397 - [x] https://github.com/appsmithorg/appsmith/issues/19398 - [x] https://github.com/appsmithorg/appsmith/issues/19399 - [x] https://github.com/appsmithorg/appsmith/issues/19400 - [x] https://github.com/appsmithorg/appsmith/issues/19401 - [x] https://github.com/appsmithorg/appsmith/issues/19402 - [x] https://github.com/appsmithorg/appsmith/issues/19403 - [x] https://github.com/appsmithorg/appsmith/issues/19404 - [x] https://github.com/appsmithorg/appsmith/issues/19405 - [x] https://github.com/appsmithorg/appsmith/issues/19406 - [x] https://github.com/appsmithorg/appsmith/issues/19407 - [x] https://github.com/appsmithorg/appsmith/issues/19408 - [x] https://github.com/appsmithorg/appsmith/issues/19409 Fixes # (issue) > if no issue exists, please create an issue and ask the maintainers about this first Media > A video or a GIF is preferred. when using Loom, don’t embed because it looks like it’s a GIF. instead, just link to the video ## Type of change > Please delete options that are not relevant. - Bug fix (non-breaking change which fixes an issue) - New feature (non-breaking change which adds functionality) - Breaking change (fix or feature that would cause existing functionality to not work as expected) - Chore (housekeeping or task changes that don't impact user perception) - This change requires a documentation update ## How Has This Been Tested? > Please describe the tests that you ran to verify your changes. Provide instructions, so we can reproduce. > Please also list any relevant details for your test configuration. > Delete anything that is not important - Manual - Jest - Cypress ### Test Plan > Add Testsmith test cases links that relate to this PR ### Issues raised during DP testing > Link issues raised during DP testing for better visiblity and tracking (copy link from comments dropped on this PR) ## Checklist: ### Dev activity - [ ] My code follows the style guidelines of this project - [ ] I have performed a self-review of my own code - [ ] I have commented my code, particularly in hard-to-understand areas - [ ] I have made corresponding changes to the documentation - [ ] My changes generate no new warnings - [ ] I have added tests that prove my fix is effective or that my feature works - [ ] New and existing unit tests pass locally with my changes - [ ] PR is being merged under a feature flag ### QA activity: - [ ] Test plan has been approved by relevant developers - [ ] Test plan has been peer reviewed by QA - [ ] Cypress test cases have been added and approved by either SDET or manual QA - [ ] Organized project review call with relevant stakeholders after Round 1/2 of QA - [ ] Added Test Plan Approved label after reveiwing all Cypress test --------- Co-authored-by: Ankita Kinger <ankita@appsmith.com> Co-authored-by: akash-codemonk <67054171+akash-codemonk@users.noreply.github.com> Co-authored-by: Tanvi Bhakta <tanvi@appsmith.com> Co-authored-by: Arsalan <arsalanyaldram0211@outlook.com> Co-authored-by: Aman Agarwal <aman@appsmith.com> Co-authored-by: Rohit Agarwal <rohit_agarwal@live.in> Co-authored-by: Nilesh Sarupriya <nilesh@appsmith.com> Co-authored-by: Nilesh Sarupriya <20905988+nsarupr@users.noreply.github.com> Co-authored-by: Tanvi Bhakta <tanvibhakta@gmail.com> Co-authored-by: Aishwarya UR <aishwarya@appsmith.com> Co-authored-by: Parthvi Goswami <parthvigoswami@Parthvis-MacBook-Pro.local> Co-authored-by: Vijetha-Kaja <vijetha@appsmith.com> Co-authored-by: Parthvi <80334441+Parthvi12@users.noreply.github.com> Co-authored-by: Apple <nandan@thinkify.io> Co-authored-by: Saroj <43822041+sarojsarab@users.noreply.github.com> Co-authored-by: Sangeeth Sivan <74818788+berzerkeer@users.noreply.github.com> Co-authored-by: Ashok Kumar M <35134347+marks0351@users.noreply.github.com> Co-authored-by: Aishwarya-U-R <91450662+Aishwarya-U-R@users.noreply.github.com> Co-authored-by: rahulramesha <rahul@appsmith.com> Co-authored-by: Aswath K <aswath.sana@gmail.com> Co-authored-by: Preet Sidhu <preetsidhu.bits@gmail.com> Co-authored-by: Vijetha-Kaja <119562824+Vijetha-Kaja@users.noreply.github.com> Co-authored-by: Shrikant Sharat Kandula <shrikant@appsmith.com>
287 lines
7.7 KiB
TypeScript
287 lines
7.7 KiB
TypeScript
import React, { useCallback, useEffect, useMemo, useState } from "react";
|
|
import {
|
|
useRouteMatch,
|
|
useLocation,
|
|
useParams,
|
|
Route,
|
|
useHistory,
|
|
} from "react-router-dom";
|
|
import { getCurrentWorkspace } from "@appsmith/selectors/workspaceSelectors";
|
|
import { useSelector, useDispatch } from "react-redux";
|
|
import styled from "styled-components";
|
|
|
|
import { Tabs, Tab, TabsList, TabPanel } from "design-system";
|
|
import MemberSettings from "@appsmith/pages/workspace/Members";
|
|
import { GeneralSettings } from "./General";
|
|
import * as Sentry from "@sentry/react";
|
|
import {
|
|
getAllApplications,
|
|
setShowAppInviteUsersDialog,
|
|
} from "@appsmith/actions/applicationActions";
|
|
import { useMediaQuery } from "react-responsive";
|
|
import { BackButton, StickyHeader } from "components/utils/helperComponents";
|
|
import { debounce } from "lodash";
|
|
import WorkspaceInviteUsersForm from "@appsmith/pages/workspace/WorkspaceInviteUsersForm";
|
|
import { SettingsPageHeader } from "./SettingsPageHeader";
|
|
import { navigateToTab } from "@appsmith/pages/workspace/helpers";
|
|
import {
|
|
isPermitted,
|
|
PERMISSION_TYPE,
|
|
} from "@appsmith/utils/permissionHelpers";
|
|
import {
|
|
createMessage,
|
|
INVITE_USERS_PLACEHOLDER,
|
|
SEARCH_USERS,
|
|
} from "@appsmith/constants/messages";
|
|
import { getAppsmithConfigs } from "@appsmith/configs";
|
|
import { APPLICATIONS_URL } from "constants/routes";
|
|
import FormDialogComponent from "components/editorComponents/form/FormDialogComponent";
|
|
|
|
const { cloudHosting } = getAppsmithConfigs();
|
|
|
|
const SentryRoute = Sentry.withSentryRouting(Route);
|
|
|
|
type TabProp = {
|
|
key: string;
|
|
title: string;
|
|
count?: number;
|
|
panelComponent?: JSX.Element;
|
|
};
|
|
|
|
const SettingsWrapper = styled.div<{
|
|
isMobile?: boolean;
|
|
}>`
|
|
width: ${(props) => (props.isMobile ? "345px" : "978px")};
|
|
margin: var(--ads-v2-spaces-7) auto;
|
|
height: 100%;
|
|
padding-left: var(--ads-v2-spaces-7);
|
|
overflow: hidden;
|
|
padding-left: ${(props) =>
|
|
props.isMobile ? "0" : "var(--ads-v2-spaces-7);"};
|
|
&::-webkit-scrollbar {
|
|
width: 0px;
|
|
}
|
|
.tabs-wrapper {
|
|
height: 100%;
|
|
${({ isMobile }) =>
|
|
!isMobile &&
|
|
`
|
|
padding: 106px 0 0;
|
|
`}
|
|
}
|
|
`;
|
|
|
|
const StyledStickyHeader = styled(StickyHeader)<{ isMobile?: boolean }>`
|
|
/* padding-top: 24px; */
|
|
${({ isMobile }) =>
|
|
!isMobile &&
|
|
`
|
|
top: 72px;
|
|
position: fixed;
|
|
width: 954px;
|
|
`}
|
|
`;
|
|
export const TabsWrapper = styled.div`
|
|
padding-top: var(--ads-v2-spaces-4);
|
|
|
|
.ads-v2-tabs {
|
|
height: 100%;
|
|
overflow: hidden;
|
|
|
|
.tab-panel {
|
|
overflow: auto;
|
|
height: calc(100% - 46px);
|
|
}
|
|
}
|
|
`;
|
|
|
|
enum TABS {
|
|
GENERAL = "general",
|
|
MEMBERS = "members",
|
|
}
|
|
|
|
export default function Settings() {
|
|
const { workspaceId } = useParams<{ workspaceId: string }>();
|
|
const currentWorkspace = useSelector(getCurrentWorkspace).filter(
|
|
(el) => el.id === workspaceId,
|
|
)[0];
|
|
const { path } = useRouteMatch();
|
|
const location = useLocation();
|
|
const dispatch = useDispatch();
|
|
|
|
const [showModal, setShowModal] = useState(false);
|
|
const [searchValue, setSearchValue] = useState("");
|
|
|
|
const [pageTitle, setPageTitle] = useState<string>("");
|
|
|
|
const history = useHistory();
|
|
|
|
const currentTab = location.pathname.split("/").pop();
|
|
// const [selectedTab, setSelectedTab] = useState(currentTab);
|
|
|
|
const isMemberofTheWorkspace = isPermitted(
|
|
currentWorkspace?.userPermissions || [],
|
|
PERMISSION_TYPE.INVITE_USER_TO_WORKSPACE,
|
|
);
|
|
const hasManageWorkspacePermissions = isPermitted(
|
|
currentWorkspace?.userPermissions,
|
|
PERMISSION_TYPE.MANAGE_WORKSPACE,
|
|
);
|
|
const shouldRedirect = useMemo(
|
|
() =>
|
|
currentWorkspace &&
|
|
((!isMemberofTheWorkspace && currentTab === TABS.MEMBERS) ||
|
|
(!hasManageWorkspacePermissions && currentTab === TABS.GENERAL)),
|
|
[
|
|
currentWorkspace,
|
|
isMemberofTheWorkspace,
|
|
hasManageWorkspacePermissions,
|
|
currentTab,
|
|
],
|
|
);
|
|
|
|
const onButtonClick = () => {
|
|
setShowModal(true);
|
|
};
|
|
|
|
useEffect(() => {
|
|
if (shouldRedirect) {
|
|
history.replace(APPLICATIONS_URL);
|
|
}
|
|
if (currentWorkspace) {
|
|
setPageTitle(`${currentWorkspace?.name}`);
|
|
}
|
|
}, [currentWorkspace, shouldRedirect]);
|
|
|
|
useEffect(() => {
|
|
if (!currentWorkspace) {
|
|
dispatch(getAllApplications());
|
|
}
|
|
}, [dispatch, currentWorkspace]);
|
|
|
|
const handleFormOpenOrClose = useCallback((isOpen: boolean) => {
|
|
dispatch(setShowAppInviteUsersDialog(isOpen));
|
|
}, []);
|
|
|
|
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`}
|
|
/>
|
|
);
|
|
|
|
const onSearch = debounce((search: string) => {
|
|
if (search.trim().length > 0) {
|
|
setSearchValue(search);
|
|
} else {
|
|
setSearchValue("");
|
|
}
|
|
}, 300);
|
|
|
|
const tabArr: TabProp[] = [
|
|
isMemberofTheWorkspace && {
|
|
key: "members",
|
|
title: "Members",
|
|
panelComponent: MemberSettingsComponent,
|
|
},
|
|
{
|
|
key: "general",
|
|
title: "General Settings",
|
|
panelComponent: GeneralSettingsComponent,
|
|
},
|
|
].filter(Boolean) as TabProp[];
|
|
|
|
const pageMenuItems: any[] = [
|
|
{
|
|
icon: "book-line",
|
|
className: "documentation-page-menu-item",
|
|
onSelect: () => {
|
|
/*console.log("hello onSelect")*/
|
|
},
|
|
text: "Documentation",
|
|
},
|
|
];
|
|
|
|
const isMembersPage = tabArr.length > 1 && currentTab === TABS.MEMBERS;
|
|
// const isGeneralPage = tabArr.length === 1 && currentTab === TABS.GENERAL;
|
|
|
|
const isMobile: boolean = useMediaQuery({ maxWidth: 767 });
|
|
return (
|
|
<>
|
|
<SettingsWrapper data-testid="t--settings-wrapper" isMobile={isMobile}>
|
|
<StyledStickyHeader isMobile={isMobile}>
|
|
<BackButton goTo="/applications" />
|
|
<SettingsPageHeader
|
|
buttonText="Add users"
|
|
onButtonClick={onButtonClick}
|
|
onSearch={onSearch}
|
|
pageMenuItems={pageMenuItems}
|
|
searchPlaceholder={createMessage(SEARCH_USERS, cloudHosting)}
|
|
showMoreOptions={false}
|
|
showSearchNButton={isMembersPage}
|
|
title={pageTitle}
|
|
/>
|
|
</StyledStickyHeader>
|
|
<TabsWrapper
|
|
className="tabs-wrapper"
|
|
data-testid="t--user-edit-tabs-wrapper"
|
|
>
|
|
<Tabs
|
|
defaultValue={currentTab}
|
|
onValueChange={(key: string) =>
|
|
navigateToTab(key, location, history)
|
|
}
|
|
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>
|
|
</TabsWrapper>
|
|
</SettingsWrapper>
|
|
{currentWorkspace && (
|
|
<FormDialogComponent
|
|
Form={WorkspaceInviteUsersForm}
|
|
hideDefaultTrigger
|
|
isOpen={showModal}
|
|
onClose={() => setShowModal(false)}
|
|
onOpenOrClose={handleFormOpenOrClose}
|
|
placeholder={createMessage(INVITE_USERS_PLACEHOLDER, cloudHosting)}
|
|
workspace={currentWorkspace}
|
|
/>
|
|
)}
|
|
</>
|
|
);
|
|
}
|