2017-02-17 00:46:39 +00:00
|
|
|
import React, { PureComponent } from 'react';
|
2016-01-11 20:04:57 +00:00
|
|
|
import { connect } from 'react-redux';
|
2017-05-26 06:20:00 +00:00
|
|
|
import { createStructuredSelector } from 'reselect';
|
2016-01-11 20:04:57 +00:00
|
|
|
import Navicon from '../components/Navicon';
|
|
|
|
import FileInput from '../components/FileInput';
|
2017-05-26 06:20:00 +00:00
|
|
|
import { getSettings, setCert, setKey, uploadCert } from '../state/settings';
|
2016-01-11 20:04:57 +00:00
|
|
|
|
2017-02-17 00:46:39 +00:00
|
|
|
class Settings extends PureComponent {
|
2016-01-11 20:04:57 +00:00
|
|
|
handleCertChange = (name, data) => this.props.dispatch(setCert(name, data));
|
|
|
|
handleKeyChange = (name, data) => this.props.dispatch(setKey(name, data));
|
|
|
|
handleCertUpload = () => this.props.dispatch(uploadCert());
|
|
|
|
|
|
|
|
render() {
|
|
|
|
const { settings } = this.props;
|
|
|
|
const status = settings.get('uploadingCert') ? 'Uploading...' : 'Upload';
|
|
|
|
const error = settings.get('certError');
|
|
|
|
|
|
|
|
return (
|
|
|
|
<div className="settings">
|
|
|
|
<Navicon />
|
|
|
|
<h1>Settings</h1>
|
|
|
|
<h2>Client Certificate</h2>
|
|
|
|
<div>
|
|
|
|
<p>Certificate</p>
|
|
|
|
<FileInput
|
|
|
|
name={settings.get('certFile') || 'Select Certificate'}
|
|
|
|
onChange={this.handleCertChange}
|
|
|
|
/>
|
|
|
|
</div>
|
|
|
|
<div>
|
|
|
|
<p>Private Key</p>
|
|
|
|
<FileInput
|
|
|
|
name={settings.get('keyFile') || 'Select Key'}
|
|
|
|
onChange={this.handleKeyChange}
|
|
|
|
/>
|
|
|
|
</div>
|
|
|
|
<button onClick={this.handleCertUpload}>{status}</button>
|
|
|
|
{ error ? <p className="error">{error}</p> : null }
|
|
|
|
</div>
|
|
|
|
);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2017-05-26 06:20:00 +00:00
|
|
|
const mapState = createStructuredSelector({
|
|
|
|
settings: getSettings
|
|
|
|
});
|
|
|
|
|
|
|
|
export default connect(mapState)(Settings);
|