2020-08-28 18:51:16 +00:00
|
|
|
import React from "react";
|
|
|
|
|
|
2020-12-01 22:01:27 +00:00
|
|
|
import { deleteOrgLogo, saveOrg, uploadOrgLogo } from "actions/orgActions";
|
2020-08-28 18:51:16 +00:00
|
|
|
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";
|
2020-12-01 22:01:27 +00:00
|
|
|
import {
|
|
|
|
|
getCurrentError,
|
|
|
|
|
getCurrentOrg,
|
|
|
|
|
} from "selectors/organizationSelectors";
|
2020-08-28 18:51:16 +00:00
|
|
|
import { useParams } from "react-router-dom";
|
|
|
|
|
import styled from "styled-components";
|
|
|
|
|
import Text, { TextType } from "components/ads/Text";
|
|
|
|
|
import { Classes } from "@blueprintjs/core";
|
2020-12-01 22:01:27 +00:00
|
|
|
import { getOrgLoadingStates } from "selectors/organizationSelectors";
|
|
|
|
|
import FilePicker, {
|
|
|
|
|
SetProgress,
|
|
|
|
|
UploadCallback,
|
|
|
|
|
} from "components/ads/FilePicker";
|
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`
|
2021-04-08 05:50:26 +00:00
|
|
|
width: 150px;
|
2020-08-28 18:51:16 +00:00
|
|
|
display: flex;
|
|
|
|
|
align-items: center;
|
|
|
|
|
`;
|
|
|
|
|
|
|
|
|
|
const SettingWrapper = styled.div`
|
|
|
|
|
width: 520px;
|
|
|
|
|
display: flex;
|
|
|
|
|
margin-bottom: 25px;
|
|
|
|
|
`;
|
|
|
|
|
|
|
|
|
|
export const SettingsHeading = styled(Text)`
|
2020-12-24 04:32:25 +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;
|
2020-12-01 22:01:27 +00:00
|
|
|
width: 320px;
|
|
|
|
|
border-radius: 0;
|
|
|
|
|
`;
|
|
|
|
|
|
|
|
|
|
const FilePickerLoader = styled.div`
|
|
|
|
|
height: 190px;
|
|
|
|
|
width: 333px;
|
2020-08-28 18:51:16 +00:00
|
|
|
border-radius: 0;
|
|
|
|
|
`;
|
|
|
|
|
|
2021-04-08 05:50:26 +00:00
|
|
|
// testing
|
|
|
|
|
export const Row = styled.div`
|
|
|
|
|
margin: 0;
|
|
|
|
|
padding: 0;
|
|
|
|
|
display: flex;
|
|
|
|
|
`;
|
|
|
|
|
|
|
|
|
|
export const Col = styled.div`
|
|
|
|
|
margin: 0;
|
|
|
|
|
padding: 0;
|
|
|
|
|
`;
|
|
|
|
|
|
2020-08-28 18:51:16 +00:00
|
|
|
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(
|
2020-12-24 04:32:25 +00:00
|
|
|
(el) => el.id === orgId,
|
2020-11-25 12:24:14 +00:00
|
|
|
)[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-12-01 22:01:27 +00:00
|
|
|
const { isFetchingOrg } = useSelector(getOrgLoadingStates);
|
|
|
|
|
const logoUploadError = useSelector(getCurrentError);
|
|
|
|
|
|
|
|
|
|
const FileUploader = (
|
|
|
|
|
file: File,
|
|
|
|
|
setProgress: SetProgress,
|
|
|
|
|
onUpload: UploadCallback,
|
|
|
|
|
) => {
|
|
|
|
|
const progress = (progressEvent: ProgressEvent) => {
|
|
|
|
|
const uploadPercentage = Math.round(
|
|
|
|
|
(progressEvent.loaded / progressEvent.total) * 100,
|
|
|
|
|
);
|
|
|
|
|
if (uploadPercentage === 100) {
|
|
|
|
|
onUpload(currentOrg.logoUrl || "");
|
|
|
|
|
}
|
|
|
|
|
setProgress(uploadPercentage);
|
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
dispatch(
|
|
|
|
|
uploadOrgLogo({
|
|
|
|
|
id: orgId as string,
|
|
|
|
|
logo: file,
|
|
|
|
|
progress: progress,
|
|
|
|
|
}),
|
|
|
|
|
);
|
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
const DeleteLogo = () => {
|
|
|
|
|
dispatch(deleteOrgLogo(orgId));
|
|
|
|
|
};
|
2020-11-25 12:24:14 +00:00
|
|
|
const isFetchingApplications = useSelector(getIsFetchingApplications);
|
2020-08-28 18:51:16 +00:00
|
|
|
|
|
|
|
|
return (
|
|
|
|
|
<>
|
2021-04-08 05:50:26 +00:00
|
|
|
<SettingsHeading type={TextType.H2}>
|
|
|
|
|
<Row>
|
|
|
|
|
<Col>General</Col>
|
|
|
|
|
</Row>
|
|
|
|
|
</SettingsHeading>
|
2020-08-28 18:51:16 +00:00
|
|
|
<SettingWrapper>
|
2021-04-08 05:50:26 +00:00
|
|
|
<Row>
|
|
|
|
|
<Col>
|
|
|
|
|
<InputLabelWrapper>
|
|
|
|
|
<Text type={TextType.H4}>Organization Name</Text>
|
|
|
|
|
</InputLabelWrapper>
|
|
|
|
|
</Col>
|
|
|
|
|
<Col>
|
2021-04-28 10:28:39 +00:00
|
|
|
{isFetchingApplications && <Loader className={Classes.SKELETON} />}
|
2021-04-08 05:50:26 +00:00
|
|
|
{!isFetchingApplications && (
|
|
|
|
|
<TextInput
|
|
|
|
|
cypressSelector="t--org-name-input"
|
2021-04-28 10:28:39 +00:00
|
|
|
defaultValue={currentOrg && currentOrg.name}
|
|
|
|
|
onChange={onWorkspaceNameChange}
|
|
|
|
|
placeholder="Organization Name"
|
|
|
|
|
validator={notEmptyValidator}
|
|
|
|
|
/>
|
2021-04-08 05:50:26 +00:00
|
|
|
)}
|
|
|
|
|
</Col>
|
|
|
|
|
</Row>
|
2020-08-28 18:51:16 +00:00
|
|
|
</SettingWrapper>
|
|
|
|
|
|
2020-12-01 22:01:27 +00:00
|
|
|
<SettingWrapper>
|
2021-04-08 05:50:26 +00:00
|
|
|
<Row className="t--organization-settings-filepicker">
|
|
|
|
|
<Col>
|
|
|
|
|
<InputLabelWrapper>
|
|
|
|
|
<Text type={TextType.H4}>Upload Logo</Text>
|
|
|
|
|
</InputLabelWrapper>
|
|
|
|
|
</Col>
|
|
|
|
|
<Col>
|
2021-04-28 10:28:39 +00:00
|
|
|
{isFetchingOrg && <FilePickerLoader className={Classes.SKELETON} />}
|
2021-04-08 05:50:26 +00:00
|
|
|
{!isFetchingOrg && (
|
|
|
|
|
<FilePicker
|
|
|
|
|
fileUploader={FileUploader}
|
|
|
|
|
logoUploadError={logoUploadError.message}
|
2021-04-28 10:28:39 +00:00
|
|
|
onFileRemoved={DeleteLogo}
|
|
|
|
|
url={currentOrg && currentOrg.logoUrl}
|
2021-04-08 05:50:26 +00:00
|
|
|
/>
|
|
|
|
|
)}
|
|
|
|
|
</Col>
|
|
|
|
|
</Row>
|
2020-12-01 22:01:27 +00:00
|
|
|
</SettingWrapper>
|
|
|
|
|
|
2020-08-28 18:51:16 +00:00
|
|
|
<SettingWrapper>
|
2021-04-08 05:50:26 +00:00
|
|
|
<Row>
|
|
|
|
|
<Col>
|
|
|
|
|
<InputLabelWrapper>
|
|
|
|
|
<Text type={TextType.H4}>Website</Text>
|
|
|
|
|
</InputLabelWrapper>
|
|
|
|
|
</Col>
|
|
|
|
|
<Col>
|
2021-04-28 10:28:39 +00:00
|
|
|
{isFetchingApplications && <Loader className={Classes.SKELETON} />}
|
2021-04-08 05:50:26 +00:00
|
|
|
{!isFetchingApplications && (
|
|
|
|
|
<TextInput
|
|
|
|
|
cypressSelector="t--org-website-input"
|
2021-04-28 10:28:39 +00:00
|
|
|
defaultValue={(currentOrg && currentOrg.website) || ""}
|
|
|
|
|
onChange={onWebsiteChange}
|
|
|
|
|
placeholder="Your website"
|
|
|
|
|
/>
|
2021-04-08 05:50:26 +00:00
|
|
|
)}
|
|
|
|
|
</Col>
|
|
|
|
|
</Row>
|
2020-08-28 18:51:16 +00:00
|
|
|
</SettingWrapper>
|
|
|
|
|
|
|
|
|
|
<SettingWrapper>
|
2021-04-08 05:50:26 +00:00
|
|
|
<Row>
|
|
|
|
|
<Col>
|
|
|
|
|
<InputLabelWrapper>
|
|
|
|
|
<Text type={TextType.H4}>Email</Text>
|
|
|
|
|
</InputLabelWrapper>
|
|
|
|
|
</Col>
|
|
|
|
|
<Col>
|
2021-04-28 10:28:39 +00:00
|
|
|
{isFetchingApplications && <Loader className={Classes.SKELETON} />}
|
2021-04-08 05:50:26 +00:00
|
|
|
{!isFetchingApplications && (
|
|
|
|
|
<TextInput
|
|
|
|
|
cypressSelector="t--org-email-input"
|
2021-04-28 10:28:39 +00:00
|
|
|
defaultValue={(currentOrg && currentOrg.email) || ""}
|
|
|
|
|
onChange={onEmailChange}
|
|
|
|
|
placeholder="Email"
|
|
|
|
|
validator={emailValidator}
|
|
|
|
|
/>
|
2021-04-08 05:50:26 +00:00
|
|
|
)}
|
|
|
|
|
</Col>
|
|
|
|
|
</Row>
|
2020-08-28 18:51:16 +00:00
|
|
|
</SettingWrapper>
|
|
|
|
|
</>
|
|
|
|
|
);
|
|
|
|
|
}
|