Skip to content

Commit

Permalink
feat: update enforce verified email checkbox
Browse files Browse the repository at this point in the history
  • Loading branch information
Chisomchima committed Jan 16, 2025
1 parent 882f863 commit 2715478
Show file tree
Hide file tree
Showing 3 changed files with 43 additions and 17 deletions.
5 changes: 5 additions & 0 deletions src/form-fields/check-box.js
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@ class Checkbox extends React.Component {
onChange,
sectionLabel,
value,
explanatoryText,
...other
} = this.props
/* eslint-enable no-unused-vars */
Expand All @@ -31,6 +32,9 @@ class Checkbox extends React.Component {
checked={value === 'true'}
{...other}
/>
{explanatoryText && (
<p style={{ fontSize: '12px' }}>{explanatoryText}</p>
)}
</div>
)
}
Expand All @@ -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,
}
Expand Down
43 changes: 34 additions & 9 deletions src/settingsFields.component.js
Original file line number Diff line number Diff line change
Expand Up @@ -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 = []
Expand Down Expand Up @@ -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, {
Expand Down
12 changes: 4 additions & 8 deletions src/settingsKeyMapping.js
Original file line number Diff line number Diff line change
Expand Up @@ -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',
Expand Down Expand Up @@ -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',
Expand Down

0 comments on commit 2715478

Please sign in to comment.