// 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 {browserHistory} from 'react-router';
import * as Utils from 'utils/utils.jsx';
import BackstageHeader from './backstage_header.jsx';
import {FormattedMessage} from 'react-intl';
import FormError from 'components/form_error.jsx';
import {Link} from 'react-router';
import SpinnerButton from 'components/spinner_button.jsx';
const REQUEST_POST = 'P';
const REQUEST_GET = 'G';
export default class AddCommand extends React.Component {
constructor(props) {
super(props);
this.handleSubmit = this.handleSubmit.bind(this);
this.updateDisplayName = this.updateDisplayName.bind(this);
this.updateDescription = this.updateDescription.bind(this);
this.updateTrigger = this.updateTrigger.bind(this);
this.updateUrl = this.updateUrl.bind(this);
this.updateMethod = this.updateMethod.bind(this);
this.updateUsername = this.updateUsername.bind(this);
this.updateIconUrl = this.updateIconUrl.bind(this);
this.updateAutocomplete = this.updateAutocomplete.bind(this);
this.updateAutocompleteHint = this.updateAutocompleteHint.bind(this);
this.updateAutocompleteDescription = this.updateAutocompleteDescription.bind(this);
this.state = {
displayName: '',
description: '',
trigger: '',
url: '',
method: REQUEST_POST,
username: '',
iconUrl: '',
autocomplete: false,
autocompleteHint: '',
autocompleteDescription: '',
saving: false,
serverError: '',
clientError: null
};
}
handleSubmit(e) {
e.preventDefault();
if (this.state.saving) {
return;
}
this.setState({
saving: true,
serverError: '',
clientError: ''
});
const command = {
display_name: this.state.displayName,
description: this.state.description,
trigger: this.state.trigger.trim(),
url: this.state.url.trim(),
method: this.state.method,
username: this.state.username,
icon_url: this.state.iconUrl,
auto_complete: this.state.autocomplete
};
if (command.auto_complete) {
command.auto_complete_desc = this.state.autocompleteDescription;
command.auto_complete_hint = this.state.autocompleteHint;
}
if (!command.trigger) {
this.setState({
saving: false,
clientError: (