mirror of
https://github.com/yu-i-i/overleaf-cep.git
synced 2026-11-14 22:23:42 +01:00
* Merge intermediate component wrappers into OL-prefixed components * Replace all intermediate wrapper consumers with OL-prefixed components directly * Fix jsx/js files still importing deleted shim components * Remove duplicate OLNotification imports left by first pass * Rename OLTagIcon to TagIcon, remove OL prefix * Rename OLDropdownMenuItem to DropdownMenuItem, remove OL prefix * Remove OLNotification, use Notification directly * Move Notification to the main shared component folder * Update tag-icon import path out of ol/ * Move TagIcon to the main shared component folder * Update dropdown-menu-item import path out of ol/ * Move DropdownMenuItem to the main shared component folder * Fix dropdown-menu-item import path to dropdown/ subfolder * Remove BS5 alias prefixes from shared components * Restore notification-list wrapper in Notification component * Add translation for loading button * Remove redundant import aliasing * Resolve conflicts * Restore notification container `notification-list` GitOrigin-RevId: 24a5af18599a3e02ac6fd61c09cf5a49ef6e0020
109 lines
3.3 KiB
TypeScript
109 lines
3.3 KiB
TypeScript
import { Fragment } from 'react'
|
|
import { useTranslation, Trans } from 'react-i18next'
|
|
import getMeta from '../../../utils/meta'
|
|
import {
|
|
UserEmailsProvider,
|
|
useUserEmailsContext,
|
|
} from '../context/user-email-context'
|
|
import EmailsHeader from './emails/header'
|
|
import EmailsRow from './emails/row'
|
|
import AddEmail from './emails/add-email'
|
|
import Notification from '@/shared/components/notification'
|
|
import LoadingSpinner from '@/shared/components/loading-spinner'
|
|
|
|
function EmailsSectionContent() {
|
|
const { t } = useTranslation()
|
|
const {
|
|
state: { data: userEmailsData },
|
|
isInitializing,
|
|
isInitializingError,
|
|
isInitializingSuccess,
|
|
} = useUserEmailsContext()
|
|
const userEmails = Object.values(userEmailsData.byId)
|
|
const primary = userEmails.find(userEmail => userEmail.default)
|
|
|
|
// Only show the "add email" button if the user has permission to add a secondary email
|
|
const hideAddSecondaryEmail = getMeta('ol-cannot-add-secondary-email')
|
|
|
|
// Sort emails: primary first, then confirmed secondary emails, then unconfirmed secondary emails
|
|
const sortedUserEmails = [...userEmails].sort((a, b) => {
|
|
// Primary email comes first
|
|
if (a.default) return -1
|
|
if (b.default) return 1
|
|
|
|
// Then sort by confirmation status
|
|
if (a.confirmedAt && !b.confirmedAt) return -1
|
|
if (!a.confirmedAt && b.confirmedAt) return 1
|
|
|
|
// If both have the same status, sort by email string
|
|
return a.email.localeCompare(b.email)
|
|
})
|
|
|
|
return (
|
|
<>
|
|
<h2 className="h3">{t('emails_and_affiliations_title')}</h2>
|
|
<p className="small">{t('emails_and_affiliations_explanation')}</p>
|
|
<p className="small">
|
|
<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
|
|
<a
|
|
href="https://docs.overleaf.com/accounts-and-security/email-address-and-login-options"
|
|
target="_blank"
|
|
rel="noopener noreferrer"
|
|
/>,
|
|
]}
|
|
/>
|
|
</p>
|
|
<>
|
|
<EmailsHeader />
|
|
{isInitializing ? (
|
|
<div className="affiliations-table-row-highlighted">
|
|
<div className="affiliations-table-cell text-center">
|
|
<LoadingSpinner size="sm" />
|
|
</div>
|
|
</div>
|
|
) : (
|
|
<>
|
|
{sortedUserEmails.map(userEmail => (
|
|
<Fragment key={userEmail.email}>
|
|
<EmailsRow userEmailData={userEmail} primary={primary} />
|
|
<div className="horizontal-divider" />
|
|
</Fragment>
|
|
))}
|
|
</>
|
|
)}
|
|
{isInitializingSuccess && !hideAddSecondaryEmail && <AddEmail />}
|
|
{isInitializingError && (
|
|
<div className="notification-list">
|
|
<Notification
|
|
type="error"
|
|
content={t('error_performing_request')}
|
|
/>
|
|
</div>
|
|
)}
|
|
</>
|
|
</>
|
|
)
|
|
}
|
|
|
|
function EmailsSection() {
|
|
const { hasAffiliationsFeature } = getMeta('ol-ExposedSettings')
|
|
if (!hasAffiliationsFeature) {
|
|
return null
|
|
}
|
|
|
|
return (
|
|
<>
|
|
<UserEmailsProvider>
|
|
<EmailsSectionContent />
|
|
</UserEmailsProvider>
|
|
</>
|
|
)
|
|
}
|
|
|
|
export default EmailsSection
|