// Copyright (c) 2016 Mattermost, Inc. All Rights Reserved. // See License.txt for license information. import React from 'react'; import Client from 'client/web_client.jsx'; import * as Utils from 'utils/utils.jsx'; import {FormattedMessage} from 'react-intl'; export default class EmailConnectionTestButton extends React.Component { static get propTypes() { return { config: React.PropTypes.object.isRequired, disabled: React.PropTypes.bool.isRequired }; } constructor(props) { super(props); this.handleTestConnection = this.handleTestConnection.bind(this); this.state = { testing: false, success: false, fail: null }; } handleTestConnection(e) { e.preventDefault(); this.setState({ testing: true, success: false, fail: null }); Client.testEmail( this.props.config, () => { this.setState({ testing: false, success: true }); }, (err) => { let fail = err.message; if (err.detailed_error) { fail += ' - ' + err.detailed_error; } this.setState({ testing: false, fail }); } ); } render() { let testMessage = null; if (this.state.success) { testMessage = (