mirror of
https://github.com/langgenius/dify.git
synced 2024-11-16 19:59:50 +08:00
45deaee762
Co-authored-by: Joel <iamjoel007@gmail.com> Co-authored-by: Patryk Garstecki <patryk20120@yahoo.pl> Co-authored-by: Sebastian.W <thiner@gmail.com> Co-authored-by: 呆萌闷油瓶 <253605712@qq.com> Co-authored-by: takatost <takatost@users.noreply.github.com> Co-authored-by: rechardwang <wh_goodjob@163.com> Co-authored-by: Nite Knite <nkCoding@gmail.com> Co-authored-by: Chenhe Gu <guchenhe@gmail.com> Co-authored-by: Joshua <138381132+joshua20231026@users.noreply.github.com> Co-authored-by: Weaxs <459312872@qq.com> Co-authored-by: Ikko Eltociear Ashimine <eltociear@gmail.com> Co-authored-by: leejoo0 <81673835+leejoo0@users.noreply.github.com> Co-authored-by: JzoNg <jzongcode@gmail.com> Co-authored-by: sino <sino2322@gmail.com> Co-authored-by: Vikey Chen <vikeytk@gmail.com> Co-authored-by: wanghl <Wang-HL@users.noreply.github.com> Co-authored-by: Haolin Wang-汪皓临 <haolin.wang@atlaslovestravel.com> Co-authored-by: Zixuan Cheng <61724187+Theysua@users.noreply.github.com> Co-authored-by: crazywoola <100913391+crazywoola@users.noreply.github.com> Co-authored-by: Bowen Liang <bowenliang@apache.org> Co-authored-by: Bowen Liang <liangbowen@gf.com.cn> Co-authored-by: fanghongtai <42790567+fanghongtai@users.noreply.github.com> Co-authored-by: wxfanghongtai <wxfanghongtai@gf.com.cn> Co-authored-by: Matri <qjp@bithuman.io> Co-authored-by: Benjamin <benjaminx@gmail.com>
107 lines
4.1 KiB
TypeScript
107 lines
4.1 KiB
TypeScript
'use client'
|
|
import type { FC } from 'react'
|
|
import React, { useEffect, useState } from 'react'
|
|
import { useTranslation } from 'react-i18next'
|
|
import cn from 'classnames'
|
|
import { addDefaultValue, toolCredentialToFormSchemas } from '../../utils/to-form-schema'
|
|
import type { Collection } from '../../types'
|
|
import Drawer from '@/app/components/base/drawer-plus'
|
|
import Button from '@/app/components/base/button'
|
|
import { fetchBuiltInToolCredential, fetchBuiltInToolCredentialSchema } from '@/service/tools'
|
|
import Loading from '@/app/components/base/loading'
|
|
import Form from '@/app/components/header/account-setting/model-provider-page/model-modal/Form'
|
|
import { LinkExternal02 } from '@/app/components/base/icons/src/vender/line/general'
|
|
|
|
type Props = {
|
|
collection: Collection
|
|
onCancel: () => void
|
|
onSaved: (value: Record<string, any>) => void
|
|
isHideRemoveBtn?: boolean
|
|
onRemove?: () => void
|
|
}
|
|
|
|
const ConfigCredential: FC<Props> = ({
|
|
collection,
|
|
onCancel,
|
|
onSaved,
|
|
isHideRemoveBtn,
|
|
onRemove = () => { },
|
|
}) => {
|
|
const { t } = useTranslation()
|
|
const [credentialSchema, setCredentialSchema] = useState<any>(null)
|
|
const { name: collectionName } = collection
|
|
const [tempCredential, setTempCredential] = React.useState<any>({})
|
|
useEffect(() => {
|
|
fetchBuiltInToolCredentialSchema(collectionName).then(async (res) => {
|
|
const toolCredentialSchemas = toolCredentialToFormSchemas(res)
|
|
const credentialValue = await fetchBuiltInToolCredential(collectionName)
|
|
setTempCredential(credentialValue)
|
|
const defaultCredentials = addDefaultValue(credentialValue, toolCredentialSchemas)
|
|
setCredentialSchema(toolCredentialSchemas)
|
|
setTempCredential(defaultCredentials)
|
|
})
|
|
}, [])
|
|
|
|
return (
|
|
<Drawer
|
|
isShow
|
|
onHide={onCancel}
|
|
title={t('tools.auth.setupModalTitle') as string}
|
|
titleDescription={t('tools.auth.setupModalTitleDescription') as string}
|
|
panelClassName='mt-2 !w-[405px]'
|
|
maxWidthClassName='!max-w-[405px]'
|
|
height='calc(100vh - 16px)'
|
|
contentClassName='!bg-gray-100'
|
|
headerClassName='!border-b-black/5'
|
|
body={
|
|
|
|
<div className='px-6 py-3 h-full'>
|
|
{!credentialSchema
|
|
? <Loading type='app' />
|
|
: (
|
|
<>
|
|
<Form
|
|
value={tempCredential}
|
|
onChange={(v) => {
|
|
setTempCredential(v)
|
|
}}
|
|
formSchemas={credentialSchema}
|
|
isEditMode={true}
|
|
showOnVariableMap={{}}
|
|
validating={false}
|
|
inputClassName='!bg-gray-50'
|
|
fieldMoreInfo={item => item.url
|
|
? (<a
|
|
href={item.url}
|
|
target='_blank' rel='noopener noreferrer'
|
|
className='inline-flex items-center text-xs text-primary-600'
|
|
>
|
|
{t('tools.howToGet')}
|
|
<LinkExternal02 className='ml-1 w-3 h-3' />
|
|
</a>)
|
|
: null}
|
|
/>
|
|
<div className={cn((collection.is_team_authorization && !isHideRemoveBtn) ? 'justify-between' : 'justify-end', 'mt-2 flex ')} >
|
|
{
|
|
(collection.is_team_authorization && !isHideRemoveBtn) && (
|
|
<Button className='flex items-center h-8 !px-3 !text-[13px] font-medium !text-gray-700' onClick={onRemove}>{t('common.operation.remove')}</Button>
|
|
)
|
|
}
|
|
< div className='flex space-x-2'>
|
|
<Button className='flex items-center h-8 !px-3 !text-[13px] font-medium !text-gray-700 bg-white' onClick={onCancel}>{t('common.operation.cancel')}</Button>
|
|
<Button className='flex items-center h-8 !px-3 !text-[13px] font-medium' type='primary' onClick={() => onSaved(tempCredential)}>{t('common.operation.save')}</Button>
|
|
</div>
|
|
</div>
|
|
</>
|
|
)
|
|
}
|
|
|
|
</div >
|
|
}
|
|
isShowMask={true}
|
|
clickOutsideNotOpen={false}
|
|
/>
|
|
)
|
|
}
|
|
export default React.memo(ConfigCredential)
|