Revize cd2f7b19
Přidáno uživatelem Dominik Poch před téměř 3 roky(ů)
webapp/pages/tags/index.tsx | ||
---|---|---|
1 | 1 |
import 'antd/dist/antd.css'; |
2 |
import React, { useContext, useEffect } from 'react'; |
|
2 |
import React, { useContext, useEffect, useState } from 'react';
|
|
3 | 3 |
|
4 | 4 |
import { useUnauthRedirect } from '../../hooks'; |
5 | 5 |
import { useRouter } from 'next/router'; |
... | ... | |
8 | 8 |
import { faTags } from '@fortawesome/free-solid-svg-icons'; |
9 | 9 |
import { LoggedUserContext } from '../../contexts/LoggedUserContext'; |
10 | 10 |
import { MainLayout } from '../../layouts/MainLayout'; |
11 |
import { Container, Row } from 'react-bootstrap'; |
|
12 |
import { Table } from 'antd'; |
|
13 |
import { tagController } from '../../controllers'; |
|
11 | 14 |
|
12 | 15 |
function TagsPage() { |
13 | 16 |
const redirecting = useUnauthRedirect('/login'); |
14 | 17 |
const { logout, role } = useContext(LoggedUserContext); |
15 | 18 |
const router = useRouter(); |
16 | 19 |
|
20 |
const [tagData, setTagData] = useState<any[] | undefined>([]); |
|
21 |
|
|
17 | 22 |
useEffect(() => { |
18 | 23 |
if (!redirecting && role === 'ADMINISTRATOR') { |
19 |
// TODO load tags |
|
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 |
}); |
|
20 | 57 |
} |
21 | 58 |
}, [logout, redirecting, role, router]); |
22 | 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 |
|
|
23 | 66 |
return redirecting || role !== 'ADMINISTRATOR' ? null : ( |
24 | 67 |
<MainLayout> |
25 |
<Typography.Title level={2}> |
|
26 |
<FontAwesomeIcon icon={faTags} /> Značky |
|
27 |
</Typography.Title> |
|
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> |
|
28 | 82 |
</MainLayout> |
29 | 83 |
); |
30 | 84 |
} |
Také k dispozici: Unified diff
Basic table
Basic table that shows tags