import { ElementType } from 'react' 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' import getMeta from '../../../utils/meta' import { useBroadcastUser } from '@/shared/hooks/user-channel/use-broadcast-user' import OLNotification from '@/features/ui/components/ol/ol-notification' const availableIntegrationLinkingWidgets = importOverleafModules( 'integrationLinkingWidgets' ) as any[] const availableReferenceLinkingWidgets = importOverleafModules( 'referenceLinkingWidgets' ) as any[] const availableLangFeedbackLinkingWidgets = importOverleafModules( 'langFeedbackLinkingWidgets' ) as any[] function LinkingSection() { useBroadcastUser() const { t } = useTranslation() const { subscriptions } = useSSOContext() const ssoErrorMessage = getMeta('ol-ssoErrorMessage') const cannotUseAi = getMeta('ol-cannot-use-ai') const projectSyncSuccessMessage = getMeta('ol-projectSyncSuccessMessage') // hide linking widgets in CI const integrationLinkingWidgets = getMeta('ol-hideLinkingWidgets') ? [] : availableIntegrationLinkingWidgets const referenceLinkingWidgets = getMeta('ol-hideLinkingWidgets') ? [] : availableReferenceLinkingWidgets const langFeedbackLinkingWidgets = getMeta('ol-hideLinkingWidgets') ? [] : availableLangFeedbackLinkingWidgets const oauth2ServerComponents = importOverleafModules('oauth2Server') as { import: { default: ElementType } path: string }[] const renderSyncSection = getMeta('ol-isSaas') || getMeta('ol-gitBridgeEnabled') const allIntegrationLinkingWidgets = integrationLinkingWidgets.concat( oauth2ServerComponents ) // since we only have Writefull here currently, we should hide the whole section if they cant use ai const haslangFeedbackLinkingWidgets = langFeedbackLinkingWidgets.length && !cannotUseAi const hasIntegrationLinkingSection = renderSyncSection && allIntegrationLinkingWidgets.length const hasReferencesLinkingSection = referenceLinkingWidgets.length // Filter out SSO providers that are not allowed to be linked by // managed users. Allow unlinking them if they are already linked. const hideGoogleSSO = getMeta('ol-cannot-link-google-sso') const hideOtherThirdPartySSO = getMeta('ol-cannot-link-other-third-party-sso') for (const providerId in subscriptions) { const isLinked = subscriptions[providerId].linked if (providerId === 'google') { if (hideGoogleSSO && !isLinked) { delete subscriptions[providerId] } } else { if (hideOtherThirdPartySSO && !isLinked) { delete subscriptions[providerId] } } } const hasSSOLinkingSection = Object.keys(subscriptions).length > 0 if ( !haslangFeedbackLinkingWidgets && !hasIntegrationLinkingSection && !hasReferencesLinkingSection && !hasSSOLinkingSection ) { return null } return ( <>
{t('linked_accounts_explained')}
{haslangFeedbackLinkingWidgets ? ( <>