2022-04-08 07:00:46 -04:00
|
|
|
import { useTranslation } from 'react-i18next'
|
|
|
|
import { UserEmailData } from '../../../../../../types/user-email'
|
|
|
|
import ResendConfirmationEmailButton from './resend-confirmation-email-button'
|
2022-05-24 07:12:55 -04:00
|
|
|
import { ssoAvailableForInstitution } from '../../utils/sso'
|
2024-05-15 10:31:00 -04:00
|
|
|
import OLBadge from '@/features/ui/components/ol/ol-badge'
|
2024-04-19 08:30:23 -04:00
|
|
|
import { isBootstrap5 } from '@/features/utils/bootstrap-5'
|
|
|
|
import classnames from 'classnames'
|
2022-04-08 07:00:46 -04:00
|
|
|
|
|
|
|
type EmailProps = {
|
|
|
|
userEmailData: UserEmailData
|
|
|
|
}
|
|
|
|
|
|
|
|
function Email({ userEmailData }: EmailProps) {
|
|
|
|
const { t } = useTranslation()
|
|
|
|
|
2022-05-24 07:12:55 -04:00
|
|
|
const ssoAvailable = ssoAvailableForInstitution(
|
2022-05-30 06:18:44 -04:00
|
|
|
userEmailData.affiliation?.institution || null
|
2022-05-24 07:12:55 -04:00
|
|
|
)
|
|
|
|
|
2022-06-15 08:46:52 -04:00
|
|
|
const isPrimary = userEmailData.default
|
|
|
|
const isProfessional =
|
|
|
|
userEmailData.confirmedAt &&
|
|
|
|
userEmailData.affiliation?.institution.confirmed &&
|
|
|
|
userEmailData.affiliation.licence !== 'free'
|
|
|
|
const hasBadges = isPrimary || isProfessional
|
|
|
|
|
2022-04-08 07:00:46 -04:00
|
|
|
return (
|
|
|
|
<>
|
|
|
|
{userEmailData.email}
|
|
|
|
{!userEmailData.confirmedAt && (
|
|
|
|
<div className="small">
|
|
|
|
<strong>
|
|
|
|
{t('unconfirmed')}.
|
2022-05-24 07:12:55 -04:00
|
|
|
{!ssoAvailable && <span> {t('please_check_your_inbox')}.</span>}
|
2022-04-08 07:00:46 -04:00
|
|
|
</strong>
|
|
|
|
<br />
|
2022-05-24 07:12:55 -04:00
|
|
|
{!ssoAvailable && (
|
2022-04-08 07:00:46 -04:00
|
|
|
<ResendConfirmationEmailButton email={userEmailData.email} />
|
|
|
|
)}
|
|
|
|
</div>
|
|
|
|
)}
|
2022-06-15 08:46:52 -04:00
|
|
|
{hasBadges && (
|
2024-07-24 09:40:24 -04:00
|
|
|
<div className={classnames({ small: !isBootstrap5() })}>
|
2022-06-15 08:46:52 -04:00
|
|
|
{isPrimary && (
|
|
|
|
<>
|
2024-05-15 10:31:00 -04:00
|
|
|
<OLBadge bg="info">Primary</OLBadge>{' '}
|
2022-06-15 08:46:52 -04:00
|
|
|
</>
|
|
|
|
)}
|
|
|
|
{isProfessional && (
|
2024-05-15 10:31:00 -04:00
|
|
|
<OLBadge bg="primary">{t('professional')}</OLBadge>
|
2022-06-15 08:46:52 -04:00
|
|
|
)}
|
|
|
|
</div>
|
|
|
|
)}
|
2022-04-08 07:00:46 -04:00
|
|
|
</>
|
|
|
|
)
|
|
|
|
}
|
|
|
|
|
|
|
|
export default Email
|