Updated the Manage.jsx

This commit is contained in:
Mathias Wagner 2023-11-13 20:11:04 +01:00
parent 26aa43cca5
commit 5ff355916a
Signed by: Mathias
GPG Key ID: B8DC354B0A1F5B44

View File

@ -1,19 +1,47 @@
import {Navigate, useOutlet} from "react-router-dom";
import {Navigate, useLocation, useOutlet} from "react-router-dom";
import Header from "@/states/Manage/components/Header";
import {useEffect, useState} from "react";
import pages from "./pages/pages.jsx";
import Sidebar from "@/states/Manage/pages/Sidebar";
import "./styles.sass";
export const getPage = (path) => {
path = path.split("/");
path = path[path.length - 1];
for (const page in pages) {
let pagePath = pages[page].path.split("/");
pagePath = pagePath[pagePath.length - 1];
if (pagePath === path) return pages[page];
}
return {};
}
export const Manage = () => {
const outlet = useOutlet();
const location = useLocation();
const [currentPage, setCurrentPage] = useState({});
useEffect(() => {
setCurrentPage(getPage(location.pathname));
}, [location]);
if (!localStorage.getItem("token")) {
return <Navigate to="/auth"/>;
}
return (
<>
<Header title="Manage"/>
<div className="content-manage">
{Object.keys(currentPage).length !== 0 && <Sidebar/>}
{outlet}
</>
<div className="content-right">
<Header title={currentPage.name}/>
{outlet}
</div>
</div>
);
}