diff --git a/lib/new-settings-loader.js b/lib/new-settings-loader.js index 3e535ca6..b6e5ab0a 100644 --- a/lib/new-settings-loader.js +++ b/lib/new-settings-loader.js @@ -22,16 +22,10 @@ const accountsSql = `update user_config set data = $2, valid = $3, schema_versio insert into user_config (type, data, valid, schema_version) select $1, $2, $3, $4 where $1 not in (select type from user_config)` function saveAccounts (accounts) { + console.log('accounts to save ' + JSON.stringify(accounts)) return loadAccounts() .then(currentAccounts => { - const emptySecretFields = _.compose( - _.map(_.last), - _.map(_.split('.')), - _.filter(e => _.get(e, accounts) === '') - )(SECRET_FIELDS) - const filledAccountInfo = _.mapValues(_.omit(emptySecretFields), accounts) - - const newAccounts = _.merge(currentAccounts, filledAccountInfo) + const newAccounts = _.merge(currentAccounts, accounts) return db.none(accountsSql, ['accounts', { accounts: newAccounts }, true, NEW_SETTINGS_LOADER_SCHEMA_VERSION]) }) } diff --git a/new-lamassu-admin/src/pages/Services/FormRenderer.js b/new-lamassu-admin/src/pages/Services/FormRenderer.js index eef0acb0..b5d46387 100644 --- a/new-lamassu-admin/src/pages/Services/FormRenderer.js +++ b/new-lamassu-admin/src/pages/Services/FormRenderer.js @@ -5,6 +5,7 @@ import * as R from 'ramda' import React from 'react' import { Button } from 'src/components/buttons' +import { SecretInput } from 'src/components/inputs/formik' const styles = { button: { @@ -40,6 +41,18 @@ const FormRenderer = ({ const values = R.merge(initialValues, value) + const saveNonEmptySecret = it => { + const emptySecretFields = R.compose( + R.map(R.prop('code')), + R.filter( + elem => + R.prop('component', elem) === SecretInput && + R.isEmpty(it[R.prop('code', elem)]) + ) + )(elements) + return save(R.omit(emptySecretFields, it)) + } + return ( + onSubmit={saveNonEmptySecret}>
{elements.map(({ component, code, display, inputProps }) => (