mirror of
https://github.com/infiniflow/ragflow.git
synced 2025-12-08 20:42:30 +08:00
### What problem does this PR solve? Feat: Display MCP multiple selection bar #3221 ### Type of change - [x] New Feature (non-breaking change which adds functionality)
54 lines
1.2 KiB
TypeScript
54 lines
1.2 KiB
TypeScript
import { useSetModalState } from '@/hooks/common-hooks';
|
|
import {
|
|
useCreateMcpServer,
|
|
useGetMcpServer,
|
|
useUpdateMcpServer,
|
|
} from '@/hooks/use-mcp-request';
|
|
import { useCallback } from 'react';
|
|
|
|
export const useEditMcp = () => {
|
|
const {
|
|
visible: editVisible,
|
|
hideModal: hideEditModal,
|
|
showModal: showEditModal,
|
|
} = useSetModalState();
|
|
const { createMcpServer, loading } = useCreateMcpServer();
|
|
const { data, setId, id } = useGetMcpServer();
|
|
const { updateMcpServer } = useUpdateMcpServer();
|
|
|
|
const handleShowModal = useCallback(
|
|
(id?: string) => () => {
|
|
if (id) {
|
|
setId(id);
|
|
}
|
|
showEditModal();
|
|
},
|
|
[setId, showEditModal],
|
|
);
|
|
|
|
const handleOk = useCallback(
|
|
async (values: any) => {
|
|
let code;
|
|
if (id) {
|
|
code = await updateMcpServer(values);
|
|
} else {
|
|
code = await createMcpServer(values);
|
|
}
|
|
if (code === 0) {
|
|
hideEditModal();
|
|
}
|
|
},
|
|
[createMcpServer, hideEditModal, id, updateMcpServer],
|
|
);
|
|
|
|
return {
|
|
editVisible,
|
|
hideEditModal,
|
|
showEditModal: handleShowModal,
|
|
loading,
|
|
createMcpServer,
|
|
detail: data,
|
|
handleOk,
|
|
};
|
|
};
|