summaryrefslogtreecommitdiffstats
path: root/webapp/components/integrations/components/edit_incoming_webhook.jsx
diff options
context:
space:
mode:
Diffstat (limited to 'webapp/components/integrations/components/edit_incoming_webhook.jsx')
-rw-r--r--webapp/components/integrations/components/edit_incoming_webhook.jsx78
1 files changed, 78 insertions, 0 deletions
diff --git a/webapp/components/integrations/components/edit_incoming_webhook.jsx b/webapp/components/integrations/components/edit_incoming_webhook.jsx
new file mode 100644
index 000000000..9e032409a
--- /dev/null
+++ b/webapp/components/integrations/components/edit_incoming_webhook.jsx
@@ -0,0 +1,78 @@
+// Copyright (c) 2016 Mattermost, Inc. All Rights Reserved.
+// See License.txt for license information.
+
+import * as AsyncClient from 'utils/async_client.jsx';
+
+import {browserHistory} from 'react-router/es6';
+import IntegrationStore from 'stores/integration_store.jsx';
+import {loadIncomingHooks} from 'actions/integration_actions.jsx';
+
+import AbstractIncomingWebhook from './abstract_incoming_webhook.jsx';
+import TeamStore from 'stores/team_store.jsx';
+
+export default class EditIncomingWebhook extends AbstractIncomingWebhook {
+ constructor(props) {
+ super(props);
+
+ this.handleIntegrationChange = this.handleIntegrationChange.bind(this);
+ this.originalIncomingHook = null;
+ }
+
+ componentDidMount() {
+ IntegrationStore.addChangeListener(this.handleIntegrationChange);
+
+ if (window.mm_config.EnableIncomingWebhooks === 'true') {
+ loadIncomingHooks();
+ }
+ }
+
+ componentWillUnmount() {
+ IntegrationStore.removeChangeListener(this.handleIntegrationChange);
+ }
+
+ handleIntegrationChange() {
+ const teamId = TeamStore.getCurrentId();
+
+ this.setState({
+ hooks: IntegrationStore.getIncomingWebhooks(teamId),
+ loading: !IntegrationStore.hasReceivedIncomingWebhooks(teamId)
+ });
+
+ if (!this.state.loading) {
+ this.originalIncomingHook = this.state.hooks.filter((hook) => hook.id === this.props.location.query.id)[0];
+
+ this.setState({
+ displayName: this.originalIncomingHook.display_name,
+ description: this.originalIncomingHook.description,
+ channelId: this.originalIncomingHook.channel_id
+ });
+ }
+ }
+
+ performAction(hook) {
+ if (this.originalIncomingHook.id) {
+ hook.id = this.originalIncomingHook.id;
+ }
+
+ AsyncClient.updateIncomingHook(
+ hook,
+ () => {
+ browserHistory.push(`/${this.props.team.name}/integrations/incoming_webhooks`);
+ },
+ (err) => {
+ this.setState({
+ saving: false,
+ serverError: err.message
+ });
+ }
+ );
+ }
+
+ header() {
+ return {id: 'integrations.edit', defaultMessage: 'Edit'};
+ }
+
+ footer() {
+ return {id: 'update_incoming_webhook.update', defaultMessage: 'Update'};
+ }
+}