2020-08-28 18:51:16 +00:00
|
|
|
import React from "react";
|
|
|
|
|
|
|
|
|
|
import { saveOrg } from "actions/orgActions";
|
|
|
|
|
import { SaveOrgRequest } from "api/OrgApi";
|
2020-11-25 12:24:14 +00:00
|
|
|
import { debounce } from "lodash";
|
2020-08-28 18:51:16 +00:00
|
|
|
import TextInput, {
|
|
|
|
|
emailValidator,
|
|
|
|
|
notEmptyValidator,
|
|
|
|
|
} from "components/ads/TextInput";
|
|
|
|
|
import { useSelector, useDispatch } from "react-redux";
|
|
|
|
|
import { getCurrentOrg } from "selectors/organizationSelectors";
|
|
|
|
|
import { useParams } from "react-router-dom";
|
|
|
|
|
import styled from "styled-components";
|
|
|
|
|
import Text, { TextType } from "components/ads/Text";
|
|
|
|
|
import { Classes } from "@blueprintjs/core";
|
2020-11-25 12:24:14 +00:00
|
|
|
import { getIsFetchingApplications } from "selectors/applicationSelectors";
|
|
|
|
|
|
2020-08-28 18:51:16 +00:00
|
|
|
const InputLabelWrapper = styled.div`
|
|
|
|
|
width: 200px;
|
|
|
|
|
display: flex;
|
|
|
|
|
align-items: center;
|
|
|
|
|
`;
|
|
|
|
|
|
|
|
|
|
const SettingWrapper = styled.div`
|
|
|
|
|
width: 520px;
|
|
|
|
|
display: flex;
|
|
|
|
|
margin-bottom: 25px;
|
|
|
|
|
`;
|
|
|
|
|
|
|
|
|
|
export const SettingsHeading = styled(Text)`
|
2020-09-23 14:06:50 +00:00
|
|
|
color: ${props => props.theme.colors.settingHeading};
|
2020-08-28 18:51:16 +00:00
|
|
|
display: inline-block;
|
|
|
|
|
margin-top: 25px;
|
|
|
|
|
margin-bottom: 32px;
|
|
|
|
|
`;
|
|
|
|
|
|
|
|
|
|
const Loader = styled.div`
|
|
|
|
|
height: 38px;
|
|
|
|
|
width: 260px;
|
|
|
|
|
border-radius: 0;
|
|
|
|
|
`;
|
|
|
|
|
|
|
|
|
|
export function GeneralSettings() {
|
2020-10-12 13:06:05 +00:00
|
|
|
const { orgId } = useParams<{ orgId: string }>();
|
2020-08-28 18:51:16 +00:00
|
|
|
const dispatch = useDispatch();
|
2020-11-25 12:24:14 +00:00
|
|
|
const currentOrg = useSelector(getCurrentOrg).filter(
|
|
|
|
|
el => el.id === orgId,
|
|
|
|
|
)[0];
|
2020-08-28 18:51:16 +00:00
|
|
|
function saveChanges(settings: SaveOrgRequest) {
|
|
|
|
|
dispatch(saveOrg(settings));
|
|
|
|
|
}
|
|
|
|
|
|
2020-11-25 12:24:14 +00:00
|
|
|
const timeout = 1000;
|
2020-08-28 18:51:16 +00:00
|
|
|
|
2020-11-25 12:24:14 +00:00
|
|
|
const onWorkspaceNameChange = debounce((newName: string) => {
|
2020-08-28 18:51:16 +00:00
|
|
|
saveChanges({
|
|
|
|
|
id: orgId as string,
|
|
|
|
|
name: newName,
|
|
|
|
|
});
|
2020-11-25 12:24:14 +00:00
|
|
|
}, timeout);
|
2020-08-28 18:51:16 +00:00
|
|
|
|
2020-11-25 12:24:14 +00:00
|
|
|
const onWebsiteChange = debounce((newWebsite: string) => {
|
2020-08-28 18:51:16 +00:00
|
|
|
saveChanges({
|
|
|
|
|
id: orgId as string,
|
|
|
|
|
website: newWebsite,
|
|
|
|
|
});
|
2020-11-25 12:24:14 +00:00
|
|
|
}, timeout);
|
2020-08-28 18:51:16 +00:00
|
|
|
|
2020-11-25 12:24:14 +00:00
|
|
|
const onEmailChange = debounce((newEmail: string) => {
|
2020-08-28 18:51:16 +00:00
|
|
|
saveChanges({
|
|
|
|
|
id: orgId as string,
|
|
|
|
|
email: newEmail,
|
|
|
|
|
});
|
2020-11-25 12:24:14 +00:00
|
|
|
}, timeout);
|
2020-08-28 18:51:16 +00:00
|
|
|
|
2020-11-25 12:24:14 +00:00
|
|
|
const isFetchingApplications = useSelector(getIsFetchingApplications);
|
2020-08-28 18:51:16 +00:00
|
|
|
|
|
|
|
|
return (
|
|
|
|
|
<>
|
|
|
|
|
<SettingsHeading type={TextType.H2}>General</SettingsHeading>
|
|
|
|
|
<SettingWrapper>
|
|
|
|
|
<InputLabelWrapper>
|
2020-11-04 16:06:44 +00:00
|
|
|
<Text type={TextType.H4}>Organization Name</Text>
|
2020-08-28 18:51:16 +00:00
|
|
|
</InputLabelWrapper>
|
2020-11-25 12:24:14 +00:00
|
|
|
{isFetchingApplications && (
|
|
|
|
|
<Loader className={Classes.SKELETON}></Loader>
|
|
|
|
|
)}
|
|
|
|
|
{!isFetchingApplications && (
|
2020-08-28 18:51:16 +00:00
|
|
|
<TextInput
|
|
|
|
|
validator={notEmptyValidator}
|
2020-11-25 12:24:14 +00:00
|
|
|
placeholder="Organization Name"
|
2020-08-28 18:51:16 +00:00
|
|
|
onChange={onWorkspaceNameChange}
|
2020-11-25 12:24:14 +00:00
|
|
|
defaultValue={currentOrg && currentOrg.name}
|
2020-10-28 05:39:28 +00:00
|
|
|
cypressSelector="t--org-name-input"
|
2020-08-28 18:51:16 +00:00
|
|
|
></TextInput>
|
|
|
|
|
)}
|
|
|
|
|
</SettingWrapper>
|
|
|
|
|
|
|
|
|
|
<SettingWrapper>
|
|
|
|
|
<InputLabelWrapper>
|
|
|
|
|
<Text type={TextType.H4}>Website</Text>
|
|
|
|
|
</InputLabelWrapper>
|
2020-11-25 12:24:14 +00:00
|
|
|
{isFetchingApplications && (
|
|
|
|
|
<Loader className={Classes.SKELETON}></Loader>
|
|
|
|
|
)}
|
|
|
|
|
{!isFetchingApplications && (
|
2020-08-28 18:51:16 +00:00
|
|
|
<TextInput
|
|
|
|
|
placeholder="Your website"
|
|
|
|
|
onChange={onWebsiteChange}
|
2020-11-25 12:24:14 +00:00
|
|
|
defaultValue={(currentOrg && currentOrg.website) || ""}
|
2020-10-28 05:39:28 +00:00
|
|
|
cypressSelector="t--org-website-input"
|
2020-08-28 18:51:16 +00:00
|
|
|
></TextInput>
|
|
|
|
|
)}
|
|
|
|
|
</SettingWrapper>
|
|
|
|
|
|
|
|
|
|
<SettingWrapper>
|
|
|
|
|
<InputLabelWrapper>
|
|
|
|
|
<Text type={TextType.H4}>Email</Text>
|
|
|
|
|
</InputLabelWrapper>
|
2020-11-25 12:24:14 +00:00
|
|
|
{isFetchingApplications && (
|
|
|
|
|
<Loader className={Classes.SKELETON}></Loader>
|
|
|
|
|
)}
|
|
|
|
|
{!isFetchingApplications && (
|
2020-08-28 18:51:16 +00:00
|
|
|
<TextInput
|
|
|
|
|
validator={emailValidator}
|
|
|
|
|
placeholder="Email"
|
|
|
|
|
onChange={onEmailChange}
|
2020-11-25 12:24:14 +00:00
|
|
|
defaultValue={(currentOrg && currentOrg.email) || ""}
|
2020-10-28 05:39:28 +00:00
|
|
|
cypressSelector="t--org-email-input"
|
2020-08-28 18:51:16 +00:00
|
|
|
></TextInput>
|
|
|
|
|
)}
|
|
|
|
|
</SettingWrapper>
|
|
|
|
|
</>
|
|
|
|
|
);
|
|
|
|
|
}
|