2024-02-05 19:26:03 +08:00
|
|
|
import { IModalManagerChildrenProps } from '@/components/modal-manager';
|
|
|
|
|
import { Form, Input, Modal } from 'antd';
|
2024-04-02 15:44:09 +08:00
|
|
|
import { useTranslation } from 'react-i18next';
|
2024-02-05 19:26:03 +08:00
|
|
|
|
|
|
|
|
type FieldType = {
|
|
|
|
|
name?: string;
|
|
|
|
|
};
|
|
|
|
|
|
2024-07-19 09:07:36 +08:00
|
|
|
interface IProps extends Omit<IModalManagerChildrenProps, 'showModal'> {
|
|
|
|
|
loading: boolean;
|
|
|
|
|
onOk: (name: string) => void;
|
|
|
|
|
}
|
|
|
|
|
|
2024-02-05 19:26:03 +08:00
|
|
|
const KnowledgeCreatingModal = ({
|
|
|
|
|
visible,
|
|
|
|
|
hideModal,
|
2024-07-19 09:07:36 +08:00
|
|
|
loading,
|
|
|
|
|
onOk,
|
|
|
|
|
}: IProps) => {
|
2024-02-05 19:26:03 +08:00
|
|
|
const [form] = Form.useForm();
|
2024-07-19 09:07:36 +08:00
|
|
|
|
2024-04-02 15:44:09 +08:00
|
|
|
const { t } = useTranslation('translation', { keyPrefix: 'knowledgeList' });
|
2024-02-05 19:26:03 +08:00
|
|
|
|
|
|
|
|
const handleOk = async () => {
|
|
|
|
|
const ret = await form.validateFields();
|
2024-07-19 09:07:36 +08:00
|
|
|
onOk(ret.name);
|
2024-02-05 19:26:03 +08:00
|
|
|
};
|
|
|
|
|
|
2025-04-25 18:53:52 +08:00
|
|
|
const handleKeyDown = async (e) => {
|
|
|
|
|
if (e.key === 'Enter') {
|
|
|
|
|
await handleOk();
|
|
|
|
|
}
|
|
|
|
|
};
|
|
|
|
|
|
2024-02-05 19:26:03 +08:00
|
|
|
return (
|
|
|
|
|
<Modal
|
2024-04-02 15:44:09 +08:00
|
|
|
title={t('createKnowledgeBase')}
|
2024-02-05 19:26:03 +08:00
|
|
|
open={visible}
|
|
|
|
|
onOk={handleOk}
|
2024-07-19 09:07:36 +08:00
|
|
|
onCancel={hideModal}
|
2024-02-05 19:26:03 +08:00
|
|
|
okButtonProps={{ loading }}
|
|
|
|
|
>
|
|
|
|
|
<Form
|
|
|
|
|
name="Create"
|
|
|
|
|
labelCol={{ span: 4 }}
|
|
|
|
|
wrapperCol={{ span: 20 }}
|
|
|
|
|
style={{ maxWidth: 600 }}
|
|
|
|
|
autoComplete="off"
|
|
|
|
|
form={form}
|
|
|
|
|
>
|
|
|
|
|
<Form.Item<FieldType>
|
2024-04-02 15:44:09 +08:00
|
|
|
label={t('name')}
|
2024-02-05 19:26:03 +08:00
|
|
|
name="name"
|
2024-04-02 15:44:09 +08:00
|
|
|
rules={[{ required: true, message: t('namePlaceholder') }]}
|
2024-02-05 19:26:03 +08:00
|
|
|
>
|
2025-04-25 18:53:52 +08:00
|
|
|
<Input placeholder={t('namePlaceholder')} onKeyDown={handleKeyDown} />
|
2024-02-05 19:26:03 +08:00
|
|
|
</Form.Item>
|
|
|
|
|
</Form>
|
|
|
|
|
</Modal>
|
|
|
|
|
);
|
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
export default KnowledgeCreatingModal;
|