Skip to content

Commit

Permalink
feat: disable verify email button if email is not valid
Browse files Browse the repository at this point in the history
  • Loading branch information
Chisomchima committed Dec 11, 2024
1 parent 07346f9 commit c6f3014
Showing 1 changed file with 6 additions and 2 deletions.
8 changes: 6 additions & 2 deletions src/layout/VerifyEmail.component.js
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,8 @@ const sendEmailVerificationMutation = {
type: 'create',
}

const emailRegex = /^(([^<>()[\]\\.,;:\s@"]+(\.[^<>()[\]\\.,;:\s@"]+)*)|(".+"))@((\[[0-9]{1,3}\.[0-9]{1,3}\.[0-9]{1,3}\.[0-9]{1,3}\])|(([a-zA-Z\-0-9]+\.)+[a-zA-Z]{2,}))$/i

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

const emailConfigured = systemInfo?.emailConfigured

const isValidEmail = emailRegex.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

0 comments on commit c6f3014

Please sign in to comment.