File size: 1,626 Bytes
68ed806 1660911 40a88fa e08f767 15052fd bd39551 40a88fa bd39551 7c6cf75 bd39551 40a88fa 1660911 7c6cf75 40a88fa 15052fd 40a88fa bd39551 40a88fa bd39551 bb69456 bd39551 40a88fa 7c6cf75 40a88fa 7c6cf75 40a88fa bd39551 40a88fa 15052fd 40a88fa 7c6cf75 40a88fa 15052fd 40a88fa |
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 |
import { useTranslate } from '@/hooks/common-hooks';
import { useFetchKnowledgeList } from '@/hooks/knowledge-hooks';
import { IModalProps } from '@/interfaces/common';
import { filterOptionsByInput } from '@/utils/common-util';
import { Form, Modal, Select } from 'antd';
import { useEffect } from 'react';
const ConnectToKnowledgeModal = ({
visible,
hideModal,
onOk,
initialValue,
loading,
}: IModalProps<string[]> & { initialValue: string[] }) => {
const [form] = Form.useForm();
const { list } = useFetchKnowledgeList();
const { t } = useTranslate('fileManager');
const options = list?.map((item) => ({
label: item.name,
value: item.id,
}));
const handleOk = async () => {
const values = await form.getFieldsValue();
const knowledgeIds = values.knowledgeIds ?? [];
return onOk?.(knowledgeIds);
};
useEffect(() => {
if (visible) {
form.setFieldValue('knowledgeIds', initialValue);
}
}, [visible, initialValue, form]);
return (
<Modal
title={t('addToKnowledge')}
open={visible}
onOk={handleOk}
onCancel={hideModal}
confirmLoading={loading}
>
<Form form={form}>
<Form.Item name="knowledgeIds" noStyle>
<Select
mode="multiple"
allowClear
showSearch
style={{ width: '100%' }}
placeholder={t('pleaseSelect')}
options={options}
optionFilterProp="children"
filterOption={filterOptionsByInput}
/>
</Form.Item>
</Form>
</Modal>
);
};
export default ConnectToKnowledgeModal;
|