PromucFlow_constructor/app/client/src/pages/workspace/settings.tsx

227 lines
5.9 KiB
TypeScript
Raw Normal View History

import React, { useCallback, useEffect, 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";
chore: migrate toast (#17208) * Refactor toast to be passed the dispatch hook externally * Add comments explaining dilemma * use store.dispatch instead of a hook * use alpha version * Change imports * Refactor DebugButton out * update release * fix issue with incorrectly merged package.lock * fix syntax of alpha version * bump ds vesion * copy lock from release * update lock to have alpha * make changes * delete Toast * DS package version updated * import change from release * use new alpha version * update ds version * update ds version * chore: migrate editable text and friends (#17285) * Delete empty components * use alpha for ds * Deleted EditableTextSubComponent, import changes * Delete EditableText, import changes * use ds alpha 10 * Delete EditableTextWrapper.tsx * update ds to use next minor version * use new alpha * fix issue with merge Co-authored-by: Albin <albin@appsmith.com> * chore: migrate file picker v2 (#17308) * use alpha ds * Delete FilePickerV2, import changes * Delete FilePicker, change imports * update alpha version * chore: move copy url form into setting components (#17322) * move CopyUrlForm to src/pages/settings/formgroup * update ds version to use next minor release * feat: Migrate table component to design system (#17329) * feat: Migrate table component to design system * removed commented code in ads index file * fix: table no data hover effect removed Co-authored-by: Tanvi Bhakta <tanvibhakta@gmail.com> * feat: Banner message component migrated to design system (#17327) * feat: Banner image component migrated to design system * Version update for design system package * design system version updated Co-authored-by: Tanvi Bhakta <tanvibhakta@gmail.com> * feat: Tabs component migrated to design system (#17321) * feat: Tabs component migrated to design system * design system package version updated * Update app/client/src/components/editorComponents/form/FormDialogComponent.tsx * Update app/client/src/pages/Editor/PropertyPane/PropertyPaneTab.tsx * Tab component expand issue fix Co-authored-by: Tanvi Bhakta <tanvibhakta@gmail.com> Co-authored-by: Albin <albin@appsmith.com> Co-authored-by: albinAppsmith <87797149+albinAppsmith@users.noreply.github.com>
2022-10-13 20:13:44 +00:00
import { MenuItemProps, TabComponent, TabProp } from "design-system";
import styled from "styled-components";
import MemberSettings from "@appsmith/pages/workspace/Members";
import { GeneralSettings } from "./General";
import * as Sentry from "@sentry/react";
import { getAllApplications } from "actions/applicationActions";
import { useMediaQuery } from "react-responsive";
import { BackButton, StickyHeader } from "components/utils/helperComponents";
import { debounce } from "lodash";
import FormDialogComponent from "components/editorComponents/form/FormDialogComponent";
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,
} from "@appsmith/constants/messages";
const SentryRoute = Sentry.withSentryRouting(Route);
const SettingsWrapper = styled.div<{
isMobile?: boolean;
}>`
width: ${(props) => (props.isMobile ? "345px" : "916px")};
Homepage redesign with themes (#482) * Updating homepage body color * WIP: Fixing scrolls and adding anchors * Removing divider from bottom of the page. * Adding hover background color to app card * Changing edit and launch icons. * Fixing app name paddding in card. * Fixing workspaces overflow * Adding right padding to applications view * Adding share icon to share btn * Fixing Application card styles. * Fixing text decoration in button. * Adding new workspace button * Fixing new workspace and new app styles. * Adding icon sizes. * Fixing Org Name and Org settings menu. * Application menu working * Fixing overlay visibility on app card * Fixing settings page content width. * Fixing workspace icon * Changing app card colors. * Removing debugger * Adding app icon. * Fixing the spaces in application card * Adding storybook-static folder to gitignore. * Adding other storybook files. * Adding menu items for app * Removing cypress selector from text. * Menu width issue fixed * Default app icon color added * Removing hardcoded colors * Removing hardcoded colors. * Light Mode on! * Showing correct icon and color in menu * Update color working properly. * Updating appIcon * Editable text working. * Adding validator * Adding edit permissions to menu * Removing box shadow on app card. * Fixing context menu fill color * Fixing Menu hover issues. * Fixing menu open close hover issues. * Fixing settings pages * Changed Workspace to org. * Fix: State management in EditableText Component (#540) * Error state height is fixed as per design * savingState prop condition fixed * Fixing createnew. * Fixing saving state for application card. * Fixed application card editable text error. * Fixing issue caused during merge. * Fixing tests in create org. * Removing commented code. * Removing unwanted vars. * Fixing delete duplicate tests. * Latest color palette. * Fixing form and table widget. * Removing switcher from header * Removing unused files * Fixing app card context dropdown * Show overlay fix * Adding localStorage support to theme. * Making dark mode the default. Co-authored-by: Rohit Kumawat <rohit.kumawat@primathon.in>
2020-09-16 11:50:47 +00:00
margin: 0 auto;
height: 100%;
&::-webkit-scrollbar {
width: 0px;
}
.tabs-wrapper {
height: 100%;
${({ isMobile }) =>
!isMobile &&
`
padding: 104px 0 0;
`}
}
`;
const StyledStickyHeader = styled(StickyHeader)<{ isMobile?: boolean }>`
padding-top: 24px;
${({ isMobile }) =>
!isMobile &&
`
top: 48px;
position: fixed;
width: 916px;
`}
`;
export const TabsWrapper = styled.div`
.react-tabs {
margin-left: 8px;
}
.react-tabs__tab-list {
border-bottom: 1px solid var(--appsmith-color-black-200);
padding: 36px 0 0;
width: 908px;
}
.react-tabs__tab-panel {
height: calc(100% - 76px);
}
Homepage redesign with themes (#482) * Updating homepage body color * WIP: Fixing scrolls and adding anchors * Removing divider from bottom of the page. * Adding hover background color to app card * Changing edit and launch icons. * Fixing app name paddding in card. * Fixing workspaces overflow * Adding right padding to applications view * Adding share icon to share btn * Fixing Application card styles. * Fixing text decoration in button. * Adding new workspace button * Fixing new workspace and new app styles. * Adding icon sizes. * Fixing Org Name and Org settings menu. * Application menu working * Fixing overlay visibility on app card * Fixing settings page content width. * Fixing workspace icon * Changing app card colors. * Removing debugger * Adding app icon. * Fixing the spaces in application card * Adding storybook-static folder to gitignore. * Adding other storybook files. * Adding menu items for app * Removing cypress selector from text. * Menu width issue fixed * Default app icon color added * Removing hardcoded colors * Removing hardcoded colors. * Light Mode on! * Showing correct icon and color in menu * Update color working properly. * Updating appIcon * Editable text working. * Adding validator * Adding edit permissions to menu * Removing box shadow on app card. * Fixing context menu fill color * Fixing Menu hover issues. * Fixing menu open close hover issues. * Fixing settings pages * Changed Workspace to org. * Fix: State management in EditableText Component (#540) * Error state height is fixed as per design * savingState prop condition fixed * Fixing createnew. * Fixing saving state for application card. * Fixed application card editable text error. * Fixing issue caused during merge. * Fixing tests in create org. * Removing commented code. * Removing unwanted vars. * Fixing delete duplicate tests. * Latest color palette. * Fixing form and table widget. * Removing switcher from header * Removing unused files * Fixing app card context dropdown * Show overlay fix * Adding localStorage support to theme. * Making dark mode the default. Co-authored-by: Rohit Kumawat <rohit.kumawat@primathon.in>
2020-09-16 11:50:47 +00:00
`;
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 onButtonClick = () => {
setShowModal(true);
};
useEffect(() => {
if (currentWorkspace) {
setPageTitle(`${currentWorkspace?.name}`);
}
}, [currentWorkspace]);
useEffect(() => {
if (!currentWorkspace) {
dispatch(getAllApplications());
}
}, [dispatch, currentWorkspace]);
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 isMemberofTheWorkspace = isPermitted(
currentWorkspace?.userPermissions || [],
PERMISSION_TYPE.INVITE_USER_TO_WORKSPACE,
);
const tabArr: TabProp[] = [
isMemberofTheWorkspace && {
key: "members",
title: "Members",
panelComponent: MemberSettingsComponent,
// icon: "gear",
// iconSize: IconSize.XL,
},
{
key: "general",
title: "General Settings",
panelComponent: GeneralSettingsComponent,
// icon: "user-2",
// iconSize: IconSize.XL,
},
].filter(Boolean) as TabProp[];
const pageMenuItems: MenuItemProps[] = [
{
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="Search"
showMoreOptions={false}
showSearchNButton={isMembersPage}
title={pageTitle}
/>
</StyledStickyHeader>
<TabsWrapper
className="tabs-wrapper"
data-testid="t--user-edit-tabs-wrapper"
>
<TabComponent
onSelect={(index: number) =>
navigateToTab(tabArr[index].key, location, history)
}
selectedIndex={isMembersPage ? 0 : isGeneralPage ? 0 : 1}
tabs={tabArr}
/>
</TabsWrapper>
</SettingsWrapper>
<FormDialogComponent
Form={WorkspaceInviteUsersForm}
canOutsideClickClose
isOpen={showModal}
onClose={() => setShowModal(false)}
placeholder={createMessage(INVITE_USERS_PLACEHOLDER)}
title={`Invite Users to ${currentWorkspace?.name}`}
trigger
workspaceId={workspaceId}
/>
</>
);
}