mirror of
https://gitee.com/dify_ai/dify.git
synced 2024-12-06 05:08:14 +08:00
fix: tool authorization setting panel not validate required fields (#6387)
This commit is contained in:
parent
279f1c986f
commit
6c798cbdaf
@ -7,11 +7,12 @@ import type { Collection } from '../../types'
|
|||||||
import cn from '@/utils/classnames'
|
import cn from '@/utils/classnames'
|
||||||
import Drawer from '@/app/components/base/drawer-plus'
|
import Drawer from '@/app/components/base/drawer-plus'
|
||||||
import Button from '@/app/components/base/button'
|
import Button from '@/app/components/base/button'
|
||||||
|
import Toast from '@/app/components/base/toast'
|
||||||
import { fetchBuiltInToolCredential, fetchBuiltInToolCredentialSchema } from '@/service/tools'
|
import { fetchBuiltInToolCredential, fetchBuiltInToolCredentialSchema } from '@/service/tools'
|
||||||
import Loading from '@/app/components/base/loading'
|
import Loading from '@/app/components/base/loading'
|
||||||
import Form from '@/app/components/header/account-setting/model-provider-page/model-modal/Form'
|
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'
|
import { LinkExternal02 } from '@/app/components/base/icons/src/vender/line/general'
|
||||||
import { useAppContext } from '@/context/app-context'
|
import { useLanguage } from '@/app/components/header/account-setting/model-provider-page/hooks'
|
||||||
|
|
||||||
type Props = {
|
type Props = {
|
||||||
collection: Collection
|
collection: Collection
|
||||||
@ -29,8 +30,8 @@ const ConfigCredential: FC<Props> = ({
|
|||||||
onRemove = () => { },
|
onRemove = () => { },
|
||||||
}) => {
|
}) => {
|
||||||
const { t } = useTranslation()
|
const { t } = useTranslation()
|
||||||
|
const language = useLanguage()
|
||||||
const [credentialSchema, setCredentialSchema] = useState<any>(null)
|
const [credentialSchema, setCredentialSchema] = useState<any>(null)
|
||||||
const { isCurrentWorkspaceManager } = useAppContext()
|
|
||||||
const { name: collectionName } = collection
|
const { name: collectionName } = collection
|
||||||
const [tempCredential, setTempCredential] = React.useState<any>({})
|
const [tempCredential, setTempCredential] = React.useState<any>({})
|
||||||
useEffect(() => {
|
useEffect(() => {
|
||||||
@ -44,6 +45,16 @@ const ConfigCredential: FC<Props> = ({
|
|||||||
})
|
})
|
||||||
}, [])
|
}, [])
|
||||||
|
|
||||||
|
const handleSave = () => {
|
||||||
|
for (const field of credentialSchema) {
|
||||||
|
if (field.required && !tempCredential[field.name]) {
|
||||||
|
Toast.notify({ type: 'error', message: t('common.errorMsg.fieldRequired', { field: field.label[language] || field.label.en_US }) })
|
||||||
|
return
|
||||||
|
}
|
||||||
|
}
|
||||||
|
onSaved(tempCredential)
|
||||||
|
}
|
||||||
|
|
||||||
return (
|
return (
|
||||||
<Drawer
|
<Drawer
|
||||||
isShow
|
isShow
|
||||||
@ -91,7 +102,7 @@ const ConfigCredential: FC<Props> = ({
|
|||||||
}
|
}
|
||||||
< div className='flex space-x-2'>
|
< div className='flex space-x-2'>
|
||||||
<Button onClick={onCancel}>{t('common.operation.cancel')}</Button>
|
<Button onClick={onCancel}>{t('common.operation.cancel')}</Button>
|
||||||
<Button variant='primary' onClick={() => onSaved(tempCredential)}>{t('common.operation.save')}</Button>
|
<Button variant='primary' onClick={handleSave}>{t('common.operation.save')}</Button>
|
||||||
</div>
|
</div>
|
||||||
</div>
|
</div>
|
||||||
</>
|
</>
|
||||||
|
Loading…
Reference in New Issue
Block a user