diff --git a/src/form-fields/check-box.js b/src/form-fields/check-box.js index c4932025..65da06f3 100644 --- a/src/form-fields/check-box.js +++ b/src/form-fields/check-box.js @@ -17,6 +17,7 @@ class Checkbox extends React.Component { onChange, sectionLabel, value, + explanatoryText, ...other } = this.props /* eslint-enable no-unused-vars */ @@ -31,6 +32,9 @@ class Checkbox extends React.Component { checked={value === 'true'} {...other} /> + {explanatoryText && ( +

{explanatoryText}

+ )} ) } @@ -40,6 +44,7 @@ Checkbox.propTypes = { onChange: PropTypes.func.isRequired, errorStyle: PropTypes.object, errorText: PropTypes.string, + explanatoryText: PropTypes.string, sectionLabel: PropTypes.string, value: PropTypes.string, } diff --git a/src/settingsFields.component.js b/src/settingsFields.component.js index b39752ba..4a03dfcd 100644 --- a/src/settingsFields.component.js +++ b/src/settingsFields.component.js @@ -129,6 +129,12 @@ function getMenuItems(mapping) { return optionsMenuItems.concat(sourceMenuItems) } +function isEmailConfigured(d2) { + const emailHostName = d2.system.settings.settings.keyEmailHostName + const emailUserName = d2.system.settings.settings.keyEmailUsername + return emailHostName && emailUserName +} + class SettingsFields extends React.Component { componentDidMount() { this.subscriptions = [] @@ -189,21 +195,40 @@ class SettingsFields extends React.Component { undefined, }), }) + case 'checkbox': { + const isEmailField = key === 'enforceVerifiedEmail' + const emailConfigured = isEmailConfigured(d2) + const explanatoryText = + emailConfigured && + 'Settings must be configured to send emails to enforce verified emails' + + const commonProps = { + label: fieldBase.props.floatingLabelText, + sectionLabel: mapping.sectionLabel || undefined, + style: fieldBase.props.style, + onCheck: (_event, checked) => { + if ( + isEmailField && + !emailConfigured && + checked === true + ) { + settingsActions.saveKey(key, 'false') + return + } + settingsActions.saveKey(key, checked ? 'true' : 'false') + }, + + disabled: isEmailField && isEmailField && !emailConfigured, + } - case 'checkbox': return Object.assign({}, fieldBase, { component: Checkbox, props: { - label: fieldBase.props.floatingLabelText, - sectionLabel: - (mapping.sectionLabel && mapping.sectionLabel) || - undefined, - style: fieldBase.props.style, - onCheck: (e, v) => { - settingsActions.saveKey(key, v ? 'true' : 'false') - }, + ...commonProps, + explanatoryText, }, }) + } case 'staticContent': return Object.assign({}, fieldBase, { diff --git a/src/settingsKeyMapping.js b/src/settingsKeyMapping.js index b20eb216..f3e04ab4 100644 --- a/src/settingsKeyMapping.js +++ b/src/settingsKeyMapping.js @@ -259,10 +259,6 @@ const settingsKeyMapping = { label: i18n.t('Include zero data values in analytics tables'), type: 'checkbox', }, - keyEmbeddedDashboardsEnabled: { - label: i18n.t('Enable embedded dashboards'), - type: 'checkbox', - }, keyAnalyticsCacheProgressiveTtlFactor: { label: i18n.t('Caching factor'), type: 'dropdown', @@ -552,16 +548,16 @@ const settingsKeyMapping = { label: i18n.t('Enable user account recovery'), type: 'checkbox', }, - enforceVerifiedEmail: { - label: i18n.t('Enforce verified emails'), - type: 'checkbox', - }, keyLockMultipleFailedLogins: { label: i18n.t( 'Lock user account temporarily after multiple failed login attempts' ), type: 'checkbox', }, + enforceVerifiedEmail: { + label: i18n.t('Enforce verified emails'), + type: 'checkbox', + }, keyCanGrantOwnUserAuthorityGroups: { label: i18n.t('Allow users to grant own user roles'), type: 'checkbox',