-
Notifications
You must be signed in to change notification settings - Fork 10
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #1445 from dhis2/DHIS2-18374/verify-email-button
feat: add send email verification button
- Loading branch information
Showing
5 changed files
with
98 additions
and
4 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,57 @@ | ||
import { useAlert, useDataMutation, useConfig } from '@dhis2/app-runtime' | ||
import { Button } from '@dhis2/ui' | ||
import PropTypes from 'prop-types' | ||
import React from 'react' | ||
import i18n from '../locales/index.js' | ||
|
||
const sendEmailVerificationMutation = { | ||
resource: 'account/sendEmailVerification', | ||
type: 'create', | ||
} | ||
|
||
export function VerifyEmail({ userEmail }) { | ||
const errorAlert = useAlert(({ message }) => message, { critical: true }) | ||
const successAlert = useAlert(({ message }) => message, { success: true }) | ||
const { systemInfo } = useConfig() | ||
|
||
const [mutateEmailVerification, { loading: mutationLoading }] = | ||
useDataMutation(sendEmailVerificationMutation, { | ||
onComplete: () => { | ||
successAlert.show({ | ||
message: i18n.t( | ||
'Email verification link sent successfully!' | ||
), | ||
}) | ||
}, | ||
onError: (err) => { | ||
errorAlert.show({ | ||
message: | ||
err.message || | ||
i18n.t('Failed to send email verification link.'), | ||
}) | ||
}, | ||
}) | ||
|
||
const emailConfigured = systemInfo?.emailConfigured | ||
|
||
if (!emailConfigured) { | ||
return null // If emailConfigured is false, don't display the button | ||
} | ||
|
||
return ( | ||
<div style={{ display: 'flex', alignItems: 'center', gap: '10px' }}> | ||
<Button | ||
secondary | ||
onClick={mutateEmailVerification} | ||
disabled={mutationLoading || !userEmail} | ||
loading={mutationLoading} | ||
> | ||
{i18n.t('Verify Email')} | ||
</Button> | ||
</div> | ||
) | ||
} | ||
|
||
VerifyEmail.propTypes = { | ||
userEmail: PropTypes.string.isRequired, | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
96c01c7
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
🎉 Published on https://dhis2-user-profile.netlify.app as production
🚀 Deployed on https://674096e7a86847b0c48a7d2f--dhis2-user-profile.netlify.app