import React, { Fragment } from 'react'; import { connect } from 'react-redux'; import PropTypes from 'prop-types'; import { Field, reduxForm, formValueSelector } from 'redux-form'; import { Trans, withNamespaces } from 'react-i18next'; import flow from 'lodash/flow'; import format from 'date-fns/format'; import { renderField, renderSelectField, toNumber, port, isSafePort } from '../../../helpers/form'; import { EMPTY_DATE } from '../../../helpers/constants'; 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; }; const clearFields = (change, setTlsConfig, t) => { const fields = { private_key: '', certificate_chain: '', port_https: 443, port_dns_over_tls: 853, server_name: '', force_https: false, enabled: false, }; // eslint-disable-next-line no-alert if (window.confirm(t('encryption_reset'))) { Object.keys(fields).forEach(field => change(field, fields[field])); setTlsConfig(fields); } }; let Form = (props) => { const { t, handleSubmit, handleChange, isEnabled, certificateChain, privateKey, change, invalid, submitting, processingConfig, processingValidate, not_after, valid_chain, valid_key, valid_cert, dns_names, key_type, issuer, subject, warning_validation, setTlsConfig, } = props; return (
); }; Form.propTypes = { handleSubmit: PropTypes.func.isRequired, handleChange: PropTypes.func, isEnabled: PropTypes.bool.isRequired, certificateChain: PropTypes.string.isRequired, privateKey: PropTypes.string.isRequired, change: PropTypes.func.isRequired, submitting: PropTypes.bool.isRequired, invalid: PropTypes.bool.isRequired, initialValues: PropTypes.object.isRequired, processingConfig: PropTypes.bool.isRequired, processingValidate: PropTypes.bool.isRequired, status_key: PropTypes.string, not_after: PropTypes.string, warning_validation: PropTypes.string, valid_chain: PropTypes.bool, valid_key: PropTypes.bool, valid_cert: PropTypes.bool, dns_names: PropTypes.string, key_type: PropTypes.string, issuer: PropTypes.string, subject: PropTypes.string, t: PropTypes.func.isRequired, setTlsConfig: PropTypes.func.isRequired, }; const selector = formValueSelector('encryptionForm'); Form = connect((state) => { const isEnabled = selector(state, 'enabled'); const certificateChain = selector(state, 'certificate_chain'); const privateKey = selector(state, 'private_key'); return { isEnabled, certificateChain, privateKey, }; })(Form); export default flow([ withNamespaces(), reduxForm({ form: 'encryptionForm', validate, }), ])(Form);