Feat: Add DatasetCreatingDialog #3221 (#4313)

### What problem does this PR solve?

Feat: Add DatasetCreatingDialog #3221

### Type of change


- [x] New Feature (non-breaking change which adds functionality)
This commit is contained in:
balibabu
2024-12-31 19:17:09 +08:00
committed by GitHub
parent 5071df9de1
commit 061a22588a
15 changed files with 233 additions and 32 deletions

View File

@ -0,0 +1,47 @@
import { KnowledgeRouteKey } from '@/constants/knowledge';
import { useSetModalState } from '@/hooks/common-hooks';
import { useCreateKnowledge } from '@/hooks/knowledge-hooks';
import { useCallback, useState } from 'react';
import { useNavigate } from 'umi';
export const useSearchKnowledge = () => {
const [searchString, setSearchString] = useState<string>('');
const handleInputChange = (e: React.ChangeEvent<HTMLInputElement>) => {
setSearchString(e.target.value);
};
return {
searchString,
handleInputChange,
};
};
export const useSaveKnowledge = () => {
const { visible: visible, hideModal, showModal } = useSetModalState();
const { loading, createKnowledge } = useCreateKnowledge();
const navigate = useNavigate();
const onCreateOk = useCallback(
async (name: string) => {
const ret = await createKnowledge({
name,
});
if (ret?.code === 0) {
hideModal();
navigate(
`/knowledge/${KnowledgeRouteKey.Configuration}?id=${ret.data.kb_id}`,
);
}
},
[createKnowledge, hideModal, navigate],
);
return {
loading,
onCreateOk,
visible,
hideModal,
showModal,
};
};