2017-08-09 13:44:24 +03:00
|
|
|
/*
|
2017-08-17 13:22:42 +03:00
|
|
|
Copyright 2017 New Vector Ltd
|
2017-08-09 13:44:24 +03:00
|
|
|
|
|
|
|
Licensed under the Apache License, Version 2.0 (the "License");
|
|
|
|
you may not use this file except in compliance with the License.
|
|
|
|
You may obtain a copy of the License at
|
|
|
|
|
|
|
|
http://www.apache.org/licenses/LICENSE-2.0
|
|
|
|
|
|
|
|
Unless required by applicable law or agreed to in writing, software
|
|
|
|
distributed under the License is distributed on an "AS IS" BASIS,
|
|
|
|
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
|
|
|
See the License for the specific language governing permissions and
|
|
|
|
limitations under the License.
|
|
|
|
*/
|
|
|
|
|
|
|
|
import React from 'react';
|
|
|
|
import PropTypes from 'prop-types';
|
|
|
|
import sdk from '../../../index';
|
|
|
|
import SdkConfig from '../../../SdkConfig';
|
|
|
|
import ScalarAuthClient from '../../../ScalarAuthClient';
|
|
|
|
import ScalarMessaging from '../../../ScalarMessaging';
|
|
|
|
import Modal from "../../../Modal";
|
|
|
|
import { _t } from '../../../languageHandler';
|
|
|
|
import AccessibleButton from './AccessibleButton';
|
|
|
|
import TintableSvg from './TintableSvg';
|
|
|
|
|
|
|
|
export default class ManageIntegsButton extends React.Component {
|
|
|
|
constructor(props) {
|
|
|
|
super(props);
|
|
|
|
|
|
|
|
this.state = {
|
2017-08-17 13:24:25 +03:00
|
|
|
scalarError: null,
|
2017-08-09 13:44:24 +03:00
|
|
|
showIntegrationsError: false,
|
|
|
|
};
|
|
|
|
|
|
|
|
this.onManageIntegrations = this.onManageIntegrations.bind(this);
|
|
|
|
this.onShowIntegrationsError = this.onShowIntegrationsError.bind(this);
|
|
|
|
}
|
|
|
|
|
|
|
|
componentWillMount() {
|
|
|
|
ScalarMessaging.startListening();
|
|
|
|
this.scalarClient = null;
|
|
|
|
|
|
|
|
if (SdkConfig.get().integrations_ui_url && SdkConfig.get().integrations_rest_url) {
|
|
|
|
this.scalarClient = new ScalarAuthClient();
|
|
|
|
this.scalarClient.connect().done(() => {
|
|
|
|
this.forceUpdate();
|
|
|
|
}, (err) => {
|
2017-08-17 13:24:25 +03:00
|
|
|
this.setState({ scalarError: err});
|
2017-08-09 13:44:24 +03:00
|
|
|
});
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
componentWillUnmount() {
|
|
|
|
ScalarMessaging.stopListening();
|
|
|
|
}
|
|
|
|
|
|
|
|
onManageIntegrations(ev) {
|
|
|
|
ev.preventDefault();
|
|
|
|
const IntegrationsManager = sdk.getComponent("views.settings.IntegrationsManager");
|
|
|
|
Modal.createDialog(IntegrationsManager, {
|
|
|
|
src: (this.scalarClient !== null && this.scalarClient.hasCredentials()) ?
|
|
|
|
this.scalarClient.getScalarInterfaceUrlForRoom(this.props.room.roomId) :
|
|
|
|
null,
|
|
|
|
onFinished: ()=>{
|
|
|
|
if (this.props.onCancelClick) {
|
|
|
|
this.props.onCancelClick(ev);
|
|
|
|
}
|
|
|
|
},
|
|
|
|
}, "mx_IntegrationsManager");
|
|
|
|
}
|
|
|
|
|
|
|
|
onShowIntegrationsError(ev) {
|
|
|
|
ev.preventDefault();
|
|
|
|
this.setState({
|
|
|
|
showIntegrationsError: !this.state.showIntegrationsError,
|
|
|
|
});
|
|
|
|
}
|
|
|
|
|
|
|
|
render() {
|
|
|
|
let integrationsButton;
|
|
|
|
let integrationsError;
|
|
|
|
if (this.scalarClient !== null) {
|
2017-08-17 13:24:25 +03:00
|
|
|
if (this.state.showIntegrationsError && this.state.scalarError) {
|
|
|
|
console.error(this.state.scalarError);
|
2017-08-09 13:44:24 +03:00
|
|
|
integrationsError = (
|
|
|
|
<span className="mx_RoomSettings_integrationsButton_errorPopup">
|
|
|
|
{ _t('Could not connect to the integration server') }
|
|
|
|
</span>
|
|
|
|
);
|
|
|
|
}
|
|
|
|
|
|
|
|
if (this.scalarClient.hasCredentials()) {
|
|
|
|
integrationsButton = (
|
|
|
|
<AccessibleButton className="mx_RoomHeader_button" onClick={this.onManageIntegrations} title={ _t('Manage Integrations') }>
|
|
|
|
<TintableSvg src="img/icons-apps.svg" width="35" height="35"/>
|
|
|
|
</AccessibleButton>
|
|
|
|
);
|
2017-08-17 13:24:25 +03:00
|
|
|
} else if (this.state.scalarError) {
|
2017-08-09 13:44:24 +03:00
|
|
|
integrationsButton = (
|
|
|
|
<div className="mx_RoomSettings_integrationsButton_error" onClick={ this.onShowIntegrationsError }>
|
|
|
|
<img src="img/warning.svg" title={_t('Integrations Error')} width="17"/>
|
|
|
|
{ integrationsError }
|
|
|
|
</div>
|
|
|
|
);
|
|
|
|
} else {
|
|
|
|
integrationsButton = (
|
|
|
|
<AccessibleButton className="mx_RoomHeader_button" onClick={this.onManageIntegrations} title={ _t('Manage Integrations') }>
|
|
|
|
<TintableSvg src="img/icons-apps.svg" width="35" height="35"/>
|
|
|
|
</AccessibleButton>
|
|
|
|
);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
return integrationsButton;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
ManageIntegsButton.propTypes = {
|
|
|
|
room: PropTypes.object.isRequired,
|
|
|
|
onCancelClick: PropTypes.func,
|
|
|
|
};
|
|
|
|
|
|
|
|
ManageIntegsButton.defaultProps = {
|
|
|
|
onCancelClick: function() {},
|
|
|
|
};
|