Commit d177e882 authored by Nicolas Frandeboeuf's avatar Nicolas Frandeboeuf
Browse files

Make settings/import stateless

parent 0b48afab
Pipeline #14741 passed with stage
in 2 minutes and 41 seconds
......@@ -5,19 +5,13 @@ import { connect } from 'react-redux';
import { actions } from '../../../store';
import { translate as $t } from '../../../helpers';
class ImportModule extends React.Component {
const ImportModule = props => {
constructor(props) {
super(props);
this.handleImport = this.handleImport.bind(this);
this.handleChange = this.handleChange.bind(this);
let fileNameInput = null;
let fileInput = null;
this.fileNameInput = null;
this.fileInput = null;
}
handleImport(e) {
if (!this.fileInput.files || !this.fileInput.files.length) {
const handleImport = e => {
if (!fileInput.files || !fileInput.files.length) {
alert($t('client.settings.no_file_selected'));
e.preventDefault();
return;
......@@ -26,7 +20,7 @@ class ImportModule extends React.Component {
let fileReader = new FileReader();
fileReader.onload = fileEvent => {
try {
this.props.importInstance(JSON.parse(fileEvent.target.result));
props.importInstance(JSON.parse(fileEvent.target.result));
} catch (err) {
if (err instanceof SyntaxError) {
alert($t('client.settings.import_invalid_json'));
......@@ -35,57 +29,55 @@ class ImportModule extends React.Component {
}
}
};
fileReader.readAsText(this.fileInput.files[0]);
fileReader.readAsText(fileInput.files[0]);
this.fileInput.value = '';
this.fileNameInput.value = '';
fileInput.value = '';
fileNameInput.value = '';
e.preventDefault();
}
};
handleChange(e) {
this.fileNameInput.value = e.target.value;
}
const handleChange = e => {
fileNameInput.value = e.target.value;
};
render() {
let fileNameInputCb = input => {
this.fileNameInput = input;
};
let fileInputCb = input => {
this.fileInput = input;
};
let fileNameInputCb = input => {
fileNameInput = input;
};
let fileInputCb = input => {
fileInput = input;
};
return (
<div className="input-group import-file">
<input
type="text"
className="form-control"
readOnly={ true }
ref={ fileNameInputCb }
/>
return (
<div className="input-group import-file">
<input
type="text"
className="form-control"
readOnly={ true }
ref={ fileNameInputCb }
/>
<span className="input-group-btn">
<div className="btn btn-primary btn-file">
{ $t('client.settings.browse') }
<input
type="file"
name="importFile"
ref={ fileInputCb }
onChange={ this.handleChange }
/>
</div>
</span>
<span className="input-group-btn">
<div className="btn btn-primary btn-file">
{ $t('client.settings.browse') }
<input
type="file"
name="importFile"
ref={ fileInputCb }
onChange={ handleChange }
/>
</div>
</span>
<span className="input-group-btn">
<button
className="btn btn-primary"
onClick={ this.handleImport }>
{ $t('client.settings.go_import_instance') }
</button>
</span>
</div>
);
}
}
<span className="input-group-btn">
<button
className="btn btn-primary"
onClick={ handleImport }>
{ $t('client.settings.go_import_instance') }
</button>
</span>
</div>
);
};
const Export = connect(() => {
return {};
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment