fix: segment error tip & save segment disable when loading (#949)

This commit is contained in:
zxhlyh
2023-08-22 15:22:16 +08:00
committed by GitHub
parent aee15adf1b
commit 9d5299e9ec
3 changed files with 51 additions and 89 deletions

View File

@@ -31,6 +31,7 @@ const NewSegmentModal: FC<NewSegmentModalProps> = memo(({
const [answer, setAnswer] = useState('')
const { datasetId, documentId } = useParams()
const [keywords, setKeywords] = useState<string[]>([])
const [loading, setLoading] = useState(false)
const handleCancel = () => {
setQuestion('')
@@ -60,10 +61,16 @@ const NewSegmentModal: FC<NewSegmentModalProps> = memo(({
if (keywords?.length)
params.keywords = keywords
await addSegment({ datasetId, documentId, body: params })
notify({ type: 'success', message: t('common.actionMsg.modifiedSuccessfully') })
handleCancel()
onSave()
setLoading(true)
try {
await addSegment({ datasetId, documentId, body: params })
notify({ type: 'success', message: t('common.actionMsg.modifiedSuccessfully') })
handleCancel()
onSave()
}
finally {
setLoading(false)
}
}
const renderContent = () => {
@@ -136,7 +143,9 @@ const NewSegmentModal: FC<NewSegmentModalProps> = memo(({
<Button
type='primary'
className='!h-9 !px-4 !py-2 text-sm font-medium !rounded-lg'
onClick={handleSave}>
onClick={handleSave}
disabled={loading}
>
{t('common.operation.save')}
</Button>
</div>