// Copyright (c) 2016 Mattermost, Inc. All Rights Reserved.
// See License.txt for license information.
import React from 'react';
import * as AsyncClient from 'utils/async_client.jsx';
import IntegrationStore from 'stores/integration_store.jsx';
import {FormattedMessage} from 'react-intl';
import InstalledCommand from './installed_command.jsx';
import InstalledIntegrations from './installed_integrations.jsx';
export default class InstalledCommands extends React.Component {
constructor(props) {
super(props);
this.handleIntegrationChange = this.handleIntegrationChange.bind(this);
this.regenCommandToken = this.regenCommandToken.bind(this);
this.deleteCommand = this.deleteCommand.bind(this);
this.state = {
commands: []
};
}
componentWillMount() {
IntegrationStore.addChangeListener(this.handleIntegrationChange);
if (window.mm_config.EnableCommands === 'true') {
if (IntegrationStore.hasReceivedCommands()) {
this.setState({
commands: IntegrationStore.getCommands()
});
} else {
AsyncClient.listTeamCommands();
}
}
}
componentWillUnmount() {
IntegrationStore.removeChangeListener(this.handleIntegrationChange);
}
handleIntegrationChange() {
const commands = IntegrationStore.getCommands();
this.setState({
commands
});
}
regenCommandToken(command) {
AsyncClient.regenCommandToken(command.id);
}
deleteCommand(command) {
AsyncClient.deleteCommand(command.id);
}
render() {
const commands = this.state.commands.map((command) => {
return (
);
});
return (
}
addText={
}
addLink='/settings/integrations/commands/add'
>
{commands}
);
}
}