Added button to reset encryption settings

This commit is contained in:
Ildar Kamalov 2019-02-01 16:52:59 +03:00 committed by Eugene Bujak
parent d42718465d
commit 1dd548c36c
4 changed files with 35 additions and 18 deletions

View File

@ -233,5 +233,6 @@
"topline_expiring_certificate": "Your SSL certificate is about to expire. Update <0>Encryption settings</0>.",
"form_error_port_range": "Enter port value in the range of 80-65535",
"form_error_equal": "Shouldn't be equal",
"form_error_password": "Password mismatched"
"form_error_password": "Password mismatched",
"reset_settings": "Reset settings",
}

View File

@ -4,16 +4,18 @@ import { Field, reduxForm } from 'redux-form';
import { Trans, withNamespaces } from 'react-i18next';
import flow from 'lodash/flow';
import { renderField, renderSelectField, required, toNumber, port } from '../../../helpers/form';
import { renderField, renderSelectField, toNumber, port } from '../../../helpers/form';
import i18n from '../../../i18n';
const validate = (values) => {
const errors = {};
if (values.port_dns_over_tls && values.port_https) {
if (values.port_dns_over_tls === values.port_https) {
errors.port_dns_over_tls = i18n.t('form_error_equal');
errors.port_https = i18n.t('form_error_equal');
}
}
return errors;
};
@ -22,6 +24,7 @@ const Form = (props) => {
const {
t,
handleSubmit,
reset,
invalid,
submitting,
processing,
@ -46,7 +49,6 @@ const Form = (props) => {
type="text"
className="form-control"
placeholder={t('encryption_server_enter')}
validate={[required]}
/>
<div className="form__desc">
<Trans>encryption_server_desc</Trans>
@ -80,7 +82,7 @@ const Form = (props) => {
type="number"
className="form-control"
placeholder={t('encryption_https')}
validate={[required, port]}
validate={[port]}
normalize={toNumber}
/>
<div className="form__desc">
@ -100,7 +102,7 @@ const Form = (props) => {
type="number"
className="form-control"
placeholder={t('encryption_dot')}
validate={[required, port]}
validate={[port]}
normalize={toNumber}
/>
<div className="form__desc">
@ -130,7 +132,6 @@ const Form = (props) => {
type="text"
className="form-control form-control--textarea"
placeholder={t('encryption_certificates_input')}
validate={[required]}
/>
<div className="form__status">
{statusCert &&
@ -170,7 +171,6 @@ const Form = (props) => {
type="text"
className="form-control form-control--textarea"
placeholder="Copy/paste your PEM-encoded private key for your cerficate here."
validate={[required]}
/>
<div className="form__status">
{statusKey &&
@ -188,19 +188,30 @@ const Form = (props) => {
</div>
</div>
<div className="btn-list">
<button
type="submit"
className="btn btn-success btn-standart"
disabled={invalid || submitting || processing}
>
{t('save_config')}
<Trans>save_config</Trans>
</button>
<button
type="submit"
className="btn btn-secondary btn-standart"
disabled={submitting || processing}
onClick={reset}
>
<Trans>reset_settings</Trans>
</button>
</div>
</form>
);
};
Form.propTypes = {
handleSubmit: PropTypes.func.isRequired,
reset: PropTypes.func.isRequired,
submitting: PropTypes.bool.isRequired,
invalid: PropTypes.bool.isRequired,
initialValues: PropTypes.object.isRequired,

View File

@ -63,7 +63,7 @@ export const isPositive = (value) => {
};
export const port = (value) => {
if (value < 80 || value > 65535) {
if (value && (value < 80 || value > 65535)) {
return <Trans>form_error_port_range</Trans>;
}
return false;

View File

@ -329,6 +329,11 @@ const encryption = handleActions({
processingConfig: false,
status_cert: '',
status_key: '',
certificate_chain: '',
private_key: '',
server_name: '',
port_https: '',
port_dns_over_tls: '',
});
export default combineReducers({