diff --git a/webapp/components/backstage/add_incoming_webhook.jsx b/webapp/components/backstage/add_incoming_webhook.jsx
index 962792ed04..cb7828698f 100644
--- a/webapp/components/backstage/add_incoming_webhook.jsx
+++ b/webapp/components/backstage/add_incoming_webhook.jsx
@@ -5,9 +5,9 @@ import React from 'react';
import * as AsyncClient from 'utils/async_client.jsx';
import {browserHistory} from 'react-router';
-import ChannelStore from 'stores/channel_store.jsx';
import TeamStore from 'stores/team_store.jsx';
+import ChannelSelect from 'components/channel_select.jsx';
import {FormattedMessage} from 'react-intl';
import FormError from 'components/form_error.jsx';
import {Link} from 'react-router';
@@ -22,13 +22,13 @@ export default class AddIncomingWebhook extends React.Component {
this.updateName = this.updateName.bind(this);
this.updateDescription = this.updateDescription.bind(this);
- this.updateChannelName = this.updateChannelName.bind(this);
+ this.updateChannelId = this.updateChannelId.bind(this);
this.state = {
team: TeamStore.getCurrent(),
name: '',
description: '',
- channelName: '',
+ channelId: '',
saving: false,
serverError: '',
clientError: null
@@ -62,15 +62,13 @@ export default class AddIncomingWebhook extends React.Component {
clientError: ''
});
- const channel = ChannelStore.getByName(this.state.channelName);
-
- if (!channel) {
+ if (!this.state.channelId) {
this.setState({
saving: false,
clientError: (
)
});
@@ -79,7 +77,7 @@ export default class AddIncomingWebhook extends React.Component {
}
const hook = {
- channel_id: channel.id
+ channel_id: this.state.channelId
};
AsyncClient.addIncomingHook(
@@ -107,9 +105,9 @@ export default class AddIncomingWebhook extends React.Component {
});
}
- updateChannelName(e) {
+ updateChannelId(e) {
this.setState({
- channelName: e.target.value
+ channelId: e.target.value
});
}
@@ -170,18 +168,17 @@ export default class AddIncomingWebhook extends React.Component {
diff --git a/webapp/components/backstage/add_outgoing_webhook.jsx b/webapp/components/backstage/add_outgoing_webhook.jsx
index 6e2f749f87..808a7185da 100644
--- a/webapp/components/backstage/add_outgoing_webhook.jsx
+++ b/webapp/components/backstage/add_outgoing_webhook.jsx
@@ -5,9 +5,9 @@ import React from 'react';
import * as AsyncClient from 'utils/async_client.jsx';
import {browserHistory} from 'react-router';
-import ChannelStore from 'stores/channel_store.jsx';
import TeamStore from 'stores/team_store.jsx';
+import ChannelSelect from 'components/channel_select.jsx';
import {FormattedMessage} from 'react-intl';
import FormError from 'components/form_error.jsx';
import {Link} from 'react-router';
@@ -22,7 +22,7 @@ export default class AddOutgoingWebhook extends React.Component {
this.updateName = this.updateName.bind(this);
this.updateDescription = this.updateDescription.bind(this);
- this.updateChannelName = this.updateChannelName.bind(this);
+ this.updateChannelId = this.updateChannelId.bind(this);
this.updateTriggerWords = this.updateTriggerWords.bind(this);
this.updateCallbackUrls = this.updateCallbackUrls.bind(this);
@@ -30,7 +30,7 @@ export default class AddOutgoingWebhook extends React.Component {
team: TeamStore.getCurrent(),
name: '',
description: '',
- channelName: '',
+ channelId: '',
triggerWords: '',
callbackUrls: '',
saving: false,
@@ -66,32 +66,13 @@ export default class AddOutgoingWebhook extends React.Component {
clientError: ''
});
- let channelId = '';
- if (this.state.channelName) {
- const channel = ChannelStore.getByName(this.state.channelName);
-
- if (!channel) {
- this.setState({
- saving: false,
- clientError: (
-
- )
- });
-
- return;
- }
-
- channelId = channel.id;
- } else if (!this.state.triggerWords) {
+ if (!this.state.channelId || !this.state.triggerWords) {
this.setState({
saving: false,
clientError: (
)
});
@@ -114,7 +95,7 @@ export default class AddOutgoingWebhook extends React.Component {
}
const hook = {
- channel_id: channelId,
+ channel_id: this.state.channelId,
trigger_words: this.state.triggerWords.split('\n').map((word) => word.trim()),
callback_urls: this.state.callbackUrls.split('\n').map((url) => url.trim())
};
@@ -144,9 +125,9 @@ export default class AddOutgoingWebhook extends React.Component {
});
}
- updateChannelName(e) {
+ updateChannelId(e) {
this.setState({
- channelName: e.target.value
+ channelId: e.target.value
});
}
@@ -219,18 +200,17 @@ export default class AddOutgoingWebhook extends React.Component {
-
diff --git a/webapp/components/channel_select.jsx b/webapp/components/channel_select.jsx
new file mode 100644
index 0000000000..b110b32da2
--- /dev/null
+++ b/webapp/components/channel_select.jsx
@@ -0,0 +1,79 @@
+// Copyright (c) 2015 Mattermost, Inc. All Rights Reserved.
+// See License.txt for license information.
+
+import React from 'react';
+
+import Constants from 'utils/constants.jsx';
+import ChannelStore from 'stores/channel_store.jsx';
+import * as Utils from 'utils/utils.jsx';
+
+export default class ChannelSelect extends React.Component {
+ static get propTypes() {
+ return {
+ onChange: React.PropTypes.func,
+ value: React.PropTypes.string
+ };
+ }
+
+ constructor(props) {
+ super(props);
+
+ this.handleChannelChange = this.handleChannelChange.bind(this);
+
+ this.state = {
+ channels: []
+ };
+ }
+
+ componentWillMount() {
+ this.setState({
+ channels: ChannelStore.getAll()
+ });
+
+ ChannelStore.addChangeListener(this.handleChannelChange);
+ }
+
+ componentWillUnmount() {
+ ChannelStore.removeChangeListener(this.handleChannelChange);
+ }
+
+ handleChannelChange() {
+ this.setState({
+ channels: ChannelStore.getAll()
+ });
+ }
+
+ render() {
+ const options = [
+
+ ];
+
+ this.state.channels.forEach((channel) => {
+ if (channel.type !== Constants.DM_CHANNEL) {
+ options.push(
+
+ );
+ }
+ });
+
+ return (
+
+ );
+ }
+}
diff --git a/webapp/utils/constants.jsx b/webapp/utils/constants.jsx
index 1f316369a2..126324de8d 100644
--- a/webapp/utils/constants.jsx
+++ b/webapp/utils/constants.jsx
@@ -69,7 +69,9 @@ export default {
RECEIVED_PREFERENCES: null,
RECEIVED_FILE_INFO: null,
RECEIVED_INCOMING_WEBHOOKS: null,
+ RECEIVED_INCOMING_WEBHOOK: null,
RECEIVED_OUTGOING_WEBHOOKS: null,
+ RECEIVED_OUTGOING_WEBHOOK: null,
RECEIVED_MSG: null,