refactoring
This commit is contained in:
@@ -4,23 +4,26 @@ const NavigationTabs = ({ isAdmin, onProtectedNavigate }) => {
|
||||
const location = useLocation();
|
||||
const navigate = useNavigate();
|
||||
|
||||
if (!isAdmin) {
|
||||
return null;
|
||||
}
|
||||
|
||||
const tabs = [
|
||||
{ to: '/', label: 'Konfiguration' },
|
||||
{ to: '/admin', label: 'Admin' }
|
||||
{ to: '/store-watch', label: 'Betriebs-Monitoring' }
|
||||
];
|
||||
if (isAdmin) {
|
||||
tabs.push({ to: '/admin', label: 'Admin' });
|
||||
}
|
||||
|
||||
const handleClick = (event, to) => {
|
||||
event.preventDefault();
|
||||
if (to === location.pathname) {
|
||||
return;
|
||||
}
|
||||
onProtectedNavigate(`zur Seite "${tabs.find((tab) => tab.to === to)?.label || ''}" zu wechseln`, () =>
|
||||
navigate(to)
|
||||
);
|
||||
const label = tabs.find((tab) => tab.to === to)?.label || '';
|
||||
const proceed = () => navigate(to);
|
||||
if (onProtectedNavigate) {
|
||||
onProtectedNavigate(`zur Seite "${label}" zu wechseln`, proceed);
|
||||
return;
|
||||
}
|
||||
proceed();
|
||||
};
|
||||
|
||||
return (
|
||||
|
||||
Reference in New Issue
Block a user