Allows space in custom fields name (issue #598) (#681)

* replace spaces for underscores in edit custom fields

* Create function getCustomFieldParamName
This commit is contained in:
LautaroCesso 2019-12-20 16:49:43 -03:00 committed by GitHub
parent 682eedba0a
commit 843bd13281
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
4 changed files with 27 additions and 16 deletions

View File

@ -4,6 +4,7 @@ import _ from 'lodash';
import API from 'lib-app/api-call';
import i18n from 'lib-app/i18n';
import { getCustomFieldParamName } from 'lib-core/APIUtils';
import SessionActions from 'actions/session-actions';
import AreYouSure from 'app-components/are-you-sure';
@ -42,15 +43,6 @@ class DashboardEditProfilePage extends React.Component {
return (
<div className="edit-profile-page">
<Header title={i18n('EDIT_PROFILE')} description={i18n('EDIT_PROFILE_VIEW_DESCRIPTION')} />
<div className="edit-profile-page__title">{i18n('ADDITIONAL_FIELDS')}</div>
<Form loading={this.state.loadingCustomFields} values={this.state.customFieldsFrom} onChange={form => this.setState({customFieldsFrom: form})} onSubmit={this.onCustomFieldsSubmit.bind(this)}>
<div className="edit-profile-page__custom-fields">
{this.state.customFields.map(this.renderCustomField.bind(this))}
</div>
<div className="row">
<SubmitButton>{i18n('SAVE')}</SubmitButton>
</div>
</Form>
<div className="edit-profile-page__title">{i18n('EDIT_EMAIL')}</div>
<Form loading={this.state.loadingEmail} onSubmit={this.onSubmitEditEmail.bind(this)}>
<FormField name="newEmail" label={i18n('NEW_EMAIL')} field="input" validation="EMAIL" fieldProps={{size:'large'}} required/>
@ -65,6 +57,23 @@ class DashboardEditProfilePage extends React.Component {
<SubmitButton>{i18n('CHANGE_PASSWORD')}</SubmitButton>
{this.renderMessagePass()}
</Form>
{this.state.customFields.length ? this.renderCustomFields() : null}
</div>
);
}
renderCustomFields() {
return (
<div>
<div className="edit-profile-page__title">{i18n('ADDITIONAL_FIELDS')}</div>
<Form loading={this.state.loadingCustomFields} values={this.state.customFieldsFrom} onChange={form => this.setState({customFieldsFrom: form})} onSubmit={this.onCustomFieldsSubmit.bind(this)}>
<div className="edit-profile-page__custom-fields">
{this.state.customFields.map(this.renderCustomField.bind(this))}
</div>
<div className="row">
<SubmitButton>{i18n('SAVE')}</SubmitButton>
</div>
</Form>
</div>
);
}
@ -116,9 +125,9 @@ class DashboardEditProfilePage extends React.Component {
customFields.forEach(customField => {
if(customField.type === 'select') {
parsedFrom[`customfield_${customField.name}`] = customField.options[form[customField.name]].name;
parsedFrom[getCustomFieldParamName(customField.name)] = customField.options[form[customField.name]].name;
} else {
parsedFrom[`customfield_${customField.name}`] = form[customField.name];
parsedFrom[getCustomFieldParamName(customField.name)] = form[customField.name];
}
});

View File

@ -204,7 +204,7 @@ export default {
'IMAGE_HEADER_URL': 'Image header URL',
'IMAGE_HEADER_DESCRIPTION': 'Image that will be used as header of the email',
'EMAIL_SETTINGS': 'Email Settings',
'ADDITIONAL_FIELDS': 'Additonal Fields',
'ADDITIONAL_FIELDS': 'Edit additonal fields',
'NEW_CUSTOM_FIELD': 'New Custom field',
'TYPE': 'Type',
'SELECT_INPUT': 'Select input',
@ -326,7 +326,7 @@ export default {
'REGISTRATION_ENABLED': 'Registration has been enabled',
'ADD_API_KEY_DESCRIPTION': 'Insert the name and a registration api key will be generated.',
'SIGN_UP_VIEW_DESCRIPTION': 'Here you can create an account for our support center. It is required to send tickets and see documentation.',
'EDIT_PROFILE_VIEW_DESCRIPTION': 'Here you can edit your user by changing your email or your password.',
'EDIT_PROFILE_VIEW_DESCRIPTION': 'Here you can edit your user preferences.',
'ENABLE_USER_SYSTEM_DESCRIPTION': 'Enable/disable the use of an user system. If you disable it, all users will be deleted but the tickets will be kept. If you enable it, the users of existent tickets will be created.',
'CSV_DESCRIPTION': 'The CSV file must have 3 columns: email, password, name. There is no limit in row count. It will be created one user per row in the file.',
'SMTP_SERVER_DESCRIPTION': 'The configuration of the SMTP server allows the application to send mails. If you do not configure it, no emails will be sent by OpenSupports.',

View File

@ -44,4 +44,8 @@ const APIUtils = {
}
};
export const getCustomFieldParamName = function (customFieldName) {
return `customfield_${customFieldName}`.replace(/ /g,'_');
}
export default APIUtils;

View File

@ -152,9 +152,8 @@ abstract class Controller {
public static function getCustomFieldValues() {
$customFields = Customfield::getAll();
$customFieldValues = new DataStoreList();
foreach($customFields as $customField) {
$value = Controller::request('customfield_' . $customField->name);
$value = Controller::request('customfield_' . str_replace(' ', '_', $customField->name));
if($value !== null) {
$customFieldValue = new Customfieldvalue();
$customFieldValue->setProperties([
@ -183,7 +182,6 @@ abstract class Controller {
$customFieldValues->add($customFieldValue);
}
}
return $customFieldValues;
}
}