2022-12-01 01:28:38 +01:00
|
|
|
import React, {useCallback, useContext} from 'react';
|
2022-11-29 14:17:11 +01:00
|
|
|
import {Link, NavLink} from "react-router-dom";
|
|
|
|
import Icon from "shared/elements/icon";
|
2022-12-01 01:28:38 +01:00
|
|
|
import {LocaleContext} from "shared/locale";
|
2024-04-14 20:31:16 +02:00
|
|
|
import {styled} from "@mui/material";
|
|
|
|
import ProfilePicture from "shared/elements/profile-picture";
|
2024-04-06 11:52:22 +02:00
|
|
|
|
|
|
|
const ProfileLink = styled(Link)((props) => ({
|
|
|
|
"& > div": {
|
|
|
|
padding: 3,
|
|
|
|
width: 30,
|
|
|
|
height: 30,
|
|
|
|
},
|
|
|
|
marginLeft: props.theme.spacing(1),
|
|
|
|
marginTop: props.theme.spacing(1),
|
|
|
|
display: "grid",
|
|
|
|
gridTemplateColumns: "45px auto",
|
|
|
|
"& > span": {
|
|
|
|
alignSelf: "center"
|
|
|
|
}
|
|
|
|
}));
|
2022-11-29 14:17:11 +01:00
|
|
|
|
|
|
|
export default function Sidebar(props) {
|
|
|
|
|
2022-12-01 01:28:38 +01:00
|
|
|
const api = props.api;
|
|
|
|
const showDialog = props.showDialog;
|
|
|
|
const {translate: L} = useContext(LocaleContext);
|
2022-11-29 14:17:11 +01:00
|
|
|
|
2022-12-01 01:28:38 +01:00
|
|
|
const onLogout = useCallback(() => {
|
|
|
|
api.logout().then(obj => {
|
2022-11-29 14:17:11 +01:00
|
|
|
if (obj.success) {
|
|
|
|
document.location = "/admin";
|
|
|
|
} else {
|
2022-12-01 01:28:38 +01:00
|
|
|
showDialog("Error logging out: " + obj.msg, "Error logging out");
|
2022-11-29 14:17:11 +01:00
|
|
|
}
|
|
|
|
});
|
2022-12-01 01:28:38 +01:00
|
|
|
}, [api, showDialog]);
|
2022-11-29 14:17:11 +01:00
|
|
|
|
|
|
|
const menuItems = {
|
|
|
|
"dashboard": {
|
2022-12-01 01:28:38 +01:00
|
|
|
"name": "admin.dashboard",
|
2022-11-29 14:17:11 +01:00
|
|
|
"icon": "tachometer-alt"
|
|
|
|
},
|
|
|
|
"users": {
|
2024-03-27 20:50:57 +01:00
|
|
|
"name": "admin.users",
|
2022-11-29 14:17:11 +01:00
|
|
|
"icon": "users"
|
|
|
|
},
|
2024-03-27 20:50:57 +01:00
|
|
|
"groups": {
|
|
|
|
"name": "admin.groups",
|
|
|
|
"icon": "users-cog"
|
|
|
|
},
|
2024-03-28 11:56:17 +01:00
|
|
|
"routes": {
|
2022-12-01 01:28:38 +01:00
|
|
|
"name": "admin.page_routes",
|
2022-11-29 14:17:11 +01:00
|
|
|
"icon": "copy",
|
|
|
|
},
|
|
|
|
"settings": {
|
2022-12-01 01:28:38 +01:00
|
|
|
"name": "admin.settings",
|
2022-11-29 14:17:11 +01:00
|
|
|
"icon": "tools"
|
|
|
|
},
|
2024-03-29 18:44:31 +01:00
|
|
|
"permissions": {
|
2024-03-27 13:05:37 +01:00
|
|
|
"name": "admin.acl",
|
|
|
|
"icon": "door-open"
|
|
|
|
},
|
2022-11-29 14:17:11 +01:00
|
|
|
"logs": {
|
2022-12-01 01:28:38 +01:00
|
|
|
"name": "admin.logs",
|
2022-11-29 14:17:11 +01:00
|
|
|
"icon": "file-medical-alt"
|
|
|
|
},
|
|
|
|
"help": {
|
2022-12-01 01:28:38 +01:00
|
|
|
"name": "admin.help",
|
2022-11-29 14:17:11 +01:00
|
|
|
"icon": "question-circle"
|
|
|
|
},
|
|
|
|
};
|
|
|
|
|
|
|
|
let li = [];
|
|
|
|
for (let id in menuItems) {
|
|
|
|
let obj = menuItems[id];
|
|
|
|
const badge = (obj.badge ? <span className={"right badge badge-" + obj.badge.type}>{obj.badge.value}</span> : <></>);
|
|
|
|
|
|
|
|
li.push(
|
|
|
|
<li key={id} className={"nav-item"}>
|
2022-12-01 01:28:38 +01:00
|
|
|
<NavLink to={"/admin/" + id} className={"nav-link"}>
|
|
|
|
<Icon icon={obj.icon} className={"nav-icon"} /><p>{L(obj.name)}{badge}</p>
|
2022-11-29 14:17:11 +01:00
|
|
|
</NavLink>
|
|
|
|
</li>
|
|
|
|
);
|
|
|
|
}
|
|
|
|
|
|
|
|
li.push(<li className={"nav-item"} key={"logout"}>
|
|
|
|
<a href={"#"} onClick={() => onLogout()} className={"nav-link"}>
|
|
|
|
<Icon icon={"arrow-left"} className={"nav-icon"} />
|
2022-12-01 01:28:38 +01:00
|
|
|
<p>{L("general.logout")}</p>
|
2022-11-29 14:17:11 +01:00
|
|
|
</a>
|
|
|
|
</li>);
|
|
|
|
|
2024-03-27 13:05:37 +01:00
|
|
|
return <>
|
2022-11-29 14:17:11 +01:00
|
|
|
<aside className={"main-sidebar sidebar-dark-primary elevation-4"}>
|
|
|
|
<Link href={"#"} className={"brand-link"} to={"/admin/dashboard"}>
|
|
|
|
<img src={"/img/icons/logo.png"} alt={"Logo"} className={"brand-image img-circle elevation-3"} style={{opacity: ".8"}} />
|
|
|
|
<span className={"brand-text font-weight-light ml-2"}>WebBase</span>
|
|
|
|
</Link>
|
|
|
|
|
|
|
|
<div className={"sidebar os-host os-theme-light os-host-overflow os-host-overflow-y os-host-resize-disabled os-host-scrollbar-horizontal-hidden os-host-transition"}>
|
|
|
|
{/* IDK what this is */}
|
|
|
|
<div className={"os-resize-observer-host"}>
|
|
|
|
<div className={"os-resize-observer observed"} style={{left: "0px", right: "auto"}}/>
|
|
|
|
</div>
|
|
|
|
<div className={"os-size-auto-observer"} style={{height: "calc(100% + 1px)", float: "left"}}>
|
|
|
|
<div className={"os-resize-observer observed"}/>
|
|
|
|
</div>
|
|
|
|
<div className={"os-content-glue"} style={{margin: "0px -8px"}}/>
|
|
|
|
<div className={"os-padding"}>
|
|
|
|
<div className={"os-viewport os-viewport-native-scrollbars-invisible"} style={{right: "0px", bottom: "0px"}}>
|
|
|
|
<div className={"os-content"} style={{padding: "0px 0px", height: "100%", width: "100%"}}>
|
|
|
|
<div className="user-panel mt-3 pb-3 mb-3 d-flex">
|
|
|
|
<div className="info">
|
2024-04-06 11:52:22 +02:00
|
|
|
<div className={"d-block text-light"}>{L("account.logged_in_as")}:</div>
|
|
|
|
<ProfileLink to={"/admin/profile"}>
|
2024-04-14 20:31:16 +02:00
|
|
|
<ProfilePicture user={api.user} />
|
2024-04-06 11:52:22 +02:00
|
|
|
<span>{api.user?.name || L("account.not_logged_in")}</span>
|
|
|
|
</ProfileLink>
|
2022-11-29 14:17:11 +01:00
|
|
|
</div>
|
|
|
|
</div>
|
|
|
|
<nav className={"mt-2"}>
|
|
|
|
<ul className={"nav nav-pills nav-sidebar flex-column"} data-widget={"treeview"} role={"menu"} data-accordion={"false"}>
|
|
|
|
{li}
|
|
|
|
</ul>
|
|
|
|
</nav>
|
|
|
|
</div>
|
|
|
|
</div>
|
|
|
|
</div>
|
|
|
|
</div>
|
|
|
|
</aside>
|
2024-03-27 13:05:37 +01:00
|
|
|
</>
|
2022-11-29 14:17:11 +01:00
|
|
|
}
|