From d4c0c36b3f29e5109575c9fe50254c117d7c1d29 Mon Sep 17 00:00:00 2001 From: Chisomchima Date: Mon, 16 Dec 2024 06:56:51 +0100 Subject: [PATCH 1/6] feat: add the verify email warning --- i18n/en.pot | 7 ++-- src/layout/FormFields.component.js | 2 ++ src/layout/VerifyEmailWarning.js | 51 ++++++++++++++++++++++++++++++ 3 files changed, 58 insertions(+), 2 deletions(-) create mode 100644 src/layout/VerifyEmailWarning.js diff --git a/i18n/en.pot b/i18n/en.pot index c8c1135b..56003add 100644 --- a/i18n/en.pot +++ b/i18n/en.pot @@ -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" @@ -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" diff --git a/src/layout/FormFields.component.js b/src/layout/FormFields.component.js index c01d84c3..297640f3 100644 --- a/src/layout/FormFields.component.js +++ b/src/layout/FormFields.component.js @@ -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: { @@ -387,6 +388,7 @@ class FormFields extends Component {
{this.props.pageLabel}
+ {this.renderFields(this.props.fieldKeys)}
diff --git a/src/layout/VerifyEmailWarning.js b/src/layout/VerifyEmailWarning.js new file mode 100644 index 00000000..d0fd6ffd --- /dev/null +++ b/src/layout/VerifyEmailWarning.js @@ -0,0 +1,51 @@ +import React from 'react' +import { useDataQuery, useConfig } from '@dhis2/app-runtime' +import i18n from '@dhis2/d2-i18n' +import { NoticeBox } from '@dhis2/ui' +import { useAlert } from '@dhis2/app-runtime' + +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( + getSystemSettingsQuery + ) + + const errorAlert = useAlert(({ message }) => message, { critical: true }) + + const enforceVerifiedEmail = + systemData?.systemSettings?.enforceVerifiedEmail + const emailVerified = userData?.me?.emailVerified + + if (userError || systemError) { + errorAlert.show({ + message: i18n.t('Error fetching user or system data.'), + }) + return null + } + + if (enforceVerifiedEmail && !emailVerified) { + return ( + + {i18n.t( + 'Your email is not verified. Please verify your email to continue using the system.' + )} + + ) + } + + return null +} + +export default VerifyEmailWarning From e9207810974328e0a8ded774988b73c5b9a760cd Mon Sep 17 00:00:00 2001 From: Chisomchima Date: Mon, 16 Dec 2024 07:02:06 +0100 Subject: [PATCH 2/6] chore: format documents --- src/layout/FormFields.component.js | 2 +- src/layout/VerifyEmailWarning.js | 5 ++--- 2 files changed, 3 insertions(+), 4 deletions(-) diff --git a/src/layout/FormFields.component.js b/src/layout/FormFields.component.js index 297640f3..b45eacea 100644 --- a/src/layout/FormFields.component.js +++ b/src/layout/FormFields.component.js @@ -17,7 +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' +import VerifyEmailWarning from './VerifyEmailWarning.js' const styles = { header: { diff --git a/src/layout/VerifyEmailWarning.js b/src/layout/VerifyEmailWarning.js index d0fd6ffd..0180e00c 100644 --- a/src/layout/VerifyEmailWarning.js +++ b/src/layout/VerifyEmailWarning.js @@ -1,8 +1,7 @@ -import React from 'react' -import { useDataQuery, useConfig } from '@dhis2/app-runtime' +import { useDataQuery, useAlert } from '@dhis2/app-runtime' import i18n from '@dhis2/d2-i18n' import { NoticeBox } from '@dhis2/ui' -import { useAlert } from '@dhis2/app-runtime' +import React from 'react' const getUserProfileQuery = { me: { From cc9a5ec2cb4b0f94663e9a63d4b3a591d11a0888 Mon Sep 17 00:00:00 2001 From: Chisomchima Date: Thu, 19 Dec 2024 13:58:24 +0100 Subject: [PATCH 3/6] feat: get data from d2 config --- i18n/en.pot | 12 +++++--- src/app.router.js | 15 +++++++++- src/layout/FormFields.component.js | 4 ++- src/layout/VerifyEmailWarning.js | 47 +++++++----------------------- src/layout/app.css | 4 +++ 5 files changed, 40 insertions(+), 42 deletions(-) diff --git a/i18n/en.pot b/i18n/en.pot index 56003add..3f852e6a 100644 --- a/i18n/en.pot +++ b/i18n/en.pot @@ -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-12-16T05:17:28.155Z\n" -"PO-Revision-Date: 2024-12-16T05:17:28.155Z\n" +"POT-Creation-Date: 2024-12-19T12:57:22.277Z\n" +"PO-Revision-Date: 2024-12-19T12:57:22.277Z\n" msgid "Never" msgstr "Never" @@ -376,8 +376,12 @@ msgstr "Failed to send email verification link." msgid "Verify Email" msgstr "Verify Email" -msgid "Please verify your email" -msgstr "Please verify your email" +msgid "" +"Your email is not verified. Please verify your email to continue using the " +"system." +msgstr "" +"Your email is not verified. Please verify your email to continue using the " +"system." msgid "Manage personal access tokens" msgstr "Manage personal access tokens" diff --git a/src/app.router.js b/src/app.router.js index 6cd42999..07ffba33 100644 --- a/src/app.router.js +++ b/src/app.router.js @@ -48,7 +48,20 @@ class AppRouter extends Component { return { baseUrl, apiVersion } } + getDefaultRedirect() { + const enforceVerifiedEmail = + this.props.d2.system.settings.settings.enforceVerifiedEmail + const emailVerified = this.props.d2.currentUser.emailVerified + + // Redirect to the profile page if email is unverified and the setting is enforced + return enforceVerifiedEmail && !emailVerified + ? '/profile' + : '/viewProfile' + } + render() { + const defaultRedirect = this.getDefaultRedirect() + return ( @@ -77,7 +90,7 @@ class AppRouter extends Component { component={PersonalAccessTokens} /> - + diff --git a/src/layout/FormFields.component.js b/src/layout/FormFields.component.js index b45eacea..b3cc44f1 100644 --- a/src/layout/FormFields.component.js +++ b/src/layout/FormFields.component.js @@ -388,7 +388,9 @@ class FormFields extends Component {
{this.props.pageLabel}
- + {this.context?.d2 && ( + + )} {this.renderFields(this.props.fieldKeys)}
diff --git a/src/layout/VerifyEmailWarning.js b/src/layout/VerifyEmailWarning.js index 0180e00c..06af578f 100644 --- a/src/layout/VerifyEmailWarning.js +++ b/src/layout/VerifyEmailWarning.js @@ -1,46 +1,21 @@ -import { useDataQuery, useAlert } from '@dhis2/app-runtime' +import { useDataQuery } 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( - getSystemSettingsQuery - ) - - const errorAlert = useAlert(({ message }) => message, { critical: true }) - - const enforceVerifiedEmail = - systemData?.systemSettings?.enforceVerifiedEmail - const emailVerified = userData?.me?.emailVerified - - if (userError || systemError) { - errorAlert.show({ - message: i18n.t('Error fetching user or system data.'), - }) - return null - } +const VerifyEmailWarning = ({ config }) => { + const enforceVerifiedEmail = config.system.settings.settings.enforceVerifiedEmail + const emailVerified = config.currentUser.emailVerified if (enforceVerifiedEmail && !emailVerified) { return ( - - {i18n.t( - 'Your email is not verified. Please verify your email to continue using the system.' - )} - +
+ + {i18n.t( + 'Your email is not verified. Please verify your email to continue using the system.' + )} + +
) } diff --git a/src/layout/app.css b/src/layout/app.css index c8e8bd00..dbf5fb82 100644 --- a/src/layout/app.css +++ b/src/layout/app.css @@ -26,6 +26,10 @@ html, body { margin: 0; } +.noticebox-wrapper{ + margin-right: 15px; +} + .info-cell-name { color: #777; font-size: 12pt; From 17487ae021e417a97f5bb9a8fa03ffca1b28ebaa Mon Sep 17 00:00:00 2001 From: Chisomchima Date: Thu, 19 Dec 2024 14:07:39 +0100 Subject: [PATCH 4/6] chore: run yarn format --- src/layout/FormFields.component.js | 2 +- src/layout/VerifyEmailWarning.js | 24 ++++++++++++++++++------ 2 files changed, 19 insertions(+), 7 deletions(-) diff --git a/src/layout/FormFields.component.js b/src/layout/FormFields.component.js index b3cc44f1..45f91315 100644 --- a/src/layout/FormFields.component.js +++ b/src/layout/FormFields.component.js @@ -17,7 +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' +import { VerifyEmailWarning } from './VerifyEmailWarning.js' const styles = { header: { diff --git a/src/layout/VerifyEmailWarning.js b/src/layout/VerifyEmailWarning.js index 06af578f..cbe3ab09 100644 --- a/src/layout/VerifyEmailWarning.js +++ b/src/layout/VerifyEmailWarning.js @@ -1,15 +1,16 @@ -import { useDataQuery } from '@dhis2/app-runtime' import i18n from '@dhis2/d2-i18n' import { NoticeBox } from '@dhis2/ui' +import PropTypes from 'prop-types' import React from 'react' -const VerifyEmailWarning = ({ config }) => { - const enforceVerifiedEmail = config.system.settings.settings.enforceVerifiedEmail - const emailVerified = config.currentUser.emailVerified +export function VerifyEmailWarning({ config }) { + const enforceVerifiedEmail = + config?.system?.settings?.enforceVerifiedEmail || false + const emailVerified = config?.currentUser?.emailVerified || false if (enforceVerifiedEmail && !emailVerified) { return ( -
+
{i18n.t( 'Your email is not verified. Please verify your email to continue using the system.' @@ -22,4 +23,15 @@ const VerifyEmailWarning = ({ config }) => { return null } -export default VerifyEmailWarning +VerifyEmailWarning.propTypes = { + config: PropTypes.shape({ + currentUser: PropTypes.shape({ + emailVerified: PropTypes.bool, + }), + system: PropTypes.shape({ + settings: PropTypes.shape({ + enforceVerifiedEmail: PropTypes.bool, + }), + }), + }).isRequired, +} From 4264a3fcf4b0a81a50ea73de191d780d3ce9594f Mon Sep 17 00:00:00 2001 From: Chisomchima Date: Tue, 7 Jan 2025 10:24:37 +0100 Subject: [PATCH 5/6] fix: update fixes --- i18n/en.pot | 4 ++-- src/app.router.js | 2 +- src/layout/VerifyEmailWarning.js | 3 ++- src/layout/app.css | 5 +++-- 4 files changed, 8 insertions(+), 6 deletions(-) diff --git a/i18n/en.pot b/i18n/en.pot index 3f852e6a..4228c8c5 100644 --- a/i18n/en.pot +++ b/i18n/en.pot @@ -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-12-19T12:57:22.277Z\n" -"PO-Revision-Date: 2024-12-19T12:57:22.277Z\n" +"POT-Creation-Date: 2025-01-07T08:32:23.225Z\n" +"PO-Revision-Date: 2025-01-07T08:32:23.226Z\n" msgid "Never" msgstr "Never" diff --git a/src/app.router.js b/src/app.router.js index 07ffba33..171e095f 100644 --- a/src/app.router.js +++ b/src/app.router.js @@ -50,7 +50,7 @@ class AppRouter extends Component { getDefaultRedirect() { const enforceVerifiedEmail = - this.props.d2.system.settings.settings.enforceVerifiedEmail + this.props.d2?.system?.settings?.settings?.enforceVerifiedEmail const emailVerified = this.props.d2.currentUser.emailVerified // Redirect to the profile page if email is unverified and the setting is enforced diff --git a/src/layout/VerifyEmailWarning.js b/src/layout/VerifyEmailWarning.js index cbe3ab09..b7d8b595 100644 --- a/src/layout/VerifyEmailWarning.js +++ b/src/layout/VerifyEmailWarning.js @@ -6,7 +6,8 @@ import React from 'react' export function VerifyEmailWarning({ config }) { const enforceVerifiedEmail = config?.system?.settings?.enforceVerifiedEmail || false - const emailVerified = config?.currentUser?.emailVerified || false + const emailVerified = + config.system?.settings?.settings?.enforceVerifiedEmail || false if (enforceVerifiedEmail && !emailVerified) { return ( diff --git a/src/layout/app.css b/src/layout/app.css index dbf5fb82..8625a39a 100644 --- a/src/layout/app.css +++ b/src/layout/app.css @@ -26,10 +26,11 @@ html, body { margin: 0; } -.noticebox-wrapper{ - margin-right: 15px; +.noticebox-wrapper { + margin-inline-end: 15px; } + .info-cell-name { color: #777; font-size: 12pt; From 5ac9cf20d2c84852ae5b2f7e2cc465dbfe0fabe1 Mon Sep 17 00:00:00 2001 From: Chisomchima Date: Tue, 7 Jan 2025 12:10:18 +0100 Subject: [PATCH 6/6] fix: lint errors and proptypes --- i18n/en.pot | 4 ++-- src/layout/VerifyEmailWarning.js | 7 ++++--- 2 files changed, 6 insertions(+), 5 deletions(-) diff --git a/i18n/en.pot b/i18n/en.pot index 4228c8c5..fd723b7b 100644 --- a/i18n/en.pot +++ b/i18n/en.pot @@ -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: 2025-01-07T08:32:23.225Z\n" -"PO-Revision-Date: 2025-01-07T08:32:23.226Z\n" +"POT-Creation-Date: 2025-01-07T11:04:56.155Z\n" +"PO-Revision-Date: 2025-01-07T11:04:56.155Z\n" msgid "Never" msgstr "Never" diff --git a/src/layout/VerifyEmailWarning.js b/src/layout/VerifyEmailWarning.js index b7d8b595..98199bf7 100644 --- a/src/layout/VerifyEmailWarning.js +++ b/src/layout/VerifyEmailWarning.js @@ -5,9 +5,8 @@ import React from 'react' export function VerifyEmailWarning({ config }) { const enforceVerifiedEmail = - config?.system?.settings?.enforceVerifiedEmail || false - const emailVerified = config.system?.settings?.settings?.enforceVerifiedEmail || false + const emailVerified = config.currentUser?.emailVerified || false if (enforceVerifiedEmail && !emailVerified) { return ( @@ -31,7 +30,9 @@ VerifyEmailWarning.propTypes = { }), system: PropTypes.shape({ settings: PropTypes.shape({ - enforceVerifiedEmail: PropTypes.bool, + settings: PropTypes.shape({ + enforceVerifiedEmail: PropTypes.bool, + }), }), }), }).isRequired,