import { useState } from 'react' import { Trans, useTranslation } from 'react-i18next' import { UserEmailData } from '../../../../../../types/user-email' import Email from './email' import InstitutionAndRole from './institution-and-role' import EmailCell from './cell' import Actions from './actions' import { institutionAlreadyLinked } from '../../utils/selectors' import { useUserEmailsContext } from '../../context/user-email-context' import getMeta from '../../../../utils/meta' import { ssoAvailableForInstitution } from '../../utils/sso' import ReconfirmationInfo from './reconfirmation-info' import { useLocation } from '../../../../shared/hooks/use-location' 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' type EmailsRowProps = { userEmailData: UserEmailData } function EmailsRow({ userEmailData }: EmailsRowProps) { const hasSSOAffiliation = Boolean( userEmailData.affiliation && ssoAvailableForInstitution(userEmailData.affiliation.institution) ) return ( <> {userEmailData.affiliation?.institution && ( )} {hasSSOAffiliation && ( )} ) } type SSOAffiliationInfoProps = { userEmailData: UserEmailData } function SSOAffiliationInfo({ userEmailData }: SSOAffiliationInfoProps) { const { samlInitPath } = getMeta('ol-ExposedSettings') const { t } = useTranslation() const { state } = useUserEmailsContext() const location = useLocation() const [linkAccountsButtonDisabled, setLinkAccountsButtonDisabled] = useState(false) function handleLinkAccountsButtonClick() { setLinkAccountsButtonDisabled(true) location.assign( `${samlInitPath}?university_id=${userEmailData.affiliation?.institution?.id}&auto=/user/settings&email=${userEmailData.email}` ) } 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 (

] } values={{ institutionName: userEmailData.affiliation?.institution.name, }} shouldUnescape tOptions={{ interpolation: { escapeValue: true } }} />

) } return (

] } />

] } />{' '} {t('find_out_more_about_institution_login')}

{t('link_accounts')}
) } export default EmailsRow