Updated the Manage.jsx
This commit is contained in:
parent
26aa43cca5
commit
5ff355916a
@ -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 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 = () => {
|
export const Manage = () => {
|
||||||
|
|
||||||
const outlet = useOutlet();
|
const outlet = useOutlet();
|
||||||
|
const location = useLocation();
|
||||||
|
|
||||||
|
const [currentPage, setCurrentPage] = useState({});
|
||||||
|
|
||||||
|
useEffect(() => {
|
||||||
|
setCurrentPage(getPage(location.pathname));
|
||||||
|
}, [location]);
|
||||||
|
|
||||||
if (!localStorage.getItem("token")) {
|
if (!localStorage.getItem("token")) {
|
||||||
return <Navigate to="/auth"/>;
|
return <Navigate to="/auth"/>;
|
||||||
}
|
}
|
||||||
|
|
||||||
return (
|
return (
|
||||||
<>
|
<div className="content-manage">
|
||||||
<Header title="Manage"/>
|
{Object.keys(currentPage).length !== 0 && <Sidebar/>}
|
||||||
|
|
||||||
|
<div className="content-right">
|
||||||
|
<Header title={currentPage.name}/>
|
||||||
{outlet}
|
{outlet}
|
||||||
</>
|
</div>
|
||||||
|
</div>
|
||||||
);
|
);
|
||||||
}
|
}
|
Loading…
x
Reference in New Issue
Block a user