mirror of
https://github.com/domfelipe/mika-agent-assist.git
synced 2026-08-07 11:16:46 +00:00
Corrigiu loading da rota admin
X-Lovable-Edit-ID: edt-6d2672f8-6b62-48cf-b60b-679f79336c66 Co-authored-by: domfelipe <53182096+domfelipe@users.noreply.github.com>
This commit is contained in:
commit
3bff9b4e4b
1 changed files with 24 additions and 4 deletions
|
|
@ -80,7 +80,7 @@ function AgentDetailPage() {
|
||||||
|
|
||||||
const { data: isAdmin, isLoading: roleLoading } = useQuery({
|
const { data: isAdmin, isLoading: roleLoading } = useQuery({
|
||||||
queryKey: ["is-admin", user?.id],
|
queryKey: ["is-admin", user?.id],
|
||||||
enabled: !!user,
|
enabled: !authLoading && !!user,
|
||||||
queryFn: async () => {
|
queryFn: async () => {
|
||||||
const { data, error } = await supabase.rpc("has_role", {
|
const { data, error } = await supabase.rpc("has_role", {
|
||||||
_user_id: user!.id,
|
_user_id: user!.id,
|
||||||
|
|
@ -93,7 +93,7 @@ function AgentDetailPage() {
|
||||||
|
|
||||||
const { data: agent, isLoading: agentLoading, error: agentError } = useQuery({
|
const { data: agent, isLoading: agentLoading, error: agentError } = useQuery({
|
||||||
queryKey: ["agent-detail", id],
|
queryKey: ["agent-detail", id],
|
||||||
enabled: !!isAdmin,
|
enabled: !authLoading && !!user && isAdmin === true,
|
||||||
refetchInterval: 10_000,
|
refetchInterval: 10_000,
|
||||||
queryFn: async () => {
|
queryFn: async () => {
|
||||||
console.log("[admin.agente] fetching agent detail", { id });
|
console.log("[admin.agente] fetching agent detail", { id });
|
||||||
|
|
@ -259,7 +259,7 @@ function AgentDetailPage() {
|
||||||
isAdmin, hasUser: !!user, hasAgent: !!agent, agentError,
|
isAdmin, hasUser: !!user, hasAgent: !!agent, agentError,
|
||||||
});
|
});
|
||||||
|
|
||||||
if (authLoading || roleLoading) {
|
if (authLoading || (user && roleLoading) || (isAdmin === true && agentLoading)) {
|
||||||
return (
|
return (
|
||||||
<div className="min-h-screen flex items-center justify-center bg-background">
|
<div className="min-h-screen flex items-center justify-center bg-background">
|
||||||
<Loader2 className="h-6 w-6 animate-spin text-primary" />
|
<Loader2 className="h-6 w-6 animate-spin text-primary" />
|
||||||
|
|
@ -267,7 +267,11 @@ function AgentDetailPage() {
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
if (!isAdmin) {
|
if (!user) {
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
|
||||||
|
if (isAdmin === false) {
|
||||||
return (
|
return (
|
||||||
<div className="min-h-screen flex items-center justify-center bg-background px-4">
|
<div className="min-h-screen flex items-center justify-center bg-background px-4">
|
||||||
<div className="max-w-md text-center space-y-4">
|
<div className="max-w-md text-center space-y-4">
|
||||||
|
|
@ -285,6 +289,22 @@ function AgentDetailPage() {
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if (agentError) {
|
||||||
|
return (
|
||||||
|
<div className="min-h-screen flex items-center justify-center bg-background px-4">
|
||||||
|
<div className="max-w-md text-center space-y-4">
|
||||||
|
<h1 className="text-2xl font-bold">Erro ao carregar agente</h1>
|
||||||
|
<p className="text-sm text-muted-foreground">{agentError.message}</p>
|
||||||
|
<Button asChild variant="outline">
|
||||||
|
<Link to="/admin">
|
||||||
|
<ArrowLeft className="h-4 w-4 mr-2" /> Voltar ao admin
|
||||||
|
</Link>
|
||||||
|
</Button>
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
);
|
||||||
|
}
|
||||||
|
|
||||||
if (!agent) {
|
if (!agent) {
|
||||||
return (
|
return (
|
||||||
<div className="min-h-screen flex items-center justify-center bg-background px-4">
|
<div className="min-h-screen flex items-center justify-center bg-background px-4">
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue