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 { Typography } from 'antd';
|
7
|
import { FontAwesomeIcon } from '@fortawesome/react-fontawesome';
|
8
|
import { faTags } from '@fortawesome/free-solid-svg-icons';
|
9
|
import { LoggedUserContext } from '../../contexts/LoggedUserContext';
|
10
|
import { MainLayout } from '../../layouts/MainLayout';
|
11
|
import { Container, Row } from 'react-bootstrap';
|
12
|
import { Table } from 'antd';
|
13
|
import { tagController } from '../../controllers';
|
14
|
|
15
|
function TagsPage() {
|
16
|
const redirecting = useUnauthRedirect('/login');
|
17
|
const { logout, role } = useContext(LoggedUserContext);
|
18
|
const router = useRouter();
|
19
|
|
20
|
const [tagData, setTagData] = useState<any[] | undefined>([]);
|
21
|
|
22
|
useEffect(() => {
|
23
|
if (!redirecting && role === 'ADMINISTRATOR') {
|
24
|
tagController.tagsGet().then((tagTree) => {
|
25
|
if (typeof tagTree.data.tagCategories != 'undefined') {
|
26
|
let data = tagTree.data.tagCategories?.map((catInfo) => {
|
27
|
return {
|
28
|
key: catInfo.id,
|
29
|
name: catInfo.name,
|
30
|
description: catInfo.description,
|
31
|
color: catInfo.color,
|
32
|
...(catInfo.tags?.length && {
|
33
|
children: catInfo.tags?.map((tagInfo) => {
|
34
|
return {
|
35
|
key: tagInfo.id,
|
36
|
name: tagInfo.name,
|
37
|
description: tagInfo.description,
|
38
|
color: tagInfo.color,
|
39
|
...(tagInfo.subTags?.length && {
|
40
|
children: tagInfo.subTags?.map((subInfo) => {
|
41
|
return {
|
42
|
key: subInfo.id,
|
43
|
name: subInfo.name,
|
44
|
description: subInfo.description,
|
45
|
};
|
46
|
}),
|
47
|
}),
|
48
|
};
|
49
|
}),
|
50
|
}),
|
51
|
};
|
52
|
});
|
53
|
|
54
|
setTagData(data);
|
55
|
}
|
56
|
});
|
57
|
}
|
58
|
}, [logout, redirecting, role, router]);
|
59
|
|
60
|
const columns = [
|
61
|
{ title: 'Název', dataIndex: 'name', key: 'name' },
|
62
|
{ title: 'Barva', dataIndex: 'color', key: 'color' },
|
63
|
{ title: 'Popis', dataIndex: 'description', key: 'description' },
|
64
|
];
|
65
|
|
66
|
return redirecting || role !== 'ADMINISTRATOR' ? null : (
|
67
|
<MainLayout>
|
68
|
<Container>
|
69
|
<Row>
|
70
|
<Typography.Title level={2}>
|
71
|
<FontAwesomeIcon icon={faTags} /> Značky
|
72
|
</Typography.Title>
|
73
|
</Row>
|
74
|
<Row>
|
75
|
<Table
|
76
|
columns={columns}
|
77
|
dataSource={tagData}
|
78
|
scroll={{ y: 'calc(100vh - 300px)' }}
|
79
|
/>
|
80
|
</Row>
|
81
|
</Container>
|
82
|
</MainLayout>
|
83
|
);
|
84
|
}
|
85
|
|
86
|
export default TagsPage;
|