From 68fe99f395ac25d820c7ed4e18ee4c228b058009 Mon Sep 17 00:00:00 2001 From: ivan Date: Wed, 4 Jan 2017 19:28:53 -0300 Subject: [PATCH] Max Red - Add functionality to "Discard changes" button, modified fixtures [skip ci] --- .../admin-panel-system-preferences.js | 61 +++++++++++++------ .../admin-panel-system-preferences.scss | 10 ++- client/src/data/fixtures/system-fixtures.js | 2 +- client/src/data/languages/en.js | 2 + 4 files changed, 52 insertions(+), 23 deletions(-) diff --git a/client/src/app/admin/panel/settings/admin-panel-system-preferences.js b/client/src/app/admin/panel/settings/admin-panel-system-preferences.js index e35e68d2..03ed99a7 100644 --- a/client/src/app/admin/panel/settings/admin-panel-system-preferences.js +++ b/client/src/app/admin/panel/settings/admin-panel-system-preferences.js @@ -10,14 +10,15 @@ import Button from 'core-components/button'; import Message from 'core-components/message'; import API from 'lib-app/api-call'; -import ToggleButton from 'app-components/toggle-button'; import i18n from 'lib-app/i18n'; +import LanguageSelector from 'app-components/language-selector'; +import ToggleButton from 'app-components/toggle-button'; class AdminPanelSystemPreferences extends React.Component { state = { loading: true, - message: false, + message: null, values: { 'maintenance': false } @@ -31,7 +32,7 @@ class AdminPanelSystemPreferences extends React.Component { return (
-
this.setState({values})} onSubmit={this.onSubmit.bind(this)} loading={this.state.loading}> + this.setState({values, message: null})} onSubmit={this.onSubmit.bind(this)} loading={this.state.loading}>
@@ -98,16 +99,13 @@ class AdminPanelSystemPreferences extends React.Component {
{i18n('ALLOW_FILE_ATTACHMENTS')} - +
{i18n('MAX_SIZE_KB')}
- +
@@ -120,14 +118,26 @@ class AdminPanelSystemPreferences extends React.Component { {i18n('UPDATE_SETTINGS')}
- +
+ {this.renderMessage()}
); } + renderMessage() { + switch (this.state.message) { + case 'success': + return {i18n('SETTINGS_UPDATED')}; + case 'fail': + return {i18n('ERROR_UPDATING_SETTINGS')}; + default: + return null; + } + } + onSubmit(form) { let fullList = Object.keys(languageList); this.setState({loading: true}); @@ -135,9 +145,9 @@ class AdminPanelSystemPreferences extends React.Component { API.call({ path: '/system/edit-settings', data: { - 'language': fullList[form.language], - 'reCaptchaKey': form.reCaptchaKey, - 'reCaptchaPrivate': form.reCaptchaPrivate, + 'language': form.language, + 'recaptcha-public': form.reCaptchaKey, + 'recaptcha-private': form.reCaptchaPrivate, 'url': form['url'], 'title': form['title'], 'layout': form['layout'] == 1 ? 'Full width' : 'Boxed', @@ -148,17 +158,20 @@ class AdminPanelSystemPreferences extends React.Component { 'smtp-user': form['smtp-user'], 'smtp-pass': form['smtp-password'], 'maintenance-mode': form['maintenance-mode'], - 'file-attachments': form['file-attachments'], + 'allow-attachments': form['allow-attachments'], 'max-size': form['max-size'], - 'allowedLanguages': form.allowedLanguages.map(index => fullList[index]), - 'supportedLanguages': form.supportedLanguages.map(index => fullList[index]) + 'allowedLanguages': JSON.stringify(form.allowedLanguages.map(index => fullList[index])), + 'supportedLanguages': JSON.stringify(form.supportedLanguages.map(index => fullList[index])) } - }).then(this.onSubmitSuccess.bind(this)); + }).then(this.onSubmitSuccess.bind(this)).catch(() => this.setState({loading: false, message: 'fail'})); } onSubmitSuccess() { this.recoverSettings(); - + this.setState({ + message: 'success', + loading: false + }); } getLanguageList() { @@ -180,7 +193,7 @@ class AdminPanelSystemPreferences extends React.Component { this.setState({ loading: false, values: { - 'language': _.indexOf(fullList, result.data.language), + 'language': result.data.language, 'reCaptchaKey': result.data.reCaptchaKey, 'reCaptchaPrivate': result.data.reCaptchaPrivate, 'url': result.data['url'], @@ -193,7 +206,7 @@ class AdminPanelSystemPreferences extends React.Component { 'smtp-user': result.data['smtp-user'], 'smtp-pass': '', 'maintenance-mode': result.data['maintenance-mode'], - 'file-attachments': result.data['file-attachments'], + 'allow-attachments': result.data['allow-attachments'], 'max-size': result.data['max-size'], 'allowedLanguages': result.data.allowedLanguages.map(lang => (_.indexOf(fullList, lang))), 'supportedLanguages': result.data.supportedLanguages.map(lang => (_.indexOf(fullList, lang))) @@ -202,7 +215,15 @@ class AdminPanelSystemPreferences extends React.Component { } onRecoverSettingsFail(result) { - + this.setState({ + message: 'error' + }); + } + + onDiscardChangesSubmit(event) { + event.preventDefault(); + this.setState({loading: true}); + this.recoverSettings(); } } diff --git a/client/src/app/admin/panel/settings/admin-panel-system-preferences.scss b/client/src/app/admin/panel/settings/admin-panel-system-preferences.scss index a468c5c3..9ee30de5 100644 --- a/client/src/app/admin/panel/settings/admin-panel-system-preferences.scss +++ b/client/src/app/admin/panel/settings/admin-panel-system-preferences.scss @@ -36,13 +36,19 @@ &-allowed { text-align: left; display: inline-block; - //background-color: red; } &-supported { text-align: left; display: inline-block; - //background-color: $light-grey; } } + + &__default-language-field { + text-align: left; + } + + &__message { + margin-top: 20px; + } } \ No newline at end of file diff --git a/client/src/data/fixtures/system-fixtures.js b/client/src/data/fixtures/system-fixtures.js index 6ab473be..64614032 100644 --- a/client/src/data/fixtures/system-fixtures.js +++ b/client/src/data/fixtures/system-fixtures.js @@ -19,7 +19,7 @@ module.exports = [ 'smtp-port': '7070', 'smtp-user': 'Wesa', 'maintenance-mode': false, - 'fileAttachments': false, + 'allow-attachments': true, 'max-size': 500, 'departments': [ {id: 1, name: 'Sales Support', owners: 2}, diff --git a/client/src/data/languages/en.js b/client/src/data/languages/en.js index 1db093b1..73f07de6 100644 --- a/client/src/data/languages/en.js +++ b/client/src/data/languages/en.js @@ -135,6 +135,7 @@ export default { 'DEFAULT_LANGUAGE': 'Default Language', 'SUPPORTED_LANGUAGES': 'Supported Languages', 'ALLOWED_LANGUAGES': 'Allowed Languages', + 'SETTINGS_UPDATED': 'Settings have been updated', 'ON': 'On', 'OFF': 'Off', 'BOXED': 'Boxed', @@ -189,6 +190,7 @@ export default { 'ERROR_RETRIEVING_BAN_LIST': 'An error occurred while trying to retrieve the list of banned emails.', 'ERROR_BANNING_EMAIL': 'An error occurred while trying to ban the email.', 'ERROR_RETRIEVING_ARTICLES': 'An error occurred while trying to retrieve articles.', + 'ERROR_UPDATING_SETTINGS': 'An error ocurred while trying to update settings.', //MESSAGES 'SIGNUP_SUCCESS': 'You have registered successfully in our support system.',