Refactoring

This commit is contained in:
Vladislav Makhov 2020-08-28 12:07:34 +03:00
parent f3991a0900
commit e67148864d
5 changed files with 41 additions and 56 deletions

View File

@ -1,6 +1,6 @@
import React from "react"; import React from "react";
import { Box, Text, ToggleButton, Icons } from "asc-web-components"; import { Box, Text, ToggleButton, Icons } from "asc-web-components";
import ConsumerModalDialog from "./modal-dialog"; import ConsumerModalDialog from "./consumerModalDialog";
class ConsumerItem extends React.Component { class ConsumerItem extends React.Component {
constructor(props) { constructor(props) {
@ -19,7 +19,7 @@ class ConsumerItem extends React.Component {
} }
render() { render() {
const { name, description, dialogVisible, consumers, onModalClose, onToggleClick, selectedConsumer } = this.props; const { dialogVisible, consumer, consumers, onModalClose, selectedConsumer } = this.props;
const { toggleActive } = this.state; const { toggleActive } = this.state;
const { onModalButtonClick } = this; const { onModalButtonClick } = this;
@ -28,12 +28,13 @@ class ConsumerItem extends React.Component {
<Box displayProp="flex" flexDirection="column"> <Box displayProp="flex" flexDirection="column">
<Box displayProp="flex" justifyContent="space-between" widthProp="100%" marginProp="21px 0 0 0"> <Box displayProp="flex" justifyContent="space-between" widthProp="100%" marginProp="21px 0 0 0">
<div> <div>
{React.createElement(Icons[`${name}Icon`], { size: "scale" })} <Text>{consumer.name}</Text>
{/* {React.createElement(Icons[`${name}Icon`], { size: "scale" })} */}
</div> </div>
</Box> </Box>
<Box displayProp="flex" marginProp="21px 0 0 0"> <Box displayProp="flex" marginProp="21px 0 0 0">
<Text> <Text>
{description} {consumer.instruction}
</Text> </Text>
</Box> </Box>
</Box> </Box>

View File

@ -28,20 +28,20 @@ const ConsumerModalDialog = (props) => {
return consumers.find((consumer) => consumer.name === selectedConsumer).name; return consumers.find((consumer) => consumer.name === selectedConsumer).name;
} }
const getInnerDescription = () => { const getInnerDescription = () => {
return consumers.find((consumer) => consumer.name === selectedConsumer).innerDescription; return consumers.find((consumer) => consumer.name === selectedConsumer).instruction;
} }
const getInputFields = () => { const getInputFields = () => {
return consumers return consumers
.find((consumer) => consumer.name === selectedConsumer) .find((consumer) => consumer.name === selectedConsumer)
.tokens .props
.map((token, i) => .map((prop, i) =>
<React.Fragment key={i}> <React.Fragment key={i}>
<Box displayProp="flex" flexDirection="column"> <Box displayProp="flex" flexDirection="column">
<Box> <Box>
<Text isBold={true}>{token}:</Text> <Text isBold={true}>{prop.title}:</Text>
</Box> </Box>
<Box> <Box>
<TextInput placeholder={token} isAutoFocussed={i === 0 && true} /> <TextInput placeholder={prop.title} isAutoFocussed={i === 0 && true} />
</Box> </Box>
</Box> </Box>
</React.Fragment> </React.Fragment>

View File

@ -6,7 +6,7 @@ const StyledToggle = styled(ToggleButton)`
position: relative; position: relative;
`; `;
class ConsumerItemToggle extends React.Component { class ConsumerToggle extends React.Component {
constructor(props) { constructor(props) {
super(props); super(props);
@ -22,33 +22,32 @@ class ConsumerItemToggle extends React.Component {
}) })
// TODO: api -> service off -> toastr // TODO: api -> service off -> toastr
} }
// this.setState({ // this.setState({
// toggleActive: true // toggleActive: true
// }); // });
else { else {
this.props.onToggleClick(); this.props.onToggleClick();
} }
} }
render() { render() {
const { name, onModalOpen } = this.props; const { name, onModalOpen, canSet } = this.props;
const { toggleActive } = this.state; const { toggleActive } = this.state;
const { onToggleClick } = this; const { onToggleClick } = this;
return ( return (
<> <>
<Box marginProp="28px 0 0 0"> <Box marginProp="28px 0 0 0">
<StyledToggle onChange={onToggleClick} <StyledToggle
isChecked={toggleActive} /> onChange={onToggleClick}
isDisabled={!canSet}
isChecked={!canSet ? true : toggleActive}
/>
</Box> </Box>
</> </>
); );
} }
} }
export default ConsumerItemToggle; export default ConsumerToggle;

View File

@ -1,26 +0,0 @@
export const consumers = [
{
name: "Amazon",
description: "Подключите Amazon AWS S3 для резервного копирования и хранения данных портала.",
innerDescription: "Добавив Amazon AWS S3, вы сможете использовать его для создания резервных копий портала, чтобы предотвратить потерю данных. Также используйте его для хранения данных и статического содержимого портала.",
tokens: ["Ключ доступа S3", "Секретный ключ доступа S3"]
},
{
name: "Bitly",
description: "Подключите это приложение для сокращения пригласительных ссылок на портал и ссылок для доступа к файлам в модуле \"Документы\" с помощью сервиса Bitly.",
innerDescription: "Добавив сервис Bitly, Вы будуте получать сокращенные ссылки для приглашения новых пользователей на портал ONLYOFFICE и сокращенные ссылки для документов в модуле \"Документы\", к которым был предоставлен доступ для внешних пользователей.",
tokens: ["login", "apiKey"]
},
{
name: "Box",
description: "Подключите приложение для управления файлами и папками Box.",
innerDescription: "Добавив приложение сервиса Box, Вы сможете подключить свой аккаунт Box в модуле \"Документы\". Это позволит загружать и создавать новые файлы в Box, редактировать существующие, копировать и удалять их, предоставлять доступ к файлам и папкам для пользователей портала ONLYOFFICE.",
tokens: ["Box ID", "Ключ Box"]
},
{
name: "Telegram",
description: "Подключите аккаунт Telegram для получения оповещений портала через Telegram.",
innerDescription: "Добавив приложение сервиса Telegram Вы сможете на странице своего профиля подключить вход на портал используя аккаунт Telegram.",
tokens: ["Токен бота", "Имя бота"]
}
]

View File

@ -1,11 +1,12 @@
import React from "react"; import React from "react";
import { consumers } from "./sub-components/consumers"; import { connect } from "react-redux";
import { getConsumers } from '../../../../../store/settings/actions';
import { withTranslation } from 'react-i18next';
import styled from "styled-components";
import { Box, Text, Link } from "asc-web-components"; import { Box, Text, Link } from "asc-web-components";
import ConsumerItem from "./sub-components/consumerItem"; import ConsumerItem from "./sub-components/consumerItem";
import { withTranslation } from 'react-i18next'; import ConsumerToggle from "./sub-components/consumerToggle";
import { connect } from "react-redux";
import ConsumerItemToggle from "./sub-components/consumerItemToggle";
import styled from "styled-components";
const RootContainer = styled(Box)` const RootContainer = styled(Box)`
@ -31,12 +32,16 @@ class ThirdPartyServices extends React.Component {
document.title = `${t("ThirdPartyAuthorization")} ${t("OrganizationName")}`; document.title = `${t("ThirdPartyAuthorization")} ${t("OrganizationName")}`;
this.state = { this.state = {
consumers: consumers,
selectedConsumer: "", selectedConsumer: "",
dialogVisible: false dialogVisible: false
} }
} }
componentDidMount() {
const { getConsumers } = this.props;
getConsumers();
}
onModalOpen = () => { onModalOpen = () => {
this.setState({ this.setState({
dialogVisible: true, dialogVisible: true,
@ -54,8 +59,8 @@ class ThirdPartyServices extends React.Component {
render() { render() {
const { t } = this.props; const { t, consumers } = this.props;
const { consumers, selectedConsumer, dialogVisible } = this.state; const { selectedConsumer, dialogVisible } = this.state;
const { titleDescription, onModalOpen, onModalClose } = this; const { titleDescription, onModalOpen, onModalClose } = this;
const consumerRefs = consumers.reduce((acc, consumer) => { const consumerRefs = consumers.reduce((acc, consumer) => {
@ -102,16 +107,17 @@ class ThirdPartyServices extends React.Component {
<Box displayProp="flex" className="consumer-item-container"> <Box displayProp="flex" className="consumer-item-container">
<ConsumerItem <ConsumerItem
ref={el => (consumerRefs[i] = el)} ref={el => (consumerRefs[i] = el)}
name={consumer.name} consumer={consumer}
description={consumer.description}
consumers={consumers} consumers={consumers}
dialogVisible={dialogVisible} dialogVisible={dialogVisible}
selectedConsumer={selectedConsumer} selectedConsumer={selectedConsumer}
onModalClose={onModalClose} onModalClose={onModalClose}
/> />
<ConsumerItemToggle <ConsumerToggle
ref={el => (toggleRefs[i] = el)} ref={el => (toggleRefs[i] = el)}
name={consumer.name} name={consumer.name}
canSet={consumer.canSet}
onToggleClick={() => { onToggleClick={() => {
this.setState({ selectedConsumer: consumer.name }) this.setState({ selectedConsumer: consumer.name })
onModalOpen() onModalOpen()
@ -127,4 +133,9 @@ class ThirdPartyServices extends React.Component {
} }
} }
export default connect(null, null)(withTranslation()(ThirdPartyServices)); const mapStateToProps = (state) => {
const { consumers } = state.settings.integration;
return { consumers }
}
export default connect(mapStateToProps, { getConsumers })(withTranslation()(ThirdPartyServices));