import { memo, useMemo, } from 'react' import { RiAddLine, } from '@remixicon/react' import { useTranslation } from 'react-i18next' import { PortalToFollowElem, PortalToFollowElemContent, PortalToFollowElemTrigger, } from '@/app/components/base/portal-to-follow-elem' import Button from '@/app/components/base/button' import { AddApiKeyButton, AddOAuthButton, } from '@/app/components/plugins/plugin-auth' import type { DataSourceAuth } from './types' import type { AddApiKeyButtonProps, AddOAuthButtonProps, PluginPayload, } from '@/app/components/plugins/plugin-auth/types' type ConfigureProps = { item: DataSourceAuth pluginPayload: PluginPayload onUpdate?: () => void disabled?: boolean } const Configure = ({ item, pluginPayload, onUpdate, disabled, }: ConfigureProps) => { const { t } = useTranslation() const canApiKey = item.credential_schema?.length const oAuthData = item.oauth_schema || {} const canOAuth = oAuthData.client_schema?.length const oAuthButtonProps: AddOAuthButtonProps = useMemo(() => { return { buttonText: t('plugin.auth.addOAuth'), pluginPayload, } }, [pluginPayload, t]) const apiKeyButtonProps: AddApiKeyButtonProps = useMemo(() => { return { pluginPayload, buttonText: t('plugin.auth.addApi'), } }, [pluginPayload, t]) return ( <>
{ canOAuth && ( ) } { canApiKey && canOAuth && (
OR
) } { canApiKey && ( ) }
) } export default memo(Configure)