Files
AdGuardHome/client/src/components/Settings/Encryption/index.tsx
Ildar Kamalov fcdebfa4d4 Pull request: ADG-8737 fixed missing version in the footer, unnecessary validation call on the encryption page
Squashed commit of the following:

commit 1c4a15f2f32cd8bfbe0878f79feee4f581f0f5a8
Merge: 399d28e67 9d1c45fd9
Author: Ildar Kamalov <ik@adguard.com>
Date:   Tue Jul 2 13:08:21 2024 +0300

    Merge branch 'master' into ADG-8737

commit 399d28e67ff8f8886d5552fea96017e83a122306
Author: Ildar Kamalov <ik@adguard.com>
Date:   Mon Jul 1 19:37:05 2024 +0300

    fix install

commit 91d5dd23cea0dd5cde1bf5979bad181229d36f1a
Author: Ainar Garipov <A.Garipov@AdGuard.COM>
Date:   Mon Jul 1 17:40:22 2024 +0300

    home: imp logs

commit 06917df08b2154c726ca2de7ed7fda1de4269655
Author: Ildar Kamalov <ik@adguard.com>
Date:   Mon Jul 1 16:38:38 2024 +0300

    ADG-8737 add missing version, remove validation call
2024-07-02 13:30:55 +03:00

139 lines
4.1 KiB
TypeScript

import React, { Component } from 'react';
import { withTranslation } from 'react-i18next';
import debounce from 'lodash/debounce';
import { DEBOUNCE_TIMEOUT, ENCRYPTION_SOURCE } from '../../../helpers/constants';
import Form from './Form';
import Card from '../../ui/Card';
import PageTitle from '../../ui/PageTitle';
import Loading from '../../ui/Loading';
import { EncryptionData } from '../../../initialState';
interface EncryptionProps {
setTlsConfig: (...args: unknown[]) => unknown;
validateTlsConfig: (...args: unknown[]) => unknown;
encryption: EncryptionData;
t: (...args: unknown[]) => string;
}
class Encryption extends Component<EncryptionProps> {
componentDidMount() {
const { validateTlsConfig, encryption } = this.props;
if (encryption.enabled) {
validateTlsConfig(encryption);
}
}
handleFormSubmit = (values: any) => {
const submitValues = this.getSubmitValues(values);
this.props.setTlsConfig(submitValues);
};
handleFormChange = debounce((values) => {
const submitValues = this.getSubmitValues(values);
if (submitValues.enabled) {
this.props.validateTlsConfig(submitValues);
}
}, DEBOUNCE_TIMEOUT);
getInitialValues = (data: any) => {
const { certificate_chain, private_key, private_key_saved } = data;
const certificate_source = certificate_chain ? ENCRYPTION_SOURCE.CONTENT : ENCRYPTION_SOURCE.PATH;
const key_source = private_key || private_key_saved ? ENCRYPTION_SOURCE.CONTENT : ENCRYPTION_SOURCE.PATH;
return {
...data,
certificate_source,
key_source,
};
};
getSubmitValues = (values: any) => {
const { certificate_source, key_source, private_key_saved, ...config } = values;
if (certificate_source === ENCRYPTION_SOURCE.PATH) {
config.certificate_chain = '';
} else {
config.certificate_path = '';
}
if (key_source === ENCRYPTION_SOURCE.PATH) {
config.private_key = '';
} else {
config.private_key_path = '';
if (private_key_saved) {
config.private_key = '';
config.private_key_saved = private_key_saved;
}
}
return config;
};
render() {
const { encryption, t } = this.props;
const {
enabled,
server_name,
force_https,
port_https,
port_dns_over_tls,
port_dns_over_quic,
certificate_chain,
private_key,
certificate_path,
private_key_path,
private_key_saved,
serve_plain_dns,
} = encryption;
const initialValues = this.getInitialValues({
enabled,
server_name,
force_https,
port_https,
port_dns_over_tls,
port_dns_over_quic,
certificate_chain,
private_key,
certificate_path,
private_key_path,
private_key_saved,
serve_plain_dns,
});
return (
<div className="encryption">
<PageTitle title={t('encryption_settings')} />
{encryption.processing && <Loading />}
{!encryption.processing && (
<Card
title={t('encryption_title')}
subtitle={t('encryption_desc')}
bodyType="card-body box-body--settings">
<Form
initialValues={initialValues}
onSubmit={this.handleFormSubmit}
onChange={this.handleFormChange}
setTlsConfig={this.props.setTlsConfig}
validateTlsConfig={this.props.validateTlsConfig}
{...this.props.encryption}
/>
</Card>
)}
</div>
);
}
}
export default withTranslation()(Encryption);