1
|
import { Button, Form, Input, Modal } from 'antd';
|
2
|
import 'antd/dist/antd.css';
|
3
|
import React from 'react';
|
4
|
import { SetRequiredAnnotationsRequest } from '../../api';
|
5
|
import { documentController } from '../../controllers';
|
6
|
import { ShowToast } from '../../utils/alerts';
|
7
|
|
8
|
interface ModalProps {
|
9
|
onCancel: () => void;
|
10
|
documentsIds: string[];
|
11
|
}
|
12
|
|
13
|
function SetRequiredAnnotationsCountModal({ onCancel, documentsIds }: ModalProps) {
|
14
|
const handleOk = () => {
|
15
|
onCancel();
|
16
|
};
|
17
|
|
18
|
const handleCancel = () => {
|
19
|
onCancel();
|
20
|
};
|
21
|
|
22
|
const onFinish = async (values: any) => {
|
23
|
if (documentsIds && documentsIds.length !== 0) {
|
24
|
const req: SetRequiredAnnotationsRequest = {
|
25
|
requiredAnnotations: values.annotationsCount,
|
26
|
documentIds: documentsIds,
|
27
|
};
|
28
|
|
29
|
await documentController.documentsRequiredAnnotationsPost(req);
|
30
|
|
31
|
ShowToast(
|
32
|
'Požadovaný počet anotací úspěšně nastaven',
|
33
|
'success',
|
34
|
3000,
|
35
|
'top-end'
|
36
|
);
|
37
|
}
|
38
|
|
39
|
handleOk();
|
40
|
};
|
41
|
|
42
|
const onFinishFailed = (errorInfo: any) => {
|
43
|
ShowToast('Zadané údaje nejsou validní', 'error', 3000, 'top-end');
|
44
|
};
|
45
|
|
46
|
return (
|
47
|
<Modal
|
48
|
title={'Nastavit požadovaný počet anotací'}
|
49
|
onOk={handleOk}
|
50
|
visible={true}
|
51
|
onCancel={handleCancel}
|
52
|
footer={null}
|
53
|
width={400}
|
54
|
centered
|
55
|
>
|
56
|
<Form
|
57
|
onFinish={onFinish}
|
58
|
onFinishFailed={onFinishFailed}
|
59
|
autoComplete="off"
|
60
|
labelCol={{ span: 4 }}
|
61
|
layout="horizontal"
|
62
|
>
|
63
|
Požadovaný počet anotací:
|
64
|
<Form.Item
|
65
|
name="annotationsCount"
|
66
|
rules={[
|
67
|
{
|
68
|
required: true,
|
69
|
message: 'Zadejte počet anotací',
|
70
|
},
|
71
|
]}
|
72
|
>
|
73
|
<Input placeholder="Počet anotací" />
|
74
|
</Form.Item>
|
75
|
<Form.Item>
|
76
|
<Button type="primary" htmlType="submit" className="w-100">
|
77
|
Změnit
|
78
|
</Button>
|
79
|
</Form.Item>
|
80
|
</Form>
|
81
|
</Modal>
|
82
|
);
|
83
|
}
|
84
|
|
85
|
export default SetRequiredAnnotationsCountModal;
|