Max Red - Add functionality to "Discard changes" button, modified fixtures [skip ci]

This commit is contained in:
ivan 2017-01-04 19:28:53 -03:00
parent 3af899efcd
commit 68fe99f395
4 changed files with 52 additions and 23 deletions

View File

@ -10,14 +10,15 @@ import Button from 'core-components/button';
import Message from 'core-components/message'; import Message from 'core-components/message';
import API from 'lib-app/api-call'; import API from 'lib-app/api-call';
import ToggleButton from 'app-components/toggle-button';
import i18n from 'lib-app/i18n'; 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 { class AdminPanelSystemPreferences extends React.Component {
state = { state = {
loading: true, loading: true,
message: false, message: null,
values: { values: {
'maintenance': false 'maintenance': false
} }
@ -31,7 +32,7 @@ class AdminPanelSystemPreferences extends React.Component {
return ( return (
<div className="admin-panel-system-preferences"> <div className="admin-panel-system-preferences">
<Header title={i18n('SYSTEM_PREFERENCES')} description="Here you can adjust your system preferences :)"/> <Header title={i18n('SYSTEM_PREFERENCES')} description="Here you can adjust your system preferences :)"/>
<Form values={this.state.values} onChange={values => this.setState({values})} onSubmit={this.onSubmit.bind(this)} loading={this.state.loading}> <Form values={this.state.values} onChange={values => this.setState({values, message: null})} onSubmit={this.onSubmit.bind(this)} loading={this.state.loading}>
<div className="row"> <div className="row">
<div className="col-md-12"> <div className="col-md-12">
<div className="admin-panel-system-preferences__maintenance"> <div className="admin-panel-system-preferences__maintenance">
@ -98,16 +99,13 @@ class AdminPanelSystemPreferences extends React.Component {
<FormField label={i18n('RECAPTCHA_PRIVATE_KEY')} fieldProps={{size: 'large'}} name="reCaptchaPrivate"/> <FormField label={i18n('RECAPTCHA_PRIVATE_KEY')} fieldProps={{size: 'large'}} name="reCaptchaPrivate"/>
<div className="admin-panel-system-preferences__file-attachments"> <div className="admin-panel-system-preferences__file-attachments">
<span>{i18n('ALLOW_FILE_ATTACHMENTS')}</span> <span>{i18n('ALLOW_FILE_ATTACHMENTS')}</span>
<FormField className="admin-panel-system-preferences__file-attachments-field" name="file-attachments" decorator={ToggleButton}/> <FormField className="admin-panel-system-preferences__file-attachments-field" name="allow-attachments" decorator={ToggleButton}/>
</div> </div>
<div className="admin-panel-system-preferences__max-size"> <div className="admin-panel-system-preferences__max-size">
<span>{i18n('MAX_SIZE_KB')}</span> <span>{i18n('MAX_SIZE_KB')}</span>
<FormField className="admin-panel-system-preferences__max-size-field" fieldProps={{size: 'small'}} name="max-size"/> <FormField className="admin-panel-system-preferences__max-size-field" fieldProps={{size: 'small'}} name="max-size"/>
</div> </div>
<FormField name="language" label={i18n('DEFAULT_LANGUAGE')} field="select" fieldProps={{ <FormField className="admin-panel-system-preferences__default-language-field" name="language" label={i18n('DEFAULT_LANGUAGE')} decorator={LanguageSelector} />
items: [{content: 'es'}, {content: 'en'}],
size: 'large'
}} />
</div> </div>
</div> </div>
<div className="row"> <div className="row">
@ -120,14 +118,26 @@ class AdminPanelSystemPreferences extends React.Component {
<SubmitButton type="secondary">{i18n('UPDATE_SETTINGS')}</SubmitButton> <SubmitButton type="secondary">{i18n('UPDATE_SETTINGS')}</SubmitButton>
</div> </div>
<div className="col-md-4"> <div className="col-md-4">
<Button onClick={event => event.preventDefault()}>{i18n('DISCARD_CHANGES')}</Button> <Button onClick={this.onDiscardChangesSubmit.bind(this)}>{i18n('DISCARD_CHANGES')}</Button>
</div> </div>
</div> </div>
</Form> </Form>
{this.renderMessage()}
</div> </div>
); );
} }
renderMessage() {
switch (this.state.message) {
case 'success':
return <Message className="admin-panel-system-preferences__message" type="success">{i18n('SETTINGS_UPDATED')}</Message>;
case 'fail':
return <Message className="admin-panel-system-preferences__message" type="error">{i18n('ERROR_UPDATING_SETTINGS')}</Message>;
default:
return null;
}
}
onSubmit(form) { onSubmit(form) {
let fullList = Object.keys(languageList); let fullList = Object.keys(languageList);
this.setState({loading: true}); this.setState({loading: true});
@ -135,9 +145,9 @@ class AdminPanelSystemPreferences extends React.Component {
API.call({ API.call({
path: '/system/edit-settings', path: '/system/edit-settings',
data: { data: {
'language': fullList[form.language], 'language': form.language,
'reCaptchaKey': form.reCaptchaKey, 'recaptcha-public': form.reCaptchaKey,
'reCaptchaPrivate': form.reCaptchaPrivate, 'recaptcha-private': form.reCaptchaPrivate,
'url': form['url'], 'url': form['url'],
'title': form['title'], 'title': form['title'],
'layout': form['layout'] == 1 ? 'Full width' : 'Boxed', 'layout': form['layout'] == 1 ? 'Full width' : 'Boxed',
@ -148,17 +158,20 @@ class AdminPanelSystemPreferences extends React.Component {
'smtp-user': form['smtp-user'], 'smtp-user': form['smtp-user'],
'smtp-pass': form['smtp-password'], 'smtp-pass': form['smtp-password'],
'maintenance-mode': form['maintenance-mode'], 'maintenance-mode': form['maintenance-mode'],
'file-attachments': form['file-attachments'], 'allow-attachments': form['allow-attachments'],
'max-size': form['max-size'], 'max-size': form['max-size'],
'allowedLanguages': form.allowedLanguages.map(index => fullList[index]), 'allowedLanguages': JSON.stringify(form.allowedLanguages.map(index => fullList[index])),
'supportedLanguages': form.supportedLanguages.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() { onSubmitSuccess() {
this.recoverSettings(); this.recoverSettings();
this.setState({
message: 'success',
loading: false
});
} }
getLanguageList() { getLanguageList() {
@ -180,7 +193,7 @@ class AdminPanelSystemPreferences extends React.Component {
this.setState({ this.setState({
loading: false, loading: false,
values: { values: {
'language': _.indexOf(fullList, result.data.language), 'language': result.data.language,
'reCaptchaKey': result.data.reCaptchaKey, 'reCaptchaKey': result.data.reCaptchaKey,
'reCaptchaPrivate': result.data.reCaptchaPrivate, 'reCaptchaPrivate': result.data.reCaptchaPrivate,
'url': result.data['url'], 'url': result.data['url'],
@ -193,7 +206,7 @@ class AdminPanelSystemPreferences extends React.Component {
'smtp-user': result.data['smtp-user'], 'smtp-user': result.data['smtp-user'],
'smtp-pass': '', 'smtp-pass': '',
'maintenance-mode': result.data['maintenance-mode'], 'maintenance-mode': result.data['maintenance-mode'],
'file-attachments': result.data['file-attachments'], 'allow-attachments': result.data['allow-attachments'],
'max-size': result.data['max-size'], 'max-size': result.data['max-size'],
'allowedLanguages': result.data.allowedLanguages.map(lang => (_.indexOf(fullList, lang))), 'allowedLanguages': result.data.allowedLanguages.map(lang => (_.indexOf(fullList, lang))),
'supportedLanguages': result.data.supportedLanguages.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) { onRecoverSettingsFail(result) {
this.setState({
message: 'error'
});
}
onDiscardChangesSubmit(event) {
event.preventDefault();
this.setState({loading: true});
this.recoverSettings();
} }
} }

View File

@ -36,13 +36,19 @@
&-allowed { &-allowed {
text-align: left; text-align: left;
display: inline-block; display: inline-block;
//background-color: red;
} }
&-supported { &-supported {
text-align: left; text-align: left;
display: inline-block; display: inline-block;
//background-color: $light-grey;
} }
} }
&__default-language-field {
text-align: left;
}
&__message {
margin-top: 20px;
}
} }

View File

@ -19,7 +19,7 @@ module.exports = [
'smtp-port': '7070', 'smtp-port': '7070',
'smtp-user': 'Wesa', 'smtp-user': 'Wesa',
'maintenance-mode': false, 'maintenance-mode': false,
'fileAttachments': false, 'allow-attachments': true,
'max-size': 500, 'max-size': 500,
'departments': [ 'departments': [
{id: 1, name: 'Sales Support', owners: 2}, {id: 1, name: 'Sales Support', owners: 2},

View File

@ -135,6 +135,7 @@ export default {
'DEFAULT_LANGUAGE': 'Default Language', 'DEFAULT_LANGUAGE': 'Default Language',
'SUPPORTED_LANGUAGES': 'Supported Languages', 'SUPPORTED_LANGUAGES': 'Supported Languages',
'ALLOWED_LANGUAGES': 'Allowed Languages', 'ALLOWED_LANGUAGES': 'Allowed Languages',
'SETTINGS_UPDATED': 'Settings have been updated',
'ON': 'On', 'ON': 'On',
'OFF': 'Off', 'OFF': 'Off',
'BOXED': 'Boxed', '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_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_BANNING_EMAIL': 'An error occurred while trying to ban the email.',
'ERROR_RETRIEVING_ARTICLES': 'An error occurred while trying to retrieve articles.', 'ERROR_RETRIEVING_ARTICLES': 'An error occurred while trying to retrieve articles.',
'ERROR_UPDATING_SETTINGS': 'An error ocurred while trying to update settings.',
//MESSAGES //MESSAGES
'SIGNUP_SUCCESS': 'You have registered successfully in our support system.', 'SIGNUP_SUCCESS': 'You have registered successfully in our support system.',