add loading for auth modal

pull/12372/head
JzoNg 1 year ago
parent 42cdc55db1
commit a70eda6c45

@ -34,6 +34,7 @@ const ConfigCredential: FC<Props> = ({
const [credentialSchema, setCredentialSchema] = useState<any>(null) const [credentialSchema, setCredentialSchema] = useState<any>(null)
const { name: collectionName } = collection const { name: collectionName } = collection
const [tempCredential, setTempCredential] = React.useState<any>({}) const [tempCredential, setTempCredential] = React.useState<any>({})
const [isLoading, setIsLoading] = React.useState(false)
useEffect(() => { useEffect(() => {
fetchBuiltInToolCredentialSchema(collectionName).then(async (res) => { fetchBuiltInToolCredentialSchema(collectionName).then(async (res) => {
const toolCredentialSchemas = toolCredentialToFormSchemas(res) const toolCredentialSchemas = toolCredentialToFormSchemas(res)
@ -45,14 +46,16 @@ const ConfigCredential: FC<Props> = ({
}) })
}, []) }, [])
const handleSave = () => { const handleSave = async () => {
for (const field of credentialSchema) { for (const field of credentialSchema) {
if (field.required && !tempCredential[field.name]) { if (field.required && !tempCredential[field.name]) {
Toast.notify({ type: 'error', message: t('common.errorMsg.fieldRequired', { field: field.label[language] || field.label.en_US }) }) Toast.notify({ type: 'error', message: t('common.errorMsg.fieldRequired', { field: field.label[language] || field.label.en_US }) })
return return
} }
} }
onSaved(tempCredential) setIsLoading(true)
await onSaved(tempCredential)
setIsLoading(false)
} }
return ( return (
@ -102,7 +105,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={handleSave}>{t('common.operation.save')}</Button> <Button loading={isLoading} disabled={isLoading} variant='primary' onClick={handleSave}>{t('common.operation.save')}</Button>
</div> </div>
</div> </div>
</> </>

Loading…
Cancel
Save