'use client' import type { FC } from 'react' import React, { useCallback, useState } from 'react' import { useTranslation } from 'react-i18next' import { PortalToFollowElem, PortalToFollowElemContent, } from '@/app/components/base/portal-to-follow-elem' import { Lock01 } from '@/app/components/base/icons/src/vender/solid/security' import Button from '@/app/components/base/button' import { DataSourceProvider } from '@/models/common' import Field from '@/app/components/datasets/create/website/base/field' import Toast from '@/app/components/base/toast' import { createDataSourceApiKeyBinding } from '@/service/datasets' import { LinkExternal02 } from '@/app/components/base/icons/src/vender/line/general' type Props = { onCancel: () => void onSaved: () => void } const I18N_PREFIX = 'datasetCreation.jinaReader' const ConfigJinaReaderModal: FC = ({ onCancel, onSaved, }) => { const { t } = useTranslation() const [isSaving, setIsSaving] = useState(false) const [apiKey, setApiKey] = useState('') const handleSave = useCallback(async () => { if (isSaving) return let errorMsg = '' if (!errorMsg) { if (!apiKey) { errorMsg = t('common.errorMsg.fieldRequired', { field: 'API Key', }) } } if (errorMsg) { Toast.notify({ type: 'error', message: errorMsg, }) return } const postData = { category: 'website', provider: DataSourceProvider.jinaReader, credentials: { auth_type: 'bearer', config: { api_key: apiKey, }, }, } try { setIsSaving(true) await createDataSourceApiKeyBinding(postData) Toast.notify({ type: 'success', message: t('common.api.success'), }) } finally { setIsSaving(false) } onSaved() }, [apiKey, onSaved, t, isSaving]) return (
{t(`${I18N_PREFIX}.configJinaReader`)}
setApiKey(value as string)} placeholder={t(`${I18N_PREFIX}.apiKeyPlaceholder`)!} />
{t(`${I18N_PREFIX}.getApiKeyLinkText`)}
{t('common.modelProvider.encrypted.front')} PKCS1_OAEP {t('common.modelProvider.encrypted.back')}
) } export default React.memo(ConfigJinaReaderModal)