1
|
import 'antd/dist/antd.css';
|
2
|
import React, { useContext, useEffect, useState } from 'react';
|
3
|
|
4
|
import { useUnauthRedirect } from '../../../hooks';
|
5
|
import { useRouter } from 'next/router';
|
6
|
import { Button, Table, Tag, Typography } from 'antd';
|
7
|
import { faFileLines } from '@fortawesome/free-solid-svg-icons';
|
8
|
import { FontAwesomeIcon } from '@fortawesome/react-fontawesome';
|
9
|
import { LoggedUserContext } from '../../../contexts/LoggedUserContext';
|
10
|
import { MainLayout } from '../../../layouts/MainLayout';
|
11
|
import { userController } from '../../../controllers';
|
12
|
import { AnnotationListInfo } from '../../../api';
|
13
|
|
14
|
function UserDocumentPage() {
|
15
|
const redirecting = useUnauthRedirect('/login');
|
16
|
const { logout, role } = useContext(LoggedUserContext);
|
17
|
const router = useRouter();
|
18
|
const [documents, setDocuments] = useState<AnnotationListInfo[]>([]);
|
19
|
|
20
|
useEffect(() => {
|
21
|
async function fetchData() {
|
22
|
let docs = (await userController.userAnnotationsGet()).data.annotations;
|
23
|
if (!docs) {
|
24
|
setDocuments([]);
|
25
|
} else {
|
26
|
setDocuments(docs);
|
27
|
}
|
28
|
}
|
29
|
if (!redirecting && role === 'ANNOTATOR') {
|
30
|
fetchData();
|
31
|
}
|
32
|
}, [logout, redirecting, role, router]);
|
33
|
|
34
|
const columns = [
|
35
|
{
|
36
|
title: 'Název dokumentu',
|
37
|
dataIndex: 'documentName',
|
38
|
key: 'documentName',
|
39
|
},
|
40
|
{
|
41
|
title: 'Stav anotace',
|
42
|
key: 'state',
|
43
|
dataIndex: 'state',
|
44
|
render: (state: string) => {
|
45
|
let color = 'green';
|
46
|
let label = 'Hotovo';
|
47
|
if (state === 'NEW') {
|
48
|
color = 'volcano';
|
49
|
label = 'Nový';
|
50
|
}
|
51
|
if (state === 'IN_PROGRESS') {
|
52
|
color = 'orange';
|
53
|
label = 'Rozpracováno';
|
54
|
}
|
55
|
return (
|
56
|
<Tag color={color} key={label}>
|
57
|
{label.toUpperCase()}
|
58
|
</Tag>
|
59
|
);
|
60
|
},
|
61
|
},
|
62
|
{
|
63
|
title: '',
|
64
|
key: 'action',
|
65
|
dataIndex: 'annotationId',
|
66
|
render: (anotationId: number) => (
|
67
|
<Button
|
68
|
key={anotationId}
|
69
|
type={'primary'}
|
70
|
onClick={() => router.push('/annotation/' + anotationId)}
|
71
|
>
|
72
|
Anotovat
|
73
|
</Button>
|
74
|
),
|
75
|
},
|
76
|
];
|
77
|
|
78
|
return redirecting || role !== 'ANNOTATOR' ? null : (
|
79
|
<MainLayout>
|
80
|
<Typography.Title level={2}>
|
81
|
<FontAwesomeIcon icon={faFileLines} /> Dokumenty
|
82
|
</Typography.Title>
|
83
|
<Table
|
84
|
columns={columns}
|
85
|
dataSource={documents}
|
86
|
size="small"
|
87
|
scroll={{ y: 500 }}
|
88
|
/>
|
89
|
</MainLayout>
|
90
|
);
|
91
|
}
|
92
|
|
93
|
export default UserDocumentPage;
|