|
1 |
| -import { useEffect, useState } from "react"; |
2 |
| -import { useTranslation } from "react-i18next"; |
3 |
| -import TableFilters from "../shared/TableFilters"; |
4 |
| -import Table from "../shared/Table"; |
5 |
| -import { fetchFilters } from "../../slices/tableFilterSlice"; |
6 | 1 | import { themesTemplateMap } from "../../configs/tableConfigs/themesTableMap";
|
7 | 2 | import { getTotalThemes } from "../../selectors/themeSelectors";
|
8 | 3 | import { loadThemesIntoTable } from "../../thunks/tableThunks";
|
9 |
| -import Notifications from "../shared/Notifications"; |
10 |
| -import Header from "../Header"; |
11 |
| -import NavBar from "../NavBar"; |
12 |
| -import MainView from "../MainView"; |
13 |
| -import Footer from "../Footer"; |
14 |
| -import { useAppDispatch, useAppSelector } from "../../store"; |
15 | 4 | import { fetchThemes } from "../../slices/themeSlice";
|
16 |
| -import { resetTableProperties } from "../../slices/tableSlice"; |
| 5 | +import TablePage from "../shared/TablePage"; |
17 | 6 |
|
18 | 7 | /**
|
19 | 8 | * This component renders the table view of events
|
20 | 9 | */
|
21 | 10 | const Themes = () => {
|
22 |
| - const { t } = useTranslation(); |
23 |
| - const dispatch = useAppDispatch(); |
24 |
| - |
25 |
| - const [displayNavigation, setNavigation] = useState(false); |
26 |
| - |
27 |
| - const themes = useAppSelector(state => getTotalThemes(state)); |
28 |
| - |
29 |
| - useEffect(() => { |
30 |
| - // State variable for interrupting the load function |
31 |
| - let allowLoadIntoTable = true; |
32 |
| - |
33 |
| - // Clear table of previous data |
34 |
| - dispatch(resetTableProperties()); |
35 |
| - |
36 |
| - dispatch(fetchFilters("themes")); |
37 |
| - |
38 |
| - // Load themes on mount |
39 |
| - const loadThemes = async () => { |
40 |
| - // Fetching themes from server |
41 |
| - await dispatch(fetchThemes()); |
42 |
| - |
43 |
| - // Load users into table |
44 |
| - if (allowLoadIntoTable) { |
45 |
| - dispatch(loadThemesIntoTable()); |
46 |
| - } |
47 |
| - }; |
48 |
| - loadThemes(); |
49 |
| - |
50 |
| - // Fetch themes every minute |
51 |
| - const fetchThemesInterval = setInterval(loadThemes, 5000); |
52 |
| - |
53 |
| - return () => { |
54 |
| - allowLoadIntoTable = false; |
55 |
| - clearInterval(fetchThemesInterval); |
56 |
| - }; |
57 |
| - // eslint-disable-next-line react-hooks/exhaustive-deps |
58 |
| - }, []); |
59 |
| - |
60 | 11 | return (
|
61 |
| - <> |
62 |
| - <Header /> |
63 |
| - <NavBar |
64 |
| - displayNavigation={displayNavigation} |
65 |
| - setNavigation={setNavigation} |
66 |
| - links={[ |
67 |
| - { |
68 |
| - path: "/configuration/themes", |
69 |
| - accessRole: "ROLE_UI_THEMES_VIEW", |
70 |
| - text: "CONFIGURATION.NAVIGATION.THEMES", |
71 |
| - }, |
72 |
| - ]} |
73 |
| - create={{ |
74 |
| - accessRole: "ROLE_UI_THEMES_CREATE", |
75 |
| - text: "CONFIGURATION.ACTIONS.ADD_THEME", |
76 |
| - resource: "themes", |
77 |
| - }} |
78 |
| - /> |
79 |
| - |
80 |
| - <MainView open={displayNavigation}> |
81 |
| - {/* Include notifications component */} |
82 |
| - <Notifications context={"other"}/> |
83 |
| - |
84 |
| - <div className="controls-container"> |
85 |
| - {/* Include filters component */} |
86 |
| - <TableFilters |
87 |
| - loadResource={fetchThemes} |
88 |
| - loadResourceIntoTable={loadThemesIntoTable} |
89 |
| - resource={"themes"} |
90 |
| - /> |
91 |
| - <h1>{t("CONFIGURATION.THEMES.TABLE.CAPTION")}</h1> |
92 |
| - <h4>{t("TABLE_SUMMARY", { numberOfRows: themes })}</h4> |
93 |
| - </div> |
94 |
| - {/* Include table component */} |
95 |
| - <Table templateMap={themesTemplateMap} /> |
96 |
| - </MainView> |
97 |
| - <Footer /> |
98 |
| - </> |
| 12 | + <TablePage |
| 13 | + resource={"themes"} |
| 14 | + fetchResource={fetchThemes} |
| 15 | + loadResourceIntoTable={loadThemesIntoTable} |
| 16 | + getTotalResources={getTotalThemes} |
| 17 | + navBarLinks={[ |
| 18 | + { |
| 19 | + path: "/configuration/themes", |
| 20 | + accessRole: "ROLE_UI_THEMES_VIEW", |
| 21 | + text: "CONFIGURATION.NAVIGATION.THEMES", |
| 22 | + }, |
| 23 | + ]} |
| 24 | + navBarCreate={{ |
| 25 | + accessRole: "ROLE_UI_THEMES_CREATE", |
| 26 | + text: "CONFIGURATION.ACTIONS.ADD_THEME", |
| 27 | + resource: "themes", |
| 28 | + }} |
| 29 | + caption={"CONFIGURATION.THEMES.TABLE.CAPTION"} |
| 30 | + templateMap={themesTemplateMap} |
| 31 | + /> |
99 | 32 | );
|
100 | 33 | };
|
101 | 34 |
|
|
0 commit comments