// Copyright (c) 2016-present Mattermost, Inc. All Rights Reserved. // See License.txt for license information. import React from 'react'; import * as Utils from 'utils/utils.jsx'; import {FormattedMessage} from 'react-intl'; import {testEmail} from 'actions/admin_actions.jsx'; export default class EmailConnectionTestButton extends React.Component { static get propTypes() { return { config: React.PropTypes.object.isRequired, getConfigFromState: React.PropTypes.func.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 }); const config = JSON.parse(JSON.stringify(this.props.config)); this.props.getConfigFromState(config); testEmail( 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 = (
); } else if (this.state.fail) { testMessage = (
); } let contents = null; if (this.state.testing) { contents = ( {Utils.localizeMessage('admin.email.testing', 'Testing...')} ); } else { contents = ( ); } return (
{testMessage}
); } }