import type { DataSourceAuth } from './types' import type { AddApiKeyButtonProps, AddOAuthButtonProps, PluginPayload, } from '@/app/components/plugins/plugin-auth/types' import { Button } from '@langgenius/dify-ui/button' import { Popover, PopoverContent, PopoverTrigger } from '@langgenius/dify-ui/popover' import { RiAddLine } from '@remixicon/react' import { memo, useCallback, useMemo, useState } from 'react' import { useTranslation } from 'react-i18next' import { AddApiKeyButton, AddOAuthButton } from '@/app/components/plugins/plugin-auth' type ConfigureProps = { item: DataSourceAuth pluginPayload: PluginPayload onUpdate?: () => void disabled?: boolean } const Configure = ({ item, pluginPayload, onUpdate, disabled }: ConfigureProps) => { const { t } = useTranslation() const [open, setOpen] = useState(false) const canApiKey = item.credential_schema?.length const oAuthData = item.oauth_schema || {} const canOAuth = oAuthData.client_schema?.length const oAuthButtonProps: AddOAuthButtonProps = useMemo(() => { return { buttonText: t(($) => $['auth.addOAuth'], { ns: 'plugin' }), pluginPayload, } }, [pluginPayload, t]) const apiKeyButtonProps: AddApiKeyButtonProps = useMemo(() => { return { pluginPayload, buttonText: t(($) => $['auth.addApi'], { ns: 'plugin' }), } }, [pluginPayload, t]) const handleUpdate = useCallback(() => { setOpen(false) onUpdate?.() }, [onUpdate]) return ( <> {t(($) => $['dataSource.configure'], { ns: 'common' })} } />
{!!canOAuth && ( )} {!!canApiKey && !!canOAuth && (
OR
)} {!!canApiKey && ( )}
) } export default memo(Configure)