1
|
import { Button, Checkbox, List, Modal } from 'antd';
|
2
|
import 'antd/dist/antd.css';
|
3
|
import React, { useContext, useEffect, useState } from 'react';
|
4
|
import { UserInfo } from '../../api';
|
5
|
import { annotationController, userController } from '../../controllers';
|
6
|
import { useUnauthRedirect } from '../../hooks';
|
7
|
import { LoggedUserContext } from '../../contexts/LoggedUserContext';
|
8
|
|
9
|
interface ModalProps {
|
10
|
onCancel: () => void;
|
11
|
documentsIds: (string | undefined)[];
|
12
|
}
|
13
|
|
14
|
function AssignDocumentModal({ onCancel, documentsIds }: ModalProps) {
|
15
|
const redirecting = useUnauthRedirect('/login');
|
16
|
const { role } = useContext(LoggedUserContext);
|
17
|
const [users, setUsers] = useState<UserInfo[]>([]);
|
18
|
const [selectedUsers, setSelectedUsers] = useState<string[]>([]);
|
19
|
|
20
|
const handleOk = () => {
|
21
|
onCancel();
|
22
|
};
|
23
|
|
24
|
const handleCancel = () => {
|
25
|
onCancel();
|
26
|
};
|
27
|
|
28
|
useEffect(() => {
|
29
|
console.log(documentsIds);
|
30
|
if (!redirecting && role === 'ADMINISTRATOR') {
|
31
|
userController.usersGet().then(({ data: { users } }) => {
|
32
|
setUsers(users || []);
|
33
|
});
|
34
|
}
|
35
|
}, [documentsIds, redirecting, role]);
|
36
|
|
37
|
const handleUpload = async () => {
|
38
|
// console.log(documentsIds, selectedUsers);
|
39
|
if (documentsIds && documentsIds.length !== 0) {
|
40
|
await annotationController.annotationsPost({
|
41
|
// @ts-ignore
|
42
|
documentIdList: documentsIds,
|
43
|
userIdList: selectedUsers,
|
44
|
});
|
45
|
}
|
46
|
onCancel();
|
47
|
};
|
48
|
|
49
|
function onChange(event: any) {
|
50
|
if (event.target.checked) {
|
51
|
selectedUsers.push(event.target.value);
|
52
|
} else {
|
53
|
setSelectedUsers(selectedUsers.filter((usr) => usr !== event.target.value));
|
54
|
}
|
55
|
}
|
56
|
|
57
|
return (
|
58
|
<Modal
|
59
|
title="Přiřadit dokumenty"
|
60
|
onOk={handleOk}
|
61
|
visible={true}
|
62
|
onCancel={handleCancel}
|
63
|
footer={[
|
64
|
<Button key="back" onClick={handleCancel}>
|
65
|
Storno
|
66
|
</Button>,
|
67
|
<Button key="submit" type="primary" onClick={handleUpload}>
|
68
|
Přiřadit
|
69
|
</Button>,
|
70
|
]}
|
71
|
>
|
72
|
<List
|
73
|
dataSource={users}
|
74
|
size={'small'}
|
75
|
grid={{ gutter: 10, column: 1 }}
|
76
|
style={{ maxHeight: 400, overflowY: 'auto', overflowX: 'hidden' }}
|
77
|
renderItem={(item) => (
|
78
|
<List.Item key={item.id}>
|
79
|
<List.Item.Meta
|
80
|
title={
|
81
|
<Checkbox onChange={onChange} value={item.id}>
|
82
|
{item.name + ' ' + item.surname}
|
83
|
</Checkbox>
|
84
|
}
|
85
|
/>
|
86
|
</List.Item>
|
87
|
)}
|
88
|
/>
|
89
|
</Modal>
|
90
|
);
|
91
|
}
|
92
|
|
93
|
export default AssignDocumentModal;
|