diff --git a/client/src/actions/access.js b/client/src/actions/access.js index 8e1efab0..e04daac0 100644 --- a/client/src/actions/access.js +++ b/client/src/actions/access.js @@ -2,9 +2,9 @@ import { createAction } from 'redux-actions'; import i18next from 'i18next'; import apiClient from '../api/Api'; -import { normalizeTextarea } from '../helpers/helpers'; import { addErrorToast, addSuccessToast } from './toasts'; import { BLOCK_ACTIONS } from '../helpers/constants'; +import { splitByNewLine } from '../helpers/helpers'; export const getAccessListRequest = createAction('GET_ACCESS_LIST_REQUEST'); export const getAccessListFailure = createAction('GET_ACCESS_LIST_FAILURE'); @@ -31,9 +31,9 @@ export const setAccessList = (config) => async (dispatch) => { const { allowed_clients, disallowed_clients, blocked_hosts } = config; const values = { - allowed_clients: normalizeTextarea(allowed_clients), - disallowed_clients: normalizeTextarea(disallowed_clients), - blocked_hosts: normalizeTextarea(blocked_hosts), + allowed_clients: splitByNewLine(allowed_clients), + disallowed_clients: splitByNewLine(disallowed_clients), + blocked_hosts: splitByNewLine(blocked_hosts), }; await apiClient.setAccessList(values); diff --git a/client/src/actions/dnsConfig.js b/client/src/actions/dnsConfig.js index 947638c3..c599ca8d 100644 --- a/client/src/actions/dnsConfig.js +++ b/client/src/actions/dnsConfig.js @@ -1,7 +1,7 @@ import { createAction } from 'redux-actions'; import apiClient from '../api/Api'; -import { normalizeTextarea } from '../helpers/helpers'; +import { splitByNewLine } from '../helpers/helpers'; import { addErrorToast, addSuccessToast } from './toasts'; export const getDnsConfigRequest = createAction('GET_DNS_CONFIG_REQUEST'); @@ -30,11 +30,11 @@ export const setDnsConfig = (config) => async (dispatch) => { let hasDnsSettings = false; if (Object.prototype.hasOwnProperty.call(data, 'bootstrap_dns')) { - data.bootstrap_dns = normalizeTextarea(config.bootstrap_dns); + data.bootstrap_dns = splitByNewLine(config.bootstrap_dns); hasDnsSettings = true; } if (Object.prototype.hasOwnProperty.call(data, 'upstream_dns')) { - data.upstream_dns = normalizeTextarea(config.upstream_dns); + data.upstream_dns = splitByNewLine(config.upstream_dns); hasDnsSettings = true; } diff --git a/client/src/actions/index.js b/client/src/actions/index.js index 2cef57e6..3d3f1b63 100644 --- a/client/src/actions/index.js +++ b/client/src/actions/index.js @@ -2,7 +2,7 @@ import { createAction } from 'redux-actions'; import i18next from 'i18next'; import axios from 'axios'; -import { isVersionGreater, normalizeTextarea, sortClients } from '../helpers/helpers'; +import { isVersionGreater, splitByNewLine, sortClients } from '../helpers/helpers'; import { CHECK_TIMEOUT, SETTINGS_NAMES } from '../helpers/constants'; import { getTlsStatus } from './encryption'; import apiClient from '../api/Api'; @@ -279,8 +279,8 @@ export const testUpstream = (config) => async (dispatch) => { dispatch(testUpstreamRequest()); try { const values = { ...config }; - values.bootstrap_dns = normalizeTextarea(values.bootstrap_dns); - values.upstream_dns = normalizeTextarea(values.upstream_dns); + values.bootstrap_dns = splitByNewLine(values.bootstrap_dns); + values.upstream_dns = splitByNewLine(values.upstream_dns); const upstreamResponse = await apiClient.testUpstream(values); const testMessages = Object.keys(upstreamResponse) diff --git a/client/src/components/Settings/Clients/ClientsTable.js b/client/src/components/Settings/Clients/ClientsTable.js index e767cfb9..a179ac30 100644 --- a/client/src/components/Settings/Clients/ClientsTable.js +++ b/client/src/components/Settings/Clients/ClientsTable.js @@ -4,7 +4,7 @@ import { Trans, withTranslation } from 'react-i18next'; import ReactTable from 'react-table'; import { MODAL_TYPE } from '../../../helpers/constants'; -import { normalizeTextarea } from '../../../helpers/helpers'; +import { splitByNewLine } from '../../../helpers/helpers'; import Card from '../../ui/Card'; import Modal from './Modal'; import CellWrap from '../../ui/CellWrap'; @@ -30,7 +30,7 @@ class ClientsTable extends Component { } if (values.upstreams && typeof values.upstreams === 'string') { - config.upstreams = normalizeTextarea(values.upstreams); + config.upstreams = splitByNewLine(values.upstreams); } else { config.upstreams = []; } diff --git a/client/src/components/Settings/Dns/Access/Form.js b/client/src/components/Settings/Dns/Access/Form.js index 8edc3189..4f8342f0 100644 --- a/client/src/components/Settings/Dns/Access/Form.js +++ b/client/src/components/Settings/Dns/Access/Form.js @@ -4,7 +4,10 @@ import { Field, reduxForm } from 'redux-form'; import { Trans, withTranslation } from 'react-i18next'; import flow from 'lodash/flow'; import { renderTextareaField } from '../../../../helpers/form'; -import { normalizeMultiline } from '../../../../helpers/helpers'; +import { + trimMultilineString, + removeEmptyLines, +} from '../../../../helpers/helpers'; import { FORM_NAME } from '../../../../helpers/constants'; const fields = [ @@ -12,16 +15,19 @@ 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, }, ]; @@ -31,7 +37,7 @@ const Form = (props) => { } = props; const renderField = ({ - id, title, subtitle, disabled = processingSet, + id, title, subtitle, disabled = processingSet, normalizeOnBlur, }) =>