2022-04-08 07:00:46 -04:00
|
|
|
import { Fragment } from 'react'
|
|
|
|
import { useTranslation, Trans } from 'react-i18next'
|
2022-04-22 09:49:26 -04:00
|
|
|
import getMeta from '../../../utils/meta'
|
2022-04-08 07:00:46 -04:00
|
|
|
import {
|
|
|
|
UserEmailsProvider,
|
|
|
|
useUserEmailsContext,
|
|
|
|
} from '../context/user-email-context'
|
|
|
|
import EmailsHeader from './emails/header'
|
|
|
|
import EmailsRow from './emails/row'
|
2022-04-25 07:05:07 -04:00
|
|
|
import AddEmail from './emails/add-email'
|
2022-04-22 09:49:26 -04:00
|
|
|
import Icon from '../../../shared/components/icon'
|
2024-05-15 10:31:00 -04:00
|
|
|
import OLNotification from '@/features/ui/components/ol/ol-notification'
|
2022-05-16 04:03:42 -04:00
|
|
|
import { LeaversSurveyAlert } from './leavers-survey-alert'
|
2022-04-08 07:00:46 -04:00
|
|
|
|
|
|
|
function EmailsSectionContent() {
|
|
|
|
const { t } = useTranslation()
|
|
|
|
const {
|
|
|
|
state: { data: userEmailsData },
|
2022-04-22 09:49:26 -04:00
|
|
|
isInitializing,
|
|
|
|
isInitializingError,
|
2022-04-29 07:10:10 -04:00
|
|
|
isInitializingSuccess,
|
2022-04-08 07:00:46 -04:00
|
|
|
} = useUserEmailsContext()
|
|
|
|
const userEmails = Object.values(userEmailsData.byId)
|
|
|
|
|
2023-07-14 05:12:12 -04:00
|
|
|
// Only show the "add email" button if the user has permission to add a secondary email
|
2024-06-18 06:01:37 -04:00
|
|
|
const hideAddSecondaryEmail = getMeta('ol-cannot-add-secondary-email')
|
2023-07-14 05:12:12 -04:00
|
|
|
|
2022-04-08 07:00:46 -04:00
|
|
|
return (
|
|
|
|
<>
|
|
|
|
<h3>{t('emails_and_affiliations_title')}</h3>
|
|
|
|
<p className="small">{t('emails_and_affiliations_explanation')}</p>
|
|
|
|
<p className="small">
|
2022-09-22 06:53:03 -04:00
|
|
|
<Trans
|
|
|
|
i18nKey="change_primary_email_address_instructions"
|
|
|
|
components={[
|
|
|
|
// eslint-disable-next-line react/jsx-key
|
|
|
|
<strong />,
|
|
|
|
// eslint-disable-next-line jsx-a11y/anchor-has-content, react/jsx-key
|
2024-02-05 10:24:01 -05:00
|
|
|
<a
|
|
|
|
href="/learn/how-to/Managing_your_Overleaf_emails"
|
|
|
|
target="_blank"
|
|
|
|
/>,
|
2022-09-22 06:53:03 -04:00
|
|
|
]}
|
|
|
|
/>
|
2022-04-08 07:00:46 -04:00
|
|
|
</p>
|
2022-04-29 07:10:10 -04:00
|
|
|
<>
|
2022-04-25 07:05:07 -04:00
|
|
|
<EmailsHeader />
|
|
|
|
{isInitializing ? (
|
2024-07-22 04:10:54 -04:00
|
|
|
<div className="affiliations-table-row-highlighted">
|
2022-04-29 07:10:10 -04:00
|
|
|
<div className="affiliations-table-cell text-center">
|
|
|
|
<Icon type="refresh" fw spin /> {t('loading')}...
|
|
|
|
</div>
|
2022-04-25 07:05:07 -04:00
|
|
|
</div>
|
|
|
|
) : (
|
|
|
|
<>
|
|
|
|
{userEmails?.map(userEmail => (
|
|
|
|
<Fragment key={userEmail.email}>
|
|
|
|
<EmailsRow userEmailData={userEmail} />
|
2022-04-22 09:49:26 -04:00
|
|
|
<div className="horizontal-divider" />
|
2022-04-25 07:05:07 -04:00
|
|
|
</Fragment>
|
|
|
|
))}
|
|
|
|
</>
|
|
|
|
)}
|
2022-05-16 04:03:42 -04:00
|
|
|
{isInitializingSuccess && <LeaversSurveyAlert />}
|
2023-07-14 05:12:12 -04:00
|
|
|
{isInitializingSuccess && !hideAddSecondaryEmail && <AddEmail />}
|
2022-04-25 07:05:07 -04:00
|
|
|
{isInitializingError && (
|
2024-05-15 10:31:00 -04:00
|
|
|
<OLNotification
|
2024-04-15 04:21:52 -04:00
|
|
|
type="error"
|
|
|
|
content={t('error_performing_request')}
|
|
|
|
bs3Props={{
|
|
|
|
icon: <Icon type="exclamation-triangle" fw />,
|
|
|
|
className: 'text-center',
|
|
|
|
}}
|
|
|
|
/>
|
2022-04-25 07:05:07 -04:00
|
|
|
)}
|
2022-04-29 07:10:10 -04:00
|
|
|
</>
|
2022-04-08 07:00:46 -04:00
|
|
|
</>
|
|
|
|
)
|
|
|
|
}
|
|
|
|
|
|
|
|
function EmailsSection() {
|
2024-06-18 06:01:37 -04:00
|
|
|
const { hasAffiliationsFeature } = getMeta('ol-ExposedSettings')
|
2022-04-22 09:49:26 -04:00
|
|
|
if (!hasAffiliationsFeature) {
|
|
|
|
return null
|
|
|
|
}
|
|
|
|
|
2022-04-08 07:00:46 -04:00
|
|
|
return (
|
2022-04-25 07:04:44 -04:00
|
|
|
<>
|
|
|
|
<UserEmailsProvider>
|
|
|
|
<EmailsSectionContent />
|
|
|
|
</UserEmailsProvider>
|
|
|
|
</>
|
2022-04-08 07:00:46 -04:00
|
|
|
)
|
|
|
|
}
|
|
|
|
|
|
|
|
export default EmailsSection
|