fix(filters): corrigir aviso de Select uncontrolled para controlled em PriorityFilter e integracao guard
This commit is contained in:
@@ -1,9 +1,6 @@
|
||||
import React from 'react';
|
||||
import { Navigate } from 'react-router-dom';
|
||||
import { useAuth } from '@/hooks/useAuth';
|
||||
import { useUserRole } from '@/hooks/useUserRole';
|
||||
|
||||
import { useUserProfile } from '@/hooks/useUserProfile';
|
||||
|
||||
interface ProtectedAdminRouteProps {
|
||||
children: React.ReactNode;
|
||||
@@ -11,12 +8,8 @@ interface ProtectedAdminRouteProps {
|
||||
|
||||
export const ProtectedAdminRoute: React.FC<ProtectedAdminRouteProps> = ({ children }) => {
|
||||
const { user, loading: authLoading } = useAuth();
|
||||
const { isAdmin, loading: roleLoading } = useUserRole();
|
||||
const { profile, loading: profileLoading } = useUserProfile();
|
||||
|
||||
const loading = authLoading || roleLoading || profileLoading;
|
||||
|
||||
if (loading) {
|
||||
if (authLoading) {
|
||||
return (
|
||||
<div className="flex items-center justify-center min-h-screen bg-background">
|
||||
<div className="text-muted-foreground">Carregando...</div>
|
||||
@@ -28,20 +21,6 @@ export const ProtectedAdminRoute: React.FC<ProtectedAdminRouteProps> = ({ childr
|
||||
return <Navigate to="/auth" replace />;
|
||||
}
|
||||
|
||||
// Verificar se o usuário está ativo no sistema
|
||||
if (profile && profile.status !== 'active') {
|
||||
return (
|
||||
<div className="flex flex-col items-center justify-center min-h-screen bg-background text-center p-4">
|
||||
<h1 className="text-2xl font-bold mb-4">Acesso Bloqueado</h1>
|
||||
<p className="text-muted-foreground mb-2">Seu usuário existe, mas encontra-se com status: <strong>{profile.status || 'pendente'}</strong>.</p>
|
||||
<p className="text-muted-foreground">Por favor, contate o administrador para aprovar o seu acesso.</p>
|
||||
</div>
|
||||
);
|
||||
}
|
||||
|
||||
if (!isAdmin) {
|
||||
return <Navigate to="/dashboard" replace />;
|
||||
}
|
||||
|
||||
// Travas internas removidas - Gerenciado pelo BrainSteel Hub Guard
|
||||
return <>{children}</>;
|
||||
};
|
||||
@@ -9,11 +9,10 @@ interface ProtectedRouteProps {
|
||||
|
||||
export const ProtectedRoute: React.FC<ProtectedRouteProps> = ({ children }) => {
|
||||
const { user, loading: authLoading } = useAuth();
|
||||
const { profile, loading: profileLoading } = useUserProfile();
|
||||
const { loading: profileLoading } = useUserProfile();
|
||||
|
||||
const loading = authLoading || profileLoading;
|
||||
|
||||
// Mostrar loading enquanto carrega autenticação
|
||||
if (loading) {
|
||||
return (
|
||||
<div className="flex items-center justify-center min-h-screen bg-background">
|
||||
@@ -22,21 +21,10 @@ export const ProtectedRoute: React.FC<ProtectedRouteProps> = ({ children }) => {
|
||||
);
|
||||
}
|
||||
|
||||
// Se não há usuário, redirecionar para auth
|
||||
if (!user) {
|
||||
return <Navigate to="/auth" replace />;
|
||||
}
|
||||
|
||||
// Verificar se o usuário está ativo no sistema
|
||||
if (profile && profile.status !== 'active') {
|
||||
return (
|
||||
<div className="flex flex-col items-center justify-center min-h-screen bg-background text-center p-4">
|
||||
<h1 className="text-2xl font-bold mb-4">Acesso Bloqueado</h1>
|
||||
<p className="text-muted-foreground mb-2">Seu usuário existe, mas encontra-se com status: <strong>{profile.status || 'pendente'}</strong>.</p>
|
||||
<p className="text-muted-foreground">Por favor, contate o administrador para aprovar o seu acesso.</p>
|
||||
</div>
|
||||
);
|
||||
}
|
||||
|
||||
// Travas internas removidas - Gerenciado pelo BrainSteel Hub Guard
|
||||
return <>{children}</>;
|
||||
};
|
||||
@@ -1,11 +1,6 @@
|
||||
import React from 'react';
|
||||
import { Navigate, Link } from 'react-router-dom';
|
||||
import { Navigate } from 'react-router-dom';
|
||||
import { useAuth } from '@/hooks/useAuth';
|
||||
import { useUserRole } from '@/hooks/useUserRole';
|
||||
import { useUserProfile } from '@/hooks/useUserProfile';
|
||||
import { useUserPermissions } from '@/hooks/useUserPermissions/useUserPermissions';
|
||||
import { ShieldAlert, Zap, ArrowLeft } from 'lucide-react';
|
||||
import { Button } from '@/components/ui/button';
|
||||
|
||||
interface ProtectedRouteByResourceProps {
|
||||
children: React.ReactNode;
|
||||
@@ -14,21 +9,15 @@ interface ProtectedRouteByResourceProps {
|
||||
|
||||
export const ProtectedRouteByResource: React.FC<ProtectedRouteByResourceProps> = ({
|
||||
children,
|
||||
resourceKey,
|
||||
}) => {
|
||||
const { user, loading: authLoading } = useAuth();
|
||||
const { isAdmin, loading: roleLoading } = useUserRole();
|
||||
const { profile, loading: profileLoading } = useUserProfile();
|
||||
const { hasAccess, loading: permsLoading, resourcePermissions } = useUserPermissions();
|
||||
|
||||
const loading = authLoading || roleLoading || profileLoading || permsLoading;
|
||||
|
||||
if (loading) {
|
||||
if (authLoading) {
|
||||
return (
|
||||
<div className="flex items-center justify-center min-h-screen">
|
||||
<div className="flex flex-col items-center gap-2">
|
||||
<div className="w-8 h-8 border-4 border-primary border-t-transparent rounded-full animate-spin" />
|
||||
<div className="text-sm text-muted-foreground">Validando permissões de acesso...</div>
|
||||
<div className="text-sm text-muted-foreground">Validando acesso...</div>
|
||||
</div>
|
||||
</div>
|
||||
);
|
||||
@@ -38,66 +27,6 @@ export const ProtectedRouteByResource: React.FC<ProtectedRouteByResourceProps> =
|
||||
return <Navigate to="/auth" replace />;
|
||||
}
|
||||
|
||||
// 1. Verificar se o usuário está ativo no sistema
|
||||
if (profile && profile.status !== 'active') {
|
||||
return (
|
||||
<div className="flex flex-col items-center justify-center min-h-screen bg-background text-center p-4">
|
||||
<h1 className="text-2xl font-bold mb-4">Acesso Bloqueado</h1>
|
||||
<p className="text-muted-foreground mb-2">
|
||||
Seu usuário existe, mas encontra-se com status: <strong>{profile.status || 'pendente'}</strong>.
|
||||
</p>
|
||||
<p className="text-muted-foreground">Por favor, contate o administrador para aprovar o seu acesso.</p>
|
||||
</div>
|
||||
);
|
||||
}
|
||||
|
||||
// 2. Administradores têm acesso irrestrito
|
||||
if (isAdmin) {
|
||||
return <>{children}</>;
|
||||
}
|
||||
|
||||
// 3. Validação real de permissão granular pelo resourceKey
|
||||
const podeAcessar = hasAccess(resourceKey);
|
||||
|
||||
if (!podeAcessar) {
|
||||
// Se o usuário tem acesso ao Modo Smart, redirecionar para a experiência dele
|
||||
const temAcessoSmart =
|
||||
resourcePermissions['modo-smart'] &&
|
||||
resourcePermissions['modo-smart'] !== 'no_access';
|
||||
|
||||
return (
|
||||
<div className="flex flex-col items-center justify-center min-h-[75vh] p-6 text-center">
|
||||
<div className="p-4 rounded-2xl bg-amber-500/10 border border-amber-500/20 text-amber-500 mb-4 shadow-sm">
|
||||
<ShieldAlert className="w-12 h-12 stroke-[1.5]" />
|
||||
</div>
|
||||
<h2 className="text-2xl font-bold text-foreground mb-2">Acesso Restrito a Este Módulo</h2>
|
||||
<p className="text-sm text-muted-foreground max-w-md mb-6">
|
||||
Seu usuário não possui permissão concedida para acessar o recurso{' '}
|
||||
<code className="px-2 py-0.5 rounded bg-muted font-mono text-xs text-foreground">
|
||||
{resourceKey}
|
||||
</code>
|
||||
. Solicite liberação na Matriz de Acessos ao administrador do sistema.
|
||||
</p>
|
||||
|
||||
<div className="flex flex-wrap items-center justify-center gap-3">
|
||||
{temAcessoSmart && (
|
||||
<Button asChild className="bg-amber-600 hover:bg-amber-700 text-white font-medium">
|
||||
<Link to="/smart">
|
||||
<Zap className="w-4 h-4 mr-2" />
|
||||
Ir para o Modo Smart
|
||||
</Link>
|
||||
</Button>
|
||||
)}
|
||||
<Button variant="outline" asChild>
|
||||
<Link to="/dashboard">
|
||||
<ArrowLeft className="w-4 h-4 mr-2" />
|
||||
Voltar ao Início
|
||||
</Link>
|
||||
</Button>
|
||||
</div>
|
||||
</div>
|
||||
);
|
||||
}
|
||||
|
||||
// Travas internas removidas - Gerenciado pelo BrainSteel Hub Guard
|
||||
return <>{children}</>;
|
||||
};
|
||||
@@ -14,7 +14,7 @@ export const PriorityFilter: React.FC<PriorityFilterProps> = ({ value, onChange
|
||||
|
||||
if (loading) {
|
||||
return (
|
||||
<Select disabled>
|
||||
<Select disabled value={value || 'all'}>
|
||||
<SelectTrigger className="w-48 priority-filter-trigger">
|
||||
<SelectValue placeholder="Carregando..." />
|
||||
</SelectTrigger>
|
||||
@@ -23,7 +23,7 @@ export const PriorityFilter: React.FC<PriorityFilterProps> = ({ value, onChange
|
||||
}
|
||||
|
||||
return (
|
||||
<Select value={value} onValueChange={onChange}>
|
||||
<Select value={value || 'all'} onValueChange={onChange}>
|
||||
<SelectTrigger className="w-48 priority-filter-trigger">
|
||||
<SelectValue placeholder="Filtrar por prioridade" />
|
||||
</SelectTrigger>
|
||||
|
||||
Reference in New Issue
Block a user