You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

index.tsx 2.0KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788
  1. import { useKnowledgeBaseId } from '@/hooks/knowledgeHook';
  2. import { Form, Input, Modal } from 'antd';
  3. import { useEffect } from 'react';
  4. import { useDispatch, useSelector } from 'umi';
  5. const RenameModal = () => {
  6. const [form] = Form.useForm();
  7. const dispatch = useDispatch();
  8. const kFModel = useSelector((state: any) => state.kFModel);
  9. const loading = useSelector(
  10. (state: any) => state.loading.effects['kFModel/document_rename'],
  11. );
  12. const knowledgeBaseId = useKnowledgeBaseId();
  13. const isModalOpen = kFModel.isShowRenameModal;
  14. const initialName = kFModel.currentRecord?.name;
  15. const documentId = kFModel.currentRecord?.id;
  16. type FieldType = {
  17. name?: string;
  18. };
  19. const closeModal = () => {
  20. dispatch({
  21. type: 'kFModel/setIsShowRenameModal',
  22. payload: false,
  23. });
  24. };
  25. const handleOk = async () => {
  26. const ret = await form.validateFields();
  27. dispatch({
  28. type: 'kFModel/document_rename',
  29. payload: {
  30. doc_id: documentId,
  31. name: ret.name,
  32. kb_id: knowledgeBaseId,
  33. },
  34. });
  35. };
  36. const handleCancel = () => {
  37. closeModal();
  38. };
  39. const onFinish = (values: any) => {
  40. console.log('Success:', values);
  41. };
  42. const onFinishFailed = (errorInfo: any) => {
  43. console.log('Failed:', errorInfo);
  44. };
  45. useEffect(() => {
  46. form.setFieldValue('name', initialName);
  47. }, [initialName, documentId, form]);
  48. return (
  49. <Modal
  50. title="Rename"
  51. open={isModalOpen}
  52. onOk={handleOk}
  53. onCancel={handleCancel}
  54. okButtonProps={{ loading }}
  55. >
  56. <Form
  57. name="basic"
  58. labelCol={{ span: 4 }}
  59. wrapperCol={{ span: 20 }}
  60. style={{ maxWidth: 600 }}
  61. onFinish={onFinish}
  62. onFinishFailed={onFinishFailed}
  63. autoComplete="off"
  64. form={form}
  65. >
  66. <Form.Item<FieldType>
  67. label="Name"
  68. name="name"
  69. rules={[{ required: true, message: 'Please input name!' }]}
  70. >
  71. <Input />
  72. </Form.Item>
  73. </Form>
  74. </Modal>
  75. );
  76. };
  77. export default RenameModal;