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 } 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) => { const fields = { private_key: '', certificate_chain: '', port_https: '', port_dns_over_tls: '', server_name: '', force_https: false, enabled: false, }; Object.keys(fields).forEach(field => change(field, fields[field])); }; let Form = (props) => { const { t, handleSubmit, handleChange, isEnabled, certificateChain, privateKey, change, invalid, submitting, processing, processingValidate, not_after, valid_chain, valid_key, valid_cert, dns_names, key_type, issuer, subject, warning_validation, } = props; return (
encryption_enable_desc

encryption_server_desc
encryption_redirect_desc
encryption_https_desc
encryption_dot_desc
link]} > encryption_certificates_desc
{certificateChain &&
encryption_status:
  • {valid_chain ? encryption_chain_valid : encryption_chain_invalid }
  • {subject &&
  • encryption_subject: {subject}
  • } {issuer &&
  • encryption_issuer: {issuer}
  • } {not_after && not_after !== EMPTY_DATE &&
  • encryption_expire:  {format(not_after, 'YYYY-MM-DD HH:mm:ss')}
  • } {dns_names &&
  • encryption_hostnames: {dns_names}
  • }
}
{privateKey &&
encryption_status:

{valid_key ? encryption_key_valid : encryption_key_invalid }

}

{ (certificateChain || privateKey) && warning_validation && warning_validation }

); }; 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, processing: 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, }; 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);