// Copyright (c) 2016 Mattermost, Inc. All Rights Reserved. // See License.txt for license information. import React from 'react'; import Client from 'utils/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) => { this.setState({ testing: false, fail: err.message + ' - ' + err.detailed_error }); } ); } render() { let testMessage = null; if (this.state.success) { testMessage = (
); } else if (this.state.fail) { testMessage = (
); } let contents = null; if (this.state.testing) { contents = ( {Utils.localizeMessage('admin.email.testing', 'Testing...')} ); } else { contents = ( ); } return (
{testMessage}
); } }