Add super admin user management
All checks were successful
Build and Deploy / build-and-deploy (push) Successful in 2m46s

This commit is contained in:
Cauê Faleiros
2026-06-16 15:46:04 -03:00
parent f811d3c0ab
commit c8d475808b
12 changed files with 1126 additions and 34 deletions

View File

@@ -1,8 +1,8 @@
import { useCallback, useState, useEffect } from 'react';
import { Outlet, Link, useLocation } from 'react-router-dom';
import { LayoutDashboard, Users, BarChart3, ChevronLeft, ChevronRight, Package, Loader2, LogOut, Megaphone, Grid3X3 } from 'lucide-react';
import { LayoutDashboard, Users, BarChart3, ChevronLeft, ChevronRight, Package, Loader2, LogOut, Megaphone, Grid3X3, Shield } from 'lucide-react';
import type { DateRange, OrderData, StockData } from '../types';
import { fetchData, fetchStock, logout } from '../dataService';
import { fetchData, fetchStock, isSuperAdmin, logout } from '../dataService';
import { rangeForLastDays } from '../dateRanges';
const Layout = () => {
@@ -78,13 +78,20 @@ const Layout = () => {
localStorage.setItem('graph_sidebar_collapsed', String(newState));
};
const navigation = [
const appNavigation = [
{ name: 'Dashboard', href: '/graph', icon: LayoutDashboard },
{ name: 'Produtos', href: '/products', icon: Package },
{ name: 'Clientes', href: '/clients', icon: Users },
{ name: 'RFV', href: '/rfm', icon: Grid3X3 },
{ name: 'Campanhas', href: '/campaigns', icon: Megaphone },
];
const adminNavigation = isSuperAdmin()
? [{ name: 'Usuários', href: '/admin/users', icon: Shield }]
: [];
const navigationSections = [
{ label: 'Painel', items: appNavigation },
...(adminNavigation.length ? [{ label: 'Super admin', items: adminNavigation }] : []),
];
return (
<div className="flex h-screen bg-dark-bg text-dark-text overflow-hidden">
@@ -112,24 +119,36 @@ const Layout = () => {
</div>
)}
<nav className="flex-1 p-4 space-y-2 overflow-y-auto">
{navigation.map((item) => {
const isActive = location.pathname === item.href || (item.href !== '/graph' && location.pathname.startsWith(item.href));
return (
<Link
key={item.name}
to={item.href}
className={`flex items-center space-x-3 px-4 py-3 rounded-xl transition-all ${
isActive
? 'bg-brand-primary/10 text-brand-primary font-semibold shadow-md shadow-brand-primary/5'
: 'text-dark-muted hover:bg-dark-card hover:text-dark-text'
}`}
>
<item.icon className="w-5 h-5 shrink-0" />
{!isSidebarCollapsed && <span className="font-medium">{item.name}</span>}
</Link>
);
})}
<nav className="flex-1 space-y-6 overflow-y-auto p-4">
{navigationSections.map((section) => (
<div key={section.label} className="space-y-2">
{!isSidebarCollapsed && (
<div className="px-3 text-xs font-bold uppercase tracking-widest text-dark-muted">
{section.label}
</div>
)}
{section.items.map((item) => {
const isActive = location.pathname === item.href || (item.href !== '/graph' && location.pathname.startsWith(item.href));
return (
<Link
key={item.name}
to={item.href}
className={`flex items-center rounded-xl px-4 py-3 transition-all ${
isSidebarCollapsed ? 'justify-center' : 'space-x-3'
} ${
isActive
? 'bg-brand-primary/10 text-brand-primary font-semibold shadow-md shadow-brand-primary/5'
: 'text-dark-muted hover:bg-dark-card hover:text-dark-text'
}`}
title={isSidebarCollapsed ? item.name : undefined}
>
<item.icon className="h-5 w-5 shrink-0" />
{!isSidebarCollapsed && <span className="font-medium">{item.name}</span>}
</Link>
);
})}
</div>
))}
</nav>
<div className="p-4 border-t border-dark-border">