2022-05-30 09:47:42 -04:00
|
|
|
import { useState } from 'react'
|
2022-05-24 07:12:39 -04:00
|
|
|
import { Trans, useTranslation } from 'react-i18next'
|
2022-04-08 07:00:46 -04:00
|
|
|
import { UserEmailData } from '../../../../../../types/user-email'
|
|
|
|
import Email from './email'
|
2022-04-14 05:19:18 -04:00
|
|
|
import InstitutionAndRole from './institution-and-role'
|
2022-04-08 07:00:46 -04:00
|
|
|
import EmailCell from './cell'
|
2022-04-22 09:49:26 -04:00
|
|
|
import Actions from './actions'
|
2022-05-24 07:12:39 -04:00
|
|
|
import { institutionAlreadyLinked } from '../../utils/selectors'
|
|
|
|
import { useUserEmailsContext } from '../../context/user-email-context'
|
|
|
|
import getMeta from '../../../../utils/meta'
|
|
|
|
import { ssoAvailableForInstitution } from '../../utils/sso'
|
2022-05-31 08:06:28 -04:00
|
|
|
import ReconfirmationInfo from './reconfirmation-info'
|
2023-03-16 08:32:48 -04:00
|
|
|
import { useLocation } from '../../../../shared/hooks/use-location'
|
2024-05-15 10:31:00 -04:00
|
|
|
import OLRow from '@/features/ui/components/ol/ol-row'
|
|
|
|
import OLCol from '@/features/ui/components/ol/ol-col'
|
|
|
|
import OLButton from '@/features/ui/components/ol/ol-button'
|
2022-04-08 07:00:46 -04:00
|
|
|
|
|
|
|
type EmailsRowProps = {
|
|
|
|
userEmailData: UserEmailData
|
|
|
|
}
|
|
|
|
|
|
|
|
function EmailsRow({ userEmailData }: EmailsRowProps) {
|
2022-05-24 07:12:39 -04:00
|
|
|
const hasSSOAffiliation = Boolean(
|
|
|
|
userEmailData.affiliation &&
|
|
|
|
ssoAvailableForInstitution(userEmailData.affiliation.institution)
|
|
|
|
)
|
|
|
|
|
2022-04-08 07:00:46 -04:00
|
|
|
return (
|
2022-05-24 07:12:39 -04:00
|
|
|
<>
|
2024-05-15 10:31:00 -04:00
|
|
|
<OLRow>
|
2024-05-28 04:48:42 -04:00
|
|
|
<OLCol lg={4}>
|
2022-04-14 05:19:18 -04:00
|
|
|
<EmailCell>
|
2022-05-24 07:12:39 -04:00
|
|
|
<Email userEmailData={userEmailData} />
|
2022-04-14 05:19:18 -04:00
|
|
|
</EmailCell>
|
2024-05-15 10:31:00 -04:00
|
|
|
</OLCol>
|
2024-05-28 04:48:42 -04:00
|
|
|
<OLCol lg={5}>
|
2022-05-24 07:12:39 -04:00
|
|
|
{userEmailData.affiliation?.institution && (
|
|
|
|
<EmailCell>
|
|
|
|
<InstitutionAndRole userEmailData={userEmailData} />
|
|
|
|
</EmailCell>
|
|
|
|
)}
|
2024-05-15 10:31:00 -04:00
|
|
|
</OLCol>
|
2024-05-28 04:48:42 -04:00
|
|
|
<OLCol lg={3}>
|
2024-06-13 08:44:38 -04:00
|
|
|
<EmailCell className="text-lg-end">
|
2022-05-24 07:12:39 -04:00
|
|
|
<Actions userEmailData={userEmailData} />
|
|
|
|
</EmailCell>
|
2024-05-15 10:31:00 -04:00
|
|
|
</OLCol>
|
|
|
|
</OLRow>
|
2022-05-24 07:12:39 -04:00
|
|
|
|
|
|
|
{hasSSOAffiliation && (
|
|
|
|
<SSOAffiliationInfo userEmailData={userEmailData} />
|
|
|
|
)}
|
2022-05-31 08:06:28 -04:00
|
|
|
<ReconfirmationInfo userEmailData={userEmailData} />
|
2022-05-24 07:12:39 -04:00
|
|
|
</>
|
|
|
|
)
|
|
|
|
}
|
|
|
|
|
|
|
|
type SSOAffiliationInfoProps = {
|
|
|
|
userEmailData: UserEmailData
|
|
|
|
}
|
|
|
|
|
|
|
|
function SSOAffiliationInfo({ userEmailData }: SSOAffiliationInfoProps) {
|
2024-06-18 06:01:37 -04:00
|
|
|
const { samlInitPath } = getMeta('ol-ExposedSettings')
|
2022-05-24 07:12:39 -04:00
|
|
|
const { t } = useTranslation()
|
|
|
|
const { state } = useUserEmailsContext()
|
2023-03-16 08:32:48 -04:00
|
|
|
const location = useLocation()
|
2022-05-24 07:12:39 -04:00
|
|
|
|
2022-05-30 09:47:42 -04:00
|
|
|
const [linkAccountsButtonDisabled, setLinkAccountsButtonDisabled] =
|
|
|
|
useState(false)
|
|
|
|
|
|
|
|
function handleLinkAccountsButtonClick() {
|
|
|
|
setLinkAccountsButtonDisabled(true)
|
2023-03-16 08:32:48 -04:00
|
|
|
location.assign(
|
|
|
|
`${samlInitPath}?university_id=${userEmailData.affiliation?.institution?.id}&auto=/user/settings&email=${userEmailData.email}`
|
|
|
|
)
|
2022-05-30 09:47:42 -04:00
|
|
|
}
|
|
|
|
|
2022-05-24 07:12:39 -04:00
|
|
|
if (
|
|
|
|
!userEmailData.samlProviderId &&
|
|
|
|
institutionAlreadyLinked(state, userEmailData)
|
|
|
|
) {
|
|
|
|
// if the email is not linked to the institution, but there's another email already linked to that institution
|
|
|
|
// no SSO affiliation is displayed, since cannot have multiple emails linked to the same institution
|
|
|
|
return null
|
|
|
|
}
|
|
|
|
|
|
|
|
if (userEmailData.samlProviderId) {
|
|
|
|
return (
|
2024-05-15 10:31:00 -04:00
|
|
|
<OLRow>
|
2024-05-28 04:48:42 -04:00
|
|
|
<OLCol lg={{ span: 8, offset: 4 }}>
|
2022-05-24 07:12:39 -04:00
|
|
|
<EmailCell>
|
|
|
|
<p>
|
|
|
|
<Trans
|
|
|
|
i18nKey="acct_linked_to_institution_acct_2"
|
|
|
|
components={
|
|
|
|
/* eslint-disable-next-line jsx-a11y/anchor-has-content, react/jsx-key */
|
|
|
|
[<strong />]
|
|
|
|
}
|
|
|
|
values={{
|
|
|
|
institutionName: userEmailData.affiliation?.institution.name,
|
|
|
|
}}
|
2023-10-19 04:27:45 -04:00
|
|
|
shouldUnescape
|
|
|
|
tOptions={{ interpolation: { escapeValue: true } }}
|
2022-05-24 07:12:39 -04:00
|
|
|
/>
|
|
|
|
</p>
|
|
|
|
</EmailCell>
|
2024-05-15 10:31:00 -04:00
|
|
|
</OLCol>
|
|
|
|
</OLRow>
|
2022-05-24 07:12:39 -04:00
|
|
|
)
|
|
|
|
}
|
|
|
|
|
|
|
|
return (
|
2024-05-15 10:31:00 -04:00
|
|
|
<OLRow>
|
2024-05-28 04:48:42 -04:00
|
|
|
<OLCol lg={{ span: 8, offset: 4 }}>
|
2022-05-24 07:12:39 -04:00
|
|
|
<div className="horizontal-divider" />
|
2024-05-15 10:31:00 -04:00
|
|
|
<OLRow>
|
2024-05-28 04:48:42 -04:00
|
|
|
<OLCol lg={9}>
|
2022-05-24 07:12:39 -04:00
|
|
|
<EmailCell>
|
|
|
|
<p className="small">
|
|
|
|
<Trans
|
|
|
|
i18nKey="can_link_your_institution_acct_2"
|
|
|
|
values={{
|
|
|
|
institutionName:
|
|
|
|
userEmailData.affiliation?.institution.name,
|
|
|
|
}}
|
2023-10-19 04:27:45 -04:00
|
|
|
shouldUnescape
|
|
|
|
tOptions={{ interpolation: { escapeValue: true } }}
|
2022-05-24 07:12:39 -04:00
|
|
|
components={
|
|
|
|
/* eslint-disable-next-line jsx-a11y/anchor-has-content, react/jsx-key */
|
|
|
|
[<strong />]
|
|
|
|
}
|
|
|
|
/>
|
|
|
|
</p>
|
|
|
|
<p className="small">
|
|
|
|
<Trans
|
|
|
|
i18nKey="doing_this_allow_log_in_through_institution_2"
|
|
|
|
components={
|
|
|
|
/* eslint-disable-next-line jsx-a11y/anchor-has-content, react/jsx-key */
|
|
|
|
[<strong />]
|
|
|
|
}
|
|
|
|
/>{' '}
|
2024-02-05 10:24:01 -05:00
|
|
|
<a href="/learn/how-to/Institutional_Login" target="_blank">
|
2022-05-24 07:12:39 -04:00
|
|
|
{t('find_out_more_about_institution_login')}
|
|
|
|
</a>
|
|
|
|
</p>
|
|
|
|
</EmailCell>
|
2024-05-15 10:31:00 -04:00
|
|
|
</OLCol>
|
2024-06-13 08:44:38 -04:00
|
|
|
<OLCol lg={3} className="text-lg-end">
|
2022-05-24 07:12:39 -04:00
|
|
|
<EmailCell>
|
2024-05-15 10:31:00 -04:00
|
|
|
<OLButton
|
2024-04-23 10:12:25 -04:00
|
|
|
variant="primary"
|
|
|
|
className="btn-link-accounts"
|
2022-05-30 09:47:42 -04:00
|
|
|
disabled={linkAccountsButtonDisabled}
|
|
|
|
onClick={handleLinkAccountsButtonClick}
|
2024-04-23 10:12:25 -04:00
|
|
|
size="small"
|
2022-05-24 07:12:39 -04:00
|
|
|
>
|
|
|
|
{t('link_accounts')}
|
2024-05-15 10:31:00 -04:00
|
|
|
</OLButton>
|
2022-05-24 07:12:39 -04:00
|
|
|
</EmailCell>
|
2024-05-15 10:31:00 -04:00
|
|
|
</OLCol>
|
|
|
|
</OLRow>
|
|
|
|
</OLCol>
|
|
|
|
</OLRow>
|
2022-04-08 07:00:46 -04:00
|
|
|
)
|
|
|
|
}
|
|
|
|
|
|
|
|
export default EmailsRow
|