Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
122 changes: 95 additions & 27 deletions src/components/layout/SidebarReorganized.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -2,11 +2,38 @@ import React, { useState, useMemo, useEffect, useCallback } from 'react';
import { useQuery } from '@tanstack/react-query';
import { useLocation, useNavigate } from 'react-router-dom';
import {
Package, Users, Heart, GitCompare, FolderOpen, ChevronLeft, ChevronRight,
ShieldCheck, Calculator, Sparkles, FileText, ShoppingCart, Wrench, Zap,
RefreshCw, DollarSign, Plus, Activity, Gauge, Truck, Palette, Brain,
Workflow, Layers, SlidersHorizontal, Boxes, ImagePlus, BarChart3,
Crosshair, Settings, Plug, ChevronsDownUp,
Package,
Users,
Heart,
GitCompare,
FolderOpen,
ChevronLeft,
ChevronRight,
ShieldCheck,
Calculator,
Sparkles,
FileText,
ShoppingCart,
Wrench,
Zap,
RefreshCw,
DollarSign,
Plus,
Activity,
Gauge,
Truck,
Palette,
Brain,
Workflow,
Layers,
SlidersHorizontal,
Boxes,
ImagePlus,
BarChart3,
Crosshair,
Settings,
Plug,
ChevronsDownUp,
} from 'lucide-react';
import { cn } from '@/lib/utils';
import { supabase } from '@/integrations/supabase/client';
Expand All @@ -33,7 +60,14 @@ const navGroups: NavGroup[] = [
defaultOpen: true,
items: [
{ icon: Plus, label: 'Novo Orçamento', href: '/orcamentos/novo', shortcut: 'Alt+N' },
{ icon: FileText, label: 'Orçamentos', href: '/orcamentos', tourId: 'quotes', exact: true, shortcut: 'Alt+O' },
{
icon: FileText,
label: 'Orçamentos',
href: '/orcamentos',
tourId: 'quotes',
exact: true,
shortcut: 'Alt+O',
},
{ icon: ShoppingCart, label: 'Carrinhos', href: '/carrinhos', shortcut: 'Alt+R' },
],
},
Expand Down Expand Up @@ -94,7 +128,10 @@ const navGroups: NavGroup[] = [
{ icon: ShieldCheck, label: 'Acesso & Bots', href: '/admin/seguranca-acesso', devOnly: true },
{ icon: Plug, label: 'Conexões', href: '/admin/conexoes', devOnly: true },
{
icon: FolderOpen, label: 'Cadastros', href: '/admin/cadastros', adminOnly: true,
icon: FolderOpen,
label: 'Cadastros',
href: '/admin/cadastros',
adminOnly: true,
children: [
{ icon: Package, label: 'Produtos', href: '/admin/cadastros?tab=products' },
{ icon: Truck, label: 'Fornecedores', href: '/admin/cadastros?tab=suppliers' },
Expand All @@ -105,7 +142,12 @@ const navGroups: NavGroup[] = [
{ icon: Workflow, label: 'Workflows IA', href: '/admin/workflows', devOnly: true },
{ icon: Activity, label: 'Telemetria', href: '/admin/telemetria', devOnly: true },
{ icon: Gauge, label: 'Performance UX', href: '/admin/client-performance', devOnly: true },
{ icon: DollarSign, label: 'Validade de Preços', href: '/admin/validade-precos', devOnly: true },
{
icon: DollarSign,
label: 'Validade de Preços',
href: '/admin/validade-precos',
devOnly: true,
},
{ icon: ShieldCheck, label: 'Auditoria RBAC', href: '/admin/rbac-rotas', devOnly: true },
{ icon: Activity, label: 'Status do Sistema', href: '/admin/status', devOnly: true },
],
Expand All @@ -120,9 +162,7 @@ const navGroups: NavGroup[] = [
function computeOpenGroups(pathname: string): Record<string, boolean> {
const next: Record<string, boolean> = {};
navGroups.forEach((group) => {
const hasActive = group.items.some((item) =>
isNavItemActive(pathname, item.href, item.exact),
);
const hasActive = group.items.some((item) => isNavItemActive(pathname, item.href, item.exact));
next[group.id] = hasActive || (group.defaultOpen ?? false);
});
return next;
Expand All @@ -138,12 +178,11 @@ export const SidebarReorganized = React.memo(
const [isCollapsed, setIsCollapsed] = useState(false);

useEffect(() => {
document.documentElement.style.setProperty('--sidebar-w',
isCollapsed ? '4rem' : '16rem');
document.documentElement.style.setProperty('--sidebar-w', isCollapsed ? '4rem' : '16rem');
}, [isCollapsed]);

const [openGroups, setOpenGroups] = useState<Record<string, boolean>>(
() => computeOpenGroups(location.pathname),
const [openGroups, setOpenGroups] = useState<Record<string, boolean>>(() =>
computeOpenGroups(location.pathname),
);

const prevPathRef = React.useRef(location.pathname);
Expand All @@ -163,8 +202,8 @@ export const SidebarReorganized = React.memo(
const { data: pendingApprovalCount } = useQuery({
queryKey: ['pending-discount-approvals-count'],
queryFn: async () => {
// rls-allow: admin-only badge query, guarded by `enabled: isAdmin`
const { count } = await supabase
// rls-allow: admin-only badge query, guarded by `enabled: isAdmin`
.from('discount_approval_requests')
.select('*', { count: 'exact', head: true })
.eq('status', 'pending');
Expand Down Expand Up @@ -197,7 +236,9 @@ export const SidebarReorganized = React.memo(
const collapseAllGroups = () => {
setOpenGroups((prev) => {
const collapsed: Record<string, boolean> = {};
Object.keys(prev).forEach((key) => { collapsed[key] = false; });
Object.keys(prev).forEach((key) => {
collapsed[key] = false;
});
return collapsed;
});
};
Expand All @@ -214,9 +255,17 @@ export const SidebarReorganized = React.memo(
const handler = (e: KeyboardEvent) => {
if (e.altKey && !e.ctrlKey && !e.metaKey) {
const target = e.target as HTMLElement;
if (target.tagName === 'INPUT' || target.tagName === 'TEXTAREA' || target.isContentEditable) return;
if (
target.tagName === 'INPUT' ||
target.tagName === 'TEXTAREA' ||
target.isContentEditable
)
return;
const href = shortcutMap[e.key.toLowerCase()];
if (href) { e.preventDefault(); navigate(href); }
if (href) {
e.preventDefault();
navigate(href);
}
}
};
window.addEventListener('keydown', handler);
Expand Down Expand Up @@ -278,20 +327,30 @@ export const SidebarReorganized = React.memo(
'theme-transitioning fixed left-0 top-0 z-50 h-full border-r border-sidebar-border/20 bg-sidebar/80 backdrop-blur-3xl transition-all duration-500',
isCollapsed ? 'overflow-visible' : 'overflow-hidden',
'lg:sticky lg:top-0 lg:z-40 lg:h-screen',
isOpen ? 'translate-x-0 shadow-[40px_0_100px_rgba(0,0,0,0.4)]' : '-translate-x-full lg:translate-x-0',
isCollapsed ? 'w-16 lg:shadow-[20px_0_50px_rgba(0,0,0,0.15)]' : 'w-64 lg:shadow-[30px_0_80px_rgba(0,0,0,0.2)]',
isOpen
? 'translate-x-0 shadow-[40px_0_100px_rgba(0,0,0,0.4)]'
: '-translate-x-full lg:translate-x-0',
isCollapsed
? 'w-16 lg:shadow-[20px_0_50px_rgba(0,0,0,0.15)]'
: 'w-64 lg:shadow-[30px_0_80px_rgba(0,0,0,0.2)]',
)}
>
<FocusTrap active={isOpen && isMobile} className="h-full" autoFocus={false}>
<div className={cn('flex h-full min-h-0 flex-col pt-16 lg:pt-0', isCollapsed && 'overflow-visible')}>
<div
className={cn(
'flex h-full min-h-0 flex-col pt-16 lg:pt-0',
isCollapsed && 'overflow-visible',
)}
>
<div className="group/brand relative border-b border-white/[0.05] bg-gradient-to-b from-white/[0.02] to-transparent">
<SidebarBrandHeader isCollapsed={isCollapsed} />
<div className="pointer-events-none absolute inset-0 rounded-full bg-primary/5 opacity-0 blur-2xl transition-opacity duration-500 group-hover/brand:opacity-100" />
</div>
<div className="mb-3 mt-4 hidden items-center justify-between gap-2 px-3 lg:flex">
{!isCollapsed && (
<Button
variant="ghost" size="sm"
variant="ghost"
size="sm"
className={cn(
'h%8 flex-1 gap-2 text-[10px] font-bold uppercase tracking-wider',
'text-sidebar-foreground/40 hover:bg-primary/10 hover:text-primary',
Expand All @@ -306,7 +365,8 @@ export const SidebarReorganized = React.memo(
</Button>
)}
<Button
variant="ghost" size="icon"
variant="ghost"
size="icon"
className={cn(
'h%8 w-8 shrink-0 text-sidebar-foreground/30 hover:bg-sidebar-accent/50 hover:text-primary',
'rounded-xl transition-all duration-300 focus-visible:ring-1 focus-visible:ring-primary',
Expand All @@ -316,7 +376,11 @@ export const SidebarReorganized = React.memo(
aria-label={isCollapsed ? 'Expandir menu' : 'Recolher menu'}
title={isCollapsed ? 'Expandir menu' : 'Recolher menu'}
>
{isCollapsed ? <ChevronRight className="h-3.5 w-3.5" /> : <ChevronLeft className="h-3.5 w-3.5" />}
{isCollapsed ? (
<ChevronRight className="h-3.5 w-3.5" />
) : (
<ChevronLeft className="h-3.5 w-3.5" />
)}
</Button>
</div>
<RestrictedRouteNotice isCollapsed={isCollapsed} />
Expand All @@ -329,8 +393,12 @@ export const SidebarReorganized = React.memo(
>
{filteredGroups.map((group, index) => (
<div key={group.id}>
{index > 0 && !isCollapsed && <div className="mx-2 my-2.5 h-px bg-sidebar-border/40" />}
{index > 0 && isCollapsed && <div className="mx-auto my-1.5 h-px w-4 bg-sidebar-border/30" />}
{index > 0 && !isCollapsed && (
<div className="mx-2 my-2.5 h-px bg-sidebar-border/40" />
)}
{index > 0 && isCollapsed && (
<div className="mx-auto my-1.5 h-px w-4 bg-sidebar-border/30" />
)}
<SidebarNavGroup
group={group}
isOpen={openGroups[group.id] ?? false}
Expand Down
2 changes: 1 addition & 1 deletion src/pages/tools/CoverageInsightsDashboardPage.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@ const parseDataset = (text: string): CoverageSnapshot[] => {

const getTrend = (values: number[]) => {
if (values.length < 2) return 0;
return Number((values[values.length - 1]! - values[0]).toFixed(1));
return Number((values[values.length - 1] - values[0]).toFixed(1));
};

export default function CoverageInsightsDashboardPage() {
Expand Down
9 changes: 5 additions & 4 deletions src/services/quoteService.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
import { supabase } from '@/integrations/supabase/client';
import type { Json } from '@/integrations/supabase/types';
import {
type Quote,
type QuoteItem,
Expand Down Expand Up @@ -209,10 +210,10 @@ export const quoteService = {
user_id: userId,
action,
description,
field_changed: options?.fieldChanged || null,
old_value: options?.oldValue || null,
new_value: options?.newValue || null,
metadata: options?.metadata || {},
field_changed: typeof options?.fieldChanged === 'string' ? options.fieldChanged : null,
old_value: typeof options?.oldValue === 'string' ? options.oldValue : null,
new_value: typeof options?.newValue === 'string' ? options.newValue : null,
metadata: (options?.metadata ?? {}) as Json,
});
},
};
Loading