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'
const integrationLinkingWidgets = importOverleafModules(
'integrationLinkingWidgets'
)
const referenceLinkingWidgets = importOverleafModules('referenceLinkingWidgets')
function LinkingSection() {
const { t } = useTranslation()
const { subscriptions } = useSSOContext()
const hasIntegrationLinkingSection = integrationLinkingWidgets.length
const hasReferencesLinkingSection = referenceLinkingWidgets.length
const hasSSOLinkingSection = Object.keys(subscriptions).length > 0
if (
!hasIntegrationLinkingSection &&
!hasReferencesLinkingSection &&
!hasSSOLinkingSection
) {
return null
}
return (
<>
{t('integrations')}
{t('linked_accounts_explained')}
{hasIntegrationLinkingSection ? (
<>
{t('sync_dropbox_github')}
{integrationLinkingWidgets.map(
({ import: importObject, path }, widgetIndex) => (
)
)}
>
) : null}
{hasReferencesLinkingSection ? (
<>
{t('reference_sync')}
{referenceLinkingWidgets.map(
({ import: importObject, path }, widgetIndex) => (
)
)}
>
) : null}
{hasSSOLinkingSection ? (
<>
{t('linked_accounts')}
{Object.values(subscriptions).map(
(subscription, subscriptionIndex) => (
)
)}
>
) : null}
{hasIntegrationLinkingSection ||
hasReferencesLinkingSection ||
hasSSOLinkingSection ? (
) : null}
>
)
}
type LinkingWidgetProps = {
ModuleComponent: any
isLast: boolean
}
function ModuleLinkingWidget({ ModuleComponent, isLast }: LinkingWidgetProps) {
return (
<>
{isLast ? null :
}
>
)
}
type SSOLinkingWidgetContainerProps = {
subscription: SSOSubscription
isLast: boolean
}
function SSOLinkingWidgetContainer({
subscription,
isLast,
}: SSOLinkingWidgetContainerProps) {
const { t } = useTranslation()
const { unlink } = useSSOContext()
return (
<>
unlink(subscription.providerId)}
/>
{isLast ? null :
}
>
)
}
export default LinkingSection