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
|
|
30
|
if (!redirecting /* && role === 'ANNOTATOR'*/) {
|
31
|
// admin can also fetch data if he likes so
|
32
|
fetchData();
|
33
|
}
|
34
|
}, [logout, redirecting, role, router]);
|
35
|
|
36
|
const columns = [
|
37
|
{
|
38
|
title: 'Název dokumentu',
|
39
|
dataIndex: 'documentName',
|
40
|
key: 'documentName',
|
41
|
},
|
42
|
{
|
43
|
title: 'Stav anotace',
|
44
|
key: 'state',
|
45
|
dataIndex: 'state',
|
46
|
render: (state: string) => {
|
47
|
let color = 'green';
|
48
|
let label = 'Hotovo';
|
49
|
if (state === 'NEW') {
|
50
|
color = 'volcano';
|
51
|
label = 'Nový';
|
52
|
}
|
53
|
if (state === 'IN_PROGRESS') {
|
54
|
color = 'orange';
|
55
|
label = 'Rozpracováno';
|
56
|
}
|
57
|
return (
|
58
|
<Tag color={color} key={label}>
|
59
|
{label.toUpperCase()}
|
60
|
</Tag>
|
61
|
);
|
62
|
},
|
63
|
},
|
64
|
{
|
65
|
title: '',
|
66
|
key: 'action',
|
67
|
dataIndex: 'annotationId',
|
68
|
render: (anotationId: number) => (
|
69
|
<Button
|
70
|
key={anotationId}
|
71
|
type={'primary'}
|
72
|
onClick={() => router.push('/annotation/' + anotationId)}
|
73
|
>
|
74
|
Anotovat
|
75
|
</Button>
|
76
|
),
|
77
|
},
|
78
|
];
|
79
|
|
80
|
return redirecting /*|| role !== 'ANNOTATOR' */ ? null : (
|
81
|
<MainLayout>
|
82
|
<Typography.Title level={2}>
|
83
|
<FontAwesomeIcon icon={faFileLines} /> Dokumenty
|
84
|
</Typography.Title>
|
85
|
<Table
|
86
|
columns={columns}
|
87
|
dataSource={documents}
|
88
|
size="small"
|
89
|
scroll={{ y: 500 }}
|
90
|
/>
|
91
|
</MainLayout>
|
92
|
);
|
93
|
}
|
94
|
|
95
|
export default UserDocumentPage;
|