2022-04-27 12:13:42 -04:00
|
|
|
import { useState } from 'react'
|
2022-05-16 04:02:17 -04:00
|
|
|
import { Alert } from 'react-bootstrap'
|
2022-04-25 07:04:44 -04:00
|
|
|
import { useTranslation } from 'react-i18next'
|
|
|
|
import importOverleafModules from '../../../../macros/import-overleaf-module.macro'
|
|
|
|
import { useSSOContext, SSOSubscription } from '../context/sso-context'
|
|
|
|
import { SSOLinkingWidget } from './linking/sso-widget'
|
2022-04-27 12:13:42 -04:00
|
|
|
import getMeta from '../../../utils/meta'
|
2022-04-25 07:04:44 -04:00
|
|
|
|
|
|
|
function LinkingSection() {
|
|
|
|
const { t } = useTranslation()
|
|
|
|
const { subscriptions } = useSSOContext()
|
2022-05-16 04:02:17 -04:00
|
|
|
const ssoErrorMessage = getMeta('ol-ssoErrorMessage') as string
|
2022-05-16 04:02:32 -04:00
|
|
|
const projectSyncSuccessMessage = getMeta(
|
|
|
|
'ol-projectSyncSuccessMessage'
|
|
|
|
) as string
|
2022-05-26 05:39:07 -04:00
|
|
|
const [integrationLinkingWidgets] = useState<any[]>(
|
2022-04-27 12:13:42 -04:00
|
|
|
() =>
|
|
|
|
getMeta('integrationLinkingWidgets') ||
|
|
|
|
importOverleafModules('integrationLinkingWidgets')
|
|
|
|
)
|
2022-05-26 05:39:07 -04:00
|
|
|
const [referenceLinkingWidgets] = useState<any[]>(
|
2022-04-27 12:13:42 -04:00
|
|
|
() =>
|
|
|
|
getMeta('referenceLinkingWidgets') ||
|
|
|
|
importOverleafModules('referenceLinkingWidgets')
|
|
|
|
)
|
|
|
|
|
2022-04-25 07:04:44 -04:00
|
|
|
const hasIntegrationLinkingSection = integrationLinkingWidgets.length
|
|
|
|
const hasReferencesLinkingSection = referenceLinkingWidgets.length
|
|
|
|
const hasSSOLinkingSection = Object.keys(subscriptions).length > 0
|
|
|
|
|
|
|
|
if (
|
|
|
|
!hasIntegrationLinkingSection &&
|
|
|
|
!hasReferencesLinkingSection &&
|
|
|
|
!hasSSOLinkingSection
|
|
|
|
) {
|
|
|
|
return null
|
|
|
|
}
|
|
|
|
|
|
|
|
return (
|
|
|
|
<>
|
|
|
|
<h3>{t('integrations')}</h3>
|
2022-04-26 11:20:09 -04:00
|
|
|
<p className="small">{t('linked_accounts_explained')}</p>
|
2022-04-25 07:04:44 -04:00
|
|
|
{hasIntegrationLinkingSection ? (
|
|
|
|
<>
|
2022-04-26 11:20:09 -04:00
|
|
|
<h3 id="project-sync" className="text-capitalize">
|
2022-05-16 04:02:50 -04:00
|
|
|
{t('project_synchronisation')}
|
2022-04-26 11:20:09 -04:00
|
|
|
</h3>
|
2022-05-16 04:02:32 -04:00
|
|
|
{projectSyncSuccessMessage ? (
|
|
|
|
<Alert bsStyle="success">{projectSyncSuccessMessage}</Alert>
|
|
|
|
) : null}
|
2022-04-25 07:04:44 -04:00
|
|
|
<div className="settings-widgets-container">
|
|
|
|
{integrationLinkingWidgets.map(
|
|
|
|
({ import: importObject, path }, widgetIndex) => (
|
|
|
|
<ModuleLinkingWidget
|
|
|
|
key={Object.keys(importObject)[0]}
|
|
|
|
ModuleComponent={Object.values(importObject)[0]}
|
|
|
|
isLast={widgetIndex === integrationLinkingWidgets.length - 1}
|
|
|
|
/>
|
|
|
|
)
|
|
|
|
)}
|
|
|
|
</div>
|
|
|
|
</>
|
|
|
|
) : null}
|
|
|
|
{hasReferencesLinkingSection ? (
|
|
|
|
<>
|
2022-04-26 11:20:09 -04:00
|
|
|
<h3 id="references" className="text-capitalize">
|
2022-05-24 03:47:08 -04:00
|
|
|
{t('reference_managers')}
|
2022-04-26 11:20:09 -04:00
|
|
|
</h3>
|
2022-04-25 07:04:44 -04:00
|
|
|
<div className="settings-widgets-container">
|
|
|
|
{referenceLinkingWidgets.map(
|
|
|
|
({ import: importObject, path }, widgetIndex) => (
|
|
|
|
<ModuleLinkingWidget
|
|
|
|
key={Object.keys(importObject)[0]}
|
|
|
|
ModuleComponent={Object.values(importObject)[0]}
|
|
|
|
isLast={widgetIndex === referenceLinkingWidgets.length - 1}
|
|
|
|
/>
|
|
|
|
)
|
|
|
|
)}
|
|
|
|
</div>
|
|
|
|
</>
|
|
|
|
) : null}
|
|
|
|
{hasSSOLinkingSection ? (
|
|
|
|
<>
|
2022-04-26 11:20:09 -04:00
|
|
|
<h3 id="linked-accounts" className="text-capitalize">
|
|
|
|
{t('linked_accounts')}
|
|
|
|
</h3>
|
2022-05-16 04:02:17 -04:00
|
|
|
{ssoErrorMessage ? (
|
|
|
|
<Alert bsStyle="danger">
|
|
|
|
{t('sso_link_error')}: {ssoErrorMessage}
|
|
|
|
</Alert>
|
|
|
|
) : null}
|
2022-04-25 07:04:44 -04:00
|
|
|
<div className="settings-widgets-container">
|
|
|
|
{Object.values(subscriptions).map(
|
|
|
|
(subscription, subscriptionIndex) => (
|
|
|
|
<SSOLinkingWidgetContainer
|
|
|
|
key={subscription.providerId}
|
|
|
|
subscription={subscription}
|
|
|
|
isLast={
|
|
|
|
subscriptionIndex === Object.keys(subscriptions).length - 1
|
|
|
|
}
|
|
|
|
/>
|
|
|
|
)
|
|
|
|
)}
|
|
|
|
</div>
|
|
|
|
</>
|
|
|
|
) : null}
|
|
|
|
{hasIntegrationLinkingSection ||
|
|
|
|
hasReferencesLinkingSection ||
|
|
|
|
hasSSOLinkingSection ? (
|
|
|
|
<hr />
|
|
|
|
) : null}
|
|
|
|
</>
|
|
|
|
)
|
|
|
|
}
|
|
|
|
|
|
|
|
type LinkingWidgetProps = {
|
|
|
|
ModuleComponent: any
|
|
|
|
isLast: boolean
|
|
|
|
}
|
|
|
|
|
|
|
|
function ModuleLinkingWidget({ ModuleComponent, isLast }: LinkingWidgetProps) {
|
|
|
|
return (
|
|
|
|
<>
|
|
|
|
<ModuleComponent />
|
|
|
|
{isLast ? null : <hr />}
|
|
|
|
</>
|
|
|
|
)
|
|
|
|
}
|
|
|
|
|
|
|
|
type SSOLinkingWidgetContainerProps = {
|
|
|
|
subscription: SSOSubscription
|
|
|
|
isLast: boolean
|
|
|
|
}
|
|
|
|
|
|
|
|
function SSOLinkingWidgetContainer({
|
|
|
|
subscription,
|
|
|
|
isLast,
|
|
|
|
}: SSOLinkingWidgetContainerProps) {
|
|
|
|
const { t } = useTranslation()
|
|
|
|
const { unlink } = useSSOContext()
|
|
|
|
|
2022-05-26 05:39:07 -04:00
|
|
|
let description = ''
|
2022-04-26 11:20:09 -04:00
|
|
|
switch (subscription.providerId) {
|
|
|
|
case 'collabratec':
|
|
|
|
description = t('linked_collabratec_description')
|
|
|
|
break
|
|
|
|
case 'google':
|
|
|
|
case 'twitter':
|
2022-05-24 03:47:08 -04:00
|
|
|
description = `${t('login_with_service', {
|
2022-04-26 11:20:09 -04:00
|
|
|
service: subscription.provider.name,
|
2022-05-24 03:47:08 -04:00
|
|
|
})}.`
|
2022-04-26 11:20:09 -04:00
|
|
|
break
|
|
|
|
case 'orcid':
|
|
|
|
description = t('oauth_orcid_description')
|
|
|
|
break
|
|
|
|
}
|
|
|
|
|
2022-04-25 07:04:44 -04:00
|
|
|
return (
|
|
|
|
<>
|
|
|
|
<SSOLinkingWidget
|
|
|
|
providerId={subscription.providerId}
|
|
|
|
title={subscription.provider.name}
|
2022-04-26 11:20:09 -04:00
|
|
|
description={description}
|
2022-04-25 07:04:44 -04:00
|
|
|
helpPath={subscription.provider.descriptionOptions?.link}
|
|
|
|
linked={subscription.linked}
|
|
|
|
linkPath={subscription.provider.linkPath}
|
|
|
|
onUnlink={() => unlink(subscription.providerId)}
|
|
|
|
/>
|
|
|
|
{isLast ? null : <hr />}
|
|
|
|
</>
|
|
|
|
)
|
|
|
|
}
|
|
|
|
|
|
|
|
export default LinkingSection
|