1
|
import { List, Modal } from 'antd';
|
2
|
import 'antd/dist/antd.css';
|
3
|
import React, { useContext, useEffect, useState } from 'react';
|
4
|
import { AnnotationListInfo } from '../../api';
|
5
|
import { userController } from '../../controllers';
|
6
|
import { useUnauthRedirect } from '../../hooks';
|
7
|
import { LoggedUserContext } from '../../contexts/LoggedUserContext';
|
8
|
|
9
|
interface ModalProps {
|
10
|
onCancel: () => void;
|
11
|
userId: string | undefined;
|
12
|
}
|
13
|
|
14
|
function UserDocumentsModal({ onCancel, userId }: ModalProps) {
|
15
|
const redirecting = useUnauthRedirect('/login');
|
16
|
const { role } = useContext(LoggedUserContext);
|
17
|
const [annotations, setAnnotations] = useState<AnnotationListInfo[]>([]);
|
18
|
|
19
|
const handleOk = () => {
|
20
|
onCancel();
|
21
|
};
|
22
|
|
23
|
const handleCancel = () => {
|
24
|
onCancel();
|
25
|
};
|
26
|
|
27
|
useEffect(() => {
|
28
|
if (!redirecting && role === 'ADMINISTRATOR' && userId) {
|
29
|
userController
|
30
|
.userUserIdAnnotationsGet(userId)
|
31
|
.then(({ data: { annotations } }) => {
|
32
|
setAnnotations(annotations || []);
|
33
|
});
|
34
|
}
|
35
|
}, [userId, redirecting, role]);
|
36
|
|
37
|
return (
|
38
|
<Modal
|
39
|
title="Dokumenty uživatele"
|
40
|
onOk={handleOk}
|
41
|
visible={true}
|
42
|
onCancel={handleCancel}
|
43
|
footer={[null]}
|
44
|
>
|
45
|
<List
|
46
|
dataSource={annotations}
|
47
|
size={'small'}
|
48
|
grid={{ gutter: 10, column: 1 }}
|
49
|
style={{ maxHeight: 400, overflowY: 'auto', overflowX: 'hidden' }}
|
50
|
renderItem={(item) => (
|
51
|
<List.Item key={item.annotationId}>
|
52
|
<List.Item.Meta title={item.documentName} />
|
53
|
</List.Item>
|
54
|
)}
|
55
|
/>
|
56
|
</Modal>
|
57
|
);
|
58
|
}
|
59
|
|
60
|
export default UserDocumentsModal;
|