import React from 'react'; import PropTypes from 'prop-types'; import { connect } from 'react-redux'; import { Field, reduxForm, formValueSelector } from 'redux-form'; import { Trans, withTranslation } from 'react-i18next'; import flow from 'lodash/flow'; import { renderTextareaField } from '../../../../helpers/form'; import { trimMultilineString, removeEmptyLines, } from '../../../../helpers/helpers'; import { CLIENT_ID_LINK, FORM_NAME } from '../../../../helpers/constants'; const fields = [ { id: 'allowed_clients', title: 'access_allowed_title', subtitle: 'access_allowed_desc', normalizeOnBlur: removeEmptyLines, }, { id: 'disallowed_clients', title: 'access_disallowed_title', subtitle: 'access_disallowed_desc', normalizeOnBlur: trimMultilineString, }, { id: 'blocked_hosts', title: 'access_blocked_title', subtitle: 'access_blocked_desc', normalizeOnBlur: removeEmptyLines, }, ]; let Form = (props) => { const { allowedClients, handleSubmit, submitting, invalid, processingSet, } = props; const renderField = ({ id, title, subtitle, disabled = false, processingSet, normalizeOnBlur, }) =>
text }}>{subtitle}
; renderField.propTypes = { id: PropTypes.string, title: PropTypes.string, subtitle: PropTypes.string, disabled: PropTypes.bool, normalizeOnBlur: PropTypes.func, }; return (
{ fields.map((f) => { const props = { ...f }; if (allowedClients && f.id === 'disallowed_clients') { props.disabled = true; } return renderField(props); }) }
); }; Form.propTypes = { handleSubmit: PropTypes.func.isRequired, submitting: PropTypes.bool.isRequired, invalid: PropTypes.bool.isRequired, initialValues: PropTypes.object.isRequired, processingSet: PropTypes.bool.isRequired, t: PropTypes.func.isRequired, textarea: PropTypes.bool, allowedClients: PropTypes.string, }; const selector = formValueSelector(FORM_NAME.ACCESS); Form = connect((state) => { const allowedClients = selector(state, 'allowed_clients'); return { allowedClients, }; })(Form); export default flow([ withTranslation(), reduxForm({ form: FORM_NAME.ACCESS, }), ])(Form);