2022-04-08 11:00:46 +00:00
|
|
|
import { Fragment } from 'react'
|
|
|
|
import { useTranslation, Trans } from 'react-i18next'
|
2022-04-22 13:49:26 +00:00
|
|
|
import getMeta from '../../../utils/meta'
|
2022-04-08 11:00:46 +00:00
|
|
|
import {
|
|
|
|
UserEmailsProvider,
|
|
|
|
useUserEmailsContext,
|
|
|
|
} from '../context/user-email-context'
|
|
|
|
import EmailsHeader from './emails/header'
|
|
|
|
import EmailsRow from './emails/row'
|
2022-04-25 11:05:07 +00:00
|
|
|
import AddEmail from './emails/add-email'
|
2022-04-22 13:49:26 +00:00
|
|
|
import Icon from '../../../shared/components/icon'
|
|
|
|
import { Alert } from 'react-bootstrap'
|
|
|
|
import { ExposedSettings } from '../../../../../types/exposed-settings'
|
2022-05-16 08:03:42 +00:00
|
|
|
import { LeaversSurveyAlert } from './leavers-survey-alert'
|
2022-04-08 11:00:46 +00:00
|
|
|
|
|
|
|
function EmailsSectionContent() {
|
|
|
|
const { t } = useTranslation()
|
|
|
|
const {
|
|
|
|
state: { data: userEmailsData },
|
2022-04-22 13:49:26 +00:00
|
|
|
isInitializing,
|
|
|
|
isInitializingError,
|
2022-04-29 11:10:10 +00:00
|
|
|
isInitializingSuccess,
|
2022-04-08 11:00:46 +00:00
|
|
|
} = useUserEmailsContext()
|
|
|
|
const userEmails = Object.values(userEmailsData.byId)
|
|
|
|
|
|
|
|
return (
|
|
|
|
<>
|
|
|
|
<h3>{t('emails_and_affiliations_title')}</h3>
|
|
|
|
<p className="small">{t('emails_and_affiliations_explanation')}</p>
|
|
|
|
<p className="small">
|
|
|
|
<Trans i18nKey="change_primary_email_address_instructions">
|
|
|
|
<strong />
|
|
|
|
{/* eslint-disable-next-line jsx-a11y/anchor-has-content */}
|
|
|
|
<a href="/learn/how-to/Keeping_your_account_secure" />
|
|
|
|
</Trans>
|
|
|
|
</p>
|
2022-04-29 11:10:10 +00:00
|
|
|
<>
|
2022-04-25 11:05:07 +00:00
|
|
|
<EmailsHeader />
|
|
|
|
{isInitializing ? (
|
2022-04-29 11:10:10 +00:00
|
|
|
<div className="affiliations-table-row--highlighted">
|
|
|
|
<div className="affiliations-table-cell text-center">
|
|
|
|
<Icon type="refresh" fw spin /> {t('loading')}...
|
|
|
|
</div>
|
2022-04-25 11:05:07 +00:00
|
|
|
</div>
|
|
|
|
) : (
|
|
|
|
<>
|
|
|
|
{userEmails?.map(userEmail => (
|
|
|
|
<Fragment key={userEmail.email}>
|
|
|
|
<EmailsRow userEmailData={userEmail} />
|
2022-04-22 13:49:26 +00:00
|
|
|
<div className="horizontal-divider" />
|
2022-04-25 11:05:07 +00:00
|
|
|
</Fragment>
|
|
|
|
))}
|
|
|
|
</>
|
|
|
|
)}
|
2022-05-16 08:03:42 +00:00
|
|
|
{isInitializingSuccess && <LeaversSurveyAlert />}
|
2022-04-29 11:10:10 +00:00
|
|
|
{isInitializingSuccess && <AddEmail />}
|
2022-04-25 11:05:07 +00:00
|
|
|
{isInitializingError && (
|
|
|
|
<Alert bsStyle="danger" className="text-center">
|
|
|
|
<Icon type="exclamation-triangle" fw />{' '}
|
|
|
|
{t('error_performing_request')}
|
|
|
|
</Alert>
|
|
|
|
)}
|
2022-04-29 11:10:10 +00:00
|
|
|
</>
|
2022-04-08 11:00:46 +00:00
|
|
|
</>
|
|
|
|
)
|
|
|
|
}
|
|
|
|
|
|
|
|
function EmailsSection() {
|
2022-04-22 13:49:26 +00:00
|
|
|
const { hasAffiliationsFeature } = getMeta(
|
|
|
|
'ol-ExposedSettings'
|
|
|
|
) as ExposedSettings
|
|
|
|
if (!hasAffiliationsFeature) {
|
|
|
|
return null
|
|
|
|
}
|
|
|
|
|
2022-04-08 11:00:46 +00:00
|
|
|
return (
|
2022-04-25 11:04:44 +00:00
|
|
|
<>
|
|
|
|
<UserEmailsProvider>
|
|
|
|
<EmailsSectionContent />
|
|
|
|
</UserEmailsProvider>
|
|
|
|
</>
|
2022-04-08 11:00:46 +00:00
|
|
|
)
|
|
|
|
}
|
|
|
|
|
|
|
|
export default EmailsSection
|