overleaf/services/web/frontend/js/features/settings/components/emails/resend-confirmation-email-button.tsx
ilkin-overleaf 5b0c122f5d Merge pull request #7290 from overleaf/ii-7154-list-user-emails
List of user emails

GitOrigin-RevId: 28a8e405812932ba7ebd8043a4dc9d3c573a68b2
2022-04-11 08:03:38 +00:00

62 lines
1.5 KiB
TypeScript

import { useEffect } from 'react'
import { useTranslation } from 'react-i18next'
import Icon from '../../../../shared/components/icon'
import useAsync from '../../../../shared/hooks/use-async'
import { postJSON } from '../../../../infrastructure/fetch-json'
import { UserEmailData } from '../../../../../../types/user-email'
import { useUserEmailsContext } from '../../context/user-email-context'
type ResendConfirmationEmailButtonProps = {
email: UserEmailData['email']
}
function ResendConfirmationEmailButton({
email,
}: ResendConfirmationEmailButtonProps) {
const { t } = useTranslation()
const { isLoading, isError, runAsync } = useAsync()
const { setLoading } = useUserEmailsContext()
// Update global isLoading prop
useEffect(() => {
setLoading(isLoading)
}, [setLoading, isLoading])
const handleResendConfirmationEmail = () => {
runAsync(
postJSON('/user/emails/resend_confirmation', {
body: {
email,
},
})
)
}
if (isLoading) {
return (
<>
<Icon type="refresh" spin fw /> {t('sending')}...
</>
)
}
return (
<>
<button
className="btn btn-inline-link"
onClick={handleResendConfirmationEmail}
>
{t('resend_confirmation_email')}
</button>
<br />
{isError && (
<span className="text-danger">
<Icon type="exclamation-triangle" fw />{' '}
{t('error_performing_request')}
</span>
)}
</>
)
}
export default ResendConfirmationEmailButton