From: Stas Vilchik Date: Tue, 6 Sep 2016 15:23:12 +0000 (+0200) Subject: SONAR-7978 Add test email configuration form to the settings page (#1216) X-Git-Tag: 6.1-RC1~195 X-Git-Url: https://source.dussan.org/?a=commitdiff_plain;h=bae4f619db5198f7cb67a7848fdff756d83b5744;p=sonarqube.git SONAR-7978 Add test email configuration form to the settings page (#1216) --- diff --git a/server/sonar-web/src/main/js/api/settings.js b/server/sonar-web/src/main/js/api/settings.js index 6792f6b081c..266463e76da 100644 --- a/server/sonar-web/src/main/js/api/settings.js +++ b/server/sonar-web/src/main/js/api/settings.js @@ -67,3 +67,9 @@ export function resetSettingValue (key, componentKey) { } return post(url, data); } + +export function sendTestEmail (to, subject, message) { + const url = '/api/emails/send'; + const data = { to, subject, message }; + return post(url, data); +} diff --git a/server/sonar-web/src/main/js/apps/settings/components/EmailForm.js b/server/sonar-web/src/main/js/apps/settings/components/EmailForm.js new file mode 100644 index 00000000000..8f7a5cd88a4 --- /dev/null +++ b/server/sonar-web/src/main/js/apps/settings/components/EmailForm.js @@ -0,0 +1,112 @@ +/* + * SonarQube + * Copyright (C) 2009-2016 SonarSource SA + * mailto:contact AT sonarsource DOT com + * + * This program is free software; you can redistribute it and/or + * modify it under the terms of the GNU Lesser General Public + * License as published by the Free Software Foundation; either + * version 3 of the License, or (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + * Lesser General Public License for more details. + * + * You should have received a copy of the GNU Lesser General Public License + * along with this program; if not, write to the Free Software Foundation, + * Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. + */ +import React from 'react'; +import { translate, translateWithParameters } from '../../../helpers/l10n'; +import { sendTestEmail } from '../../../api/settings'; +import { parseError } from '../../code/utils'; + +export default class EmailForm extends React.Component { + constructor (props) { + super(props); + this.state = { + recipient: window.SS.userEmail, + subject: translate('email_configuration.test.subject'), + message: translate('email_configuration.test.message_text'), + loading: false, + success: false, + error: null + }; + } + + handleFormSubmit (e) { + e.preventDefault(); + this.setState({ success: false, error: null, loading: true }); + const { recipient, subject, message } = this.state; + sendTestEmail(recipient, subject, message).then( + () => this.setState({ success: true, loading: false }), + error => parseError(error).then(message => this.setState({ error: message, loading: false })) + ); + } + + render () { + return ( +
+

{translate('email_configuration.test.title')}

+ +
this.handleFormSubmit(e)}> + {this.state.success && ( +
+ {translateWithParameters('email_configuration.test.email_was_sent_to_x', this.state.recipient)} +
+ )} + + {this.state.error != null && ( +
+ {this.state.error} +
+ )} + +
+ + this.setState({ recipient: e.target.value })}/> +
+
+ + this.setState({ subject: e.target.value })}/> +
+
+ +