Projekt

Obecné

Profil

Stáhnout (2.89 KB) Statistiky
| Větev: | Tag: | Revize:
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, EState } from '../../../api';
13
import {
14
    getAnnotationStateString,
15
    getAnnotationStateColor,
16
} from '../../../utils/strings';
17

    
18
function UserDocumentPage() {
19
    const redirecting = useUnauthRedirect('/login');
20
    const { logout, role } = useContext(LoggedUserContext);
21
    const router = useRouter();
22
    const [documents, setDocuments] = useState<AnnotationListInfo[]>([]);
23

    
24
    useEffect(() => {
25
        async function fetchData() {
26
            let docs = (await userController.userAnnotationsGet()).data.annotations;
27
            if (!docs) {
28
                setDocuments([]);
29
            } else {
30
                setDocuments(docs);
31
            }
32
        }
33

    
34
        if (!redirecting /* && role === 'ANNOTATOR'*/) {
35
            // admin can also fetch data if he likes so
36
            fetchData();
37
        }
38
    }, [logout, redirecting, role, router]);
39

    
40
    const columns = [
41
        {
42
            title: 'Název dokumentu',
43
            dataIndex: 'documentName',
44
            key: 'documentName',
45
        },
46
        {
47
            title: 'Stav anotace',
48
            key: 'state',
49
            dataIndex: 'state',
50
            render: (state: EState) => {
51
                const color = getAnnotationStateColor(state);
52
                const label = getAnnotationStateString(state);
53

    
54
                return (
55
                    <Tag color={color} key={label}>
56
                        {label.toUpperCase()}
57
                    </Tag>
58
                );
59
            },
60
        },
61
        {
62
            title: '',
63
            key: 'action',
64
            dataIndex: 'annotationId',
65
            render: (anotationId: number) => (
66
                <Button
67
                    key={anotationId}
68
                    type={'primary'}
69
                    onClick={() => router.push('/annotation/' + anotationId)}
70
                >
71
                    Anotovat
72
                </Button>
73
            ),
74
        },
75
    ];
76

    
77
    return redirecting /*|| role !== 'ANNOTATOR' */ ? null : (
78
        <MainLayout>
79
            <Typography.Title level={2}>
80
                <FontAwesomeIcon icon={faFileLines} /> Dokumenty
81
            </Typography.Title>
82
            <Table
83
                columns={columns}
84
                dataSource={documents}
85
                size="small"
86
                scroll={{ y: 500 }}
87
            />
88
        </MainLayout>
89
    );
90
}
91

    
92
export default UserDocumentPage;
    (1-1/1)