2020-06-17 10:19:56 +00:00
|
|
|
import React, { useEffect } from "react";
|
2020-08-28 18:51:16 +00:00
|
|
|
import { useRouteMatch, useLocation, useParams, Link } from "react-router-dom";
|
|
|
|
|
import AppRoute from "pages/common/AppRoute";
|
|
|
|
|
import { getCurrentOrg } from "selectors/organizationSelectors";
|
|
|
|
|
import { useSelector, useDispatch } from "react-redux";
|
|
|
|
|
import { TabComponent, TabProp } from "components/ads/Tabs";
|
|
|
|
|
import Text, { TextType } from "components/ads/Text";
|
|
|
|
|
import history from "utils/history";
|
2020-06-17 10:19:56 +00:00
|
|
|
import styled from "styled-components";
|
2020-07-08 10:14:03 +00:00
|
|
|
|
2020-08-28 18:51:16 +00:00
|
|
|
import MemberSettings from "./Members";
|
|
|
|
|
import IconComponent from "components/designSystems/appsmith/IconComponent";
|
|
|
|
|
import { fetchOrg } from "actions/orgActions";
|
|
|
|
|
import { GeneralSettings } from "./General";
|
2020-06-17 10:19:56 +00:00
|
|
|
|
2020-08-28 18:51:16 +00:00
|
|
|
const LinkToApplications = styled(Link)`
|
|
|
|
|
margin-bottom: 35px;
|
|
|
|
|
width: auto;
|
|
|
|
|
&:hover {
|
|
|
|
|
text-decoration: none;
|
2020-08-17 13:38:05 +00:00
|
|
|
}
|
2020-08-28 18:51:16 +00:00
|
|
|
svg {
|
2020-06-17 10:19:56 +00:00
|
|
|
cursor: pointer;
|
|
|
|
|
}
|
|
|
|
|
`;
|
|
|
|
|
|
2020-08-28 18:51:16 +00:00
|
|
|
export default function Settings() {
|
|
|
|
|
const { orgId } = useParams();
|
|
|
|
|
const currentOrg = useSelector(getCurrentOrg);
|
|
|
|
|
const { path } = useRouteMatch();
|
|
|
|
|
const location = useLocation();
|
|
|
|
|
const dispatch = useDispatch();
|
|
|
|
|
useEffect(() => {
|
|
|
|
|
dispatch(fetchOrg(orgId as string));
|
|
|
|
|
}, []);
|
|
|
|
|
|
|
|
|
|
const SettingsRenderer = (
|
|
|
|
|
<div>
|
|
|
|
|
<AppRoute
|
|
|
|
|
path={`${path}/general`}
|
|
|
|
|
component={GeneralSettings}
|
|
|
|
|
location={location}
|
|
|
|
|
name={"Settings"}
|
2020-07-08 10:14:03 +00:00
|
|
|
/>
|
2020-08-28 18:51:16 +00:00
|
|
|
<AppRoute
|
|
|
|
|
path={`${path}/members`}
|
|
|
|
|
component={MemberSettings}
|
|
|
|
|
location={location}
|
|
|
|
|
name={"Settings"}
|
|
|
|
|
/>
|
|
|
|
|
</div>
|
2020-07-08 10:14:03 +00:00
|
|
|
);
|
|
|
|
|
|
2020-08-28 18:51:16 +00:00
|
|
|
const tabArr: TabProp[] = [
|
|
|
|
|
{
|
|
|
|
|
key: "general",
|
|
|
|
|
title: "General",
|
|
|
|
|
panelComponent: SettingsRenderer,
|
2020-09-01 07:24:53 +00:00
|
|
|
icon: "general",
|
2020-06-17 10:19:56 +00:00
|
|
|
},
|
2020-06-25 18:48:07 +00:00
|
|
|
{
|
2020-08-28 18:51:16 +00:00
|
|
|
key: "members",
|
|
|
|
|
title: "Members",
|
|
|
|
|
panelComponent: SettingsRenderer,
|
2020-09-01 07:24:53 +00:00
|
|
|
icon: "user",
|
2020-06-25 18:48:07 +00:00
|
|
|
},
|
2020-08-28 18:51:16 +00:00
|
|
|
];
|
|
|
|
|
const isMembersPage = location.pathname.indexOf("members") !== -1;
|
2020-06-17 10:19:56 +00:00
|
|
|
|
2019-12-23 12:16:33 +00:00
|
|
|
return (
|
2020-08-28 18:51:16 +00:00
|
|
|
<>
|
|
|
|
|
<LinkToApplications to={"/applications"}>
|
|
|
|
|
<IconComponent iconName="chevron-left" color="#9F9F9F"></IconComponent>
|
|
|
|
|
<Text type={TextType.H1}>{currentOrg.name}</Text>
|
|
|
|
|
</LinkToApplications>
|
|
|
|
|
<TabComponent
|
|
|
|
|
tabs={tabArr}
|
|
|
|
|
selectedIndex={isMembersPage ? 1 : 0}
|
|
|
|
|
onSelect={(index: number) => {
|
|
|
|
|
const settingsStartIndex = location.pathname.indexOf("settings");
|
|
|
|
|
const settingsEndIndex = settingsStartIndex + "settings".length;
|
|
|
|
|
const hasSlash = location.pathname[settingsEndIndex] === "/";
|
|
|
|
|
let newUrl = "";
|
|
|
|
|
|
|
|
|
|
if (hasSlash) {
|
|
|
|
|
newUrl = `${location.pathname.substr(0, settingsEndIndex)}/${
|
|
|
|
|
tabArr[index].key
|
|
|
|
|
}`;
|
|
|
|
|
} else {
|
|
|
|
|
newUrl = `${location.pathname}/${tabArr[index].key}`;
|
2020-06-17 10:19:56 +00:00
|
|
|
}
|
2020-08-28 18:51:16 +00:00
|
|
|
history.push(newUrl);
|
|
|
|
|
}}
|
|
|
|
|
></TabComponent>
|
|
|
|
|
</>
|
2019-12-23 12:16:33 +00:00
|
|
|
);
|
2020-08-28 18:51:16 +00:00
|
|
|
}
|