Skip to content

Commit

Permalink
Merge pull request #1454 from dhis2/DHIS2-18374/verify-email-button
Browse files Browse the repository at this point in the history
fix: disable verify email button
  • Loading branch information
Chisomchima authored Dec 13, 2024
2 parents 459c111 + 01c8607 commit 4006555
Showing 1 changed file with 7 additions and 2 deletions.
9 changes: 7 additions & 2 deletions src/layout/VerifyEmail.component.js
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,9 @@ const sendEmailVerificationMutation = {
type: 'create',
}

const emailRegExp =
/^[a-zA-Z0-9.!#$%&'*+/=?^_`{|}~-]+@[a-zA-Z0-9](?:[a-zA-Z0-9-]{0,61}[a-zA-Z0-9])?(?:\.[a-zA-Z0-9](?:[a-zA-Z0-9-]{0,61}[a-zA-Z0-9])?)*$/

export function VerifyEmail({ userEmail }) {
const errorAlert = useAlert(({ message }) => message, { critical: true })
const successAlert = useAlert(({ message }) => message, { success: true })
Expand All @@ -34,16 +37,18 @@ export function VerifyEmail({ userEmail }) {

const emailConfigured = systemInfo?.emailConfigured

const isValidEmail = emailRegExp.test(userEmail)

if (!emailConfigured) {
return null // If emailConfigured is false, don't display the button
return null
}

return (
<div style={{ display: 'flex', alignItems: 'center', gap: '10px' }}>
<Button
secondary
onClick={mutateEmailVerification}
disabled={mutationLoading || !userEmail}
disabled={mutationLoading || !isValidEmail || !userEmail}
loading={mutationLoading}
>
{i18n.t('Verify Email')}
Expand Down

1 comment on commit 4006555

@dhis2-bot
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Please sign in to comment.