From 9e6c8a482e3e710fa6406fbdc231d07cc7ff4e0d Mon Sep 17 00:00:00 2001 From: "gpt-engineer-app[bot]" <159125892+gpt-engineer-app[bot]@users.noreply.github.com> Date: Thu, 23 Apr 2026 20:59:03 +0000 Subject: [PATCH] Changes Co-authored-by: domfelipe <53182096+domfelipe@users.noreply.github.com> --- src/routes/admin.tsx | 88 +++++++++++++++++++++++--------------------- 1 file changed, 47 insertions(+), 41 deletions(-) diff --git a/src/routes/admin.tsx b/src/routes/admin.tsx index 72edeb2..df5a5d0 100644 --- a/src/routes/admin.tsx +++ b/src/routes/admin.tsx @@ -9,8 +9,8 @@ import { Loader2, PlayCircle, PauseCircle, - RotateCw, Server, + Settings, ShieldAlert, } from "lucide-react"; import { supabase } from "@/integrations/supabase/client"; @@ -43,6 +43,8 @@ interface AgentRow { vps_pool_id: string | null; created_at: string; provisioned_at: string | null; + profile: { full_name: string | null } | null; + subscription: { plans: { slug: string; name: string } | null } | null; } function AdminPage() { @@ -65,18 +67,30 @@ function AdminPage() { }); const { data: agents, isLoading: agentsLoading } = useQuery({ - queryKey: ["admin-agents"], + queryKey: ["agents-admin"], enabled: !!isAdmin, + refetchInterval: 15000, queryFn: async () => { const { data, error } = await supabase .from("agent_instances") .select( - "id, user_id, status, uuid_tenant, telegram_bot_username, telegram_bot_token_vault_id, railway_service_id, vps_pool_id, created_at, provisioned_at", + `id, user_id, status, uuid_tenant, telegram_bot_username, telegram_bot_token_vault_id, + railway_service_id, vps_pool_id, created_at, provisioned_at, + profile:profiles!agent_instances_user_id_fkey(full_name), + subscription:subscriptions!subscriptions_user_id_fkey(plans(slug, name))`, ) .order("created_at", { ascending: false }) .limit(100); if (error) throw error; - return data as AgentRow[]; + // Pegar apenas a subscription ativa (primeira) — o relacionamento retorna array + // deno-lint-ignore no-explicit-any + return (data as any[]).map((a) => ({ + ...a, + profile: Array.isArray(a.profile) ? a.profile[0] ?? null : a.profile, + subscription: Array.isArray(a.subscription) + ? a.subscription.find((s: { plans: unknown }) => s.plans) ?? a.subscription[0] ?? null + : a.subscription, + })) as AgentRow[]; }, }); @@ -115,10 +129,7 @@ function AdminPage() { ); } - async function action( - fn: "provision-agent" | "suspend-agent" | "resume-agent", - agentId: string, - ) { + async function action(fn: "suspend-agent" | "resume-agent", agentId: string) { setBusy(agentId + fn); const { data, error } = await invokeFunction<{ ok?: boolean; error?: string }>(fn, { agent_instance_id: agentId, @@ -130,20 +141,20 @@ function AdminPage() { toast.error(`${fn}: ${data.error}`); } else { toast.success(`${fn} executado com sucesso`); - queryClient.invalidateQueries({ queryKey: ["admin-agents"] }); + queryClient.invalidateQueries({ queryKey: ["agents-admin"] }); } } return (
-
+

Admin · Mika

- Gerencie agentes provisionados, suspenda e reative containers Railway. + Configure e gerencie agentes provisionados.

- )} + {a.status === "active" && ( )} {a.status === "suspended" && ( @@ -244,7 +241,7 @@ function AdminPage() { ) : ( )} - Reativar + Reativar )} @@ -267,3 +264,12 @@ function StatusBadge({ status }: { status: string }) { if (status === "error") return Erro; return {status}; } + +function PlanBadge({ slug }: { slug: string | null }) { + if (!slug) return Sem plano; + if (slug === "professional" || slug === "enterprise") + return {slug}; + if (slug === "starter") return {slug}; + return {slug}; +} +