Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat: verify email warning #1458

Open
wants to merge 5 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from 3 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
7 changes: 5 additions & 2 deletions i18n/en.pot
Original file line number Diff line number Diff line change
Expand Up @@ -5,8 +5,8 @@ msgstr ""
"Content-Type: text/plain; charset=utf-8\n"
"Content-Transfer-Encoding: 8bit\n"
"Plural-Forms: nplurals=2; plural=(n != 1)\n"
"POT-Creation-Date: 2024-11-21T08:20:57.566Z\n"
"PO-Revision-Date: 2024-11-21T08:20:57.566Z\n"
"POT-Creation-Date: 2024-12-16T05:17:28.155Z\n"
"PO-Revision-Date: 2024-12-16T05:17:28.155Z\n"

msgid "Never"
msgstr "Never"
Expand Down Expand Up @@ -376,6 +376,9 @@ msgstr "Failed to send email verification link."
msgid "Verify Email"
msgstr "Verify Email"

msgid "Please verify your email"
msgstr "Please verify your email"

msgid "Manage personal access tokens"
msgstr "Manage personal access tokens"

Expand Down
2 changes: 2 additions & 0 deletions src/layout/FormFields.component.js
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@ import userSettingsKeyMapping from '../userSettingsMapping.js'
import AvatarEditor from './AvatarEditor.component.js'
import AppTheme from './theme.js'
import { VerifyEmail } from './VerifyEmail.component.js'
import VerifyEmailWarning from './VerifyEmailWarning.js'

const styles = {
header: {
Expand Down Expand Up @@ -387,6 +388,7 @@ class FormFields extends Component {
<div className="content-area">
<div style={styles.header}>{this.props.pageLabel}</div>
<form autoComplete="off">
<VerifyEmailWarning />
{this.renderFields(this.props.fieldKeys)}
</form>
</div>
Expand Down
50 changes: 50 additions & 0 deletions src/layout/VerifyEmailWarning.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,50 @@
import { useDataQuery, useAlert } from '@dhis2/app-runtime'
import i18n from '@dhis2/d2-i18n'
import { NoticeBox } from '@dhis2/ui'
import React from 'react'

const getUserProfileQuery = {
me: {
resource: 'me',
},
}
const getSystemSettingsQuery = {
systemSettings: {
resource: 'systemSettings',
},
}

const VerifyEmailWarning = () => {
const { data: userData, error: userError } =
useDataQuery(getUserProfileQuery)
const { data: systemData, error: systemError } = useDataQuery(
Chisomchima marked this conversation as resolved.
Show resolved Hide resolved
getSystemSettingsQuery
)

const errorAlert = useAlert(({ message }) => message, { critical: true })

const enforceVerifiedEmail =
systemData?.systemSettings?.enforceVerifiedEmail
const emailVerified = userData?.me?.emailVerified

if (userError || systemError) {
Chisomchima marked this conversation as resolved.
Show resolved Hide resolved
errorAlert.show({
message: i18n.t('Error fetching user or system data.'),
})
return null
}

if (enforceVerifiedEmail && !emailVerified) {
return (
<NoticeBox warning>
{i18n.t(
'Your email is not verified. Please verify your email to continue using the system.'
)}
</NoticeBox>
)
}

return null
}

export default VerifyEmailWarning
Loading