From 77f48652cddac4fb1fb7abba8ae6a001367a6f85 Mon Sep 17 00:00:00 2001 From: Esdras Renan Date: Sun, 19 Oct 2025 02:13:39 -0300 Subject: [PATCH] Auth: poll machine session to reflect deactivation in real time; Desktop: refresh deactivation screen to match design system --- .../src/components/DeactivationScreen.tsx | 48 ++++++++--------- src/lib/auth-client.tsx | 51 +++++++++++++++++++ 2 files changed, 75 insertions(+), 24 deletions(-) diff --git a/apps/desktop/src/components/DeactivationScreen.tsx b/apps/desktop/src/components/DeactivationScreen.tsx index d65f43b..e4ba4c5 100644 --- a/apps/desktop/src/components/DeactivationScreen.tsx +++ b/apps/desktop/src/components/DeactivationScreen.tsx @@ -1,40 +1,40 @@ -import { RefreshCw, Mail } from "lucide-react" +import { ShieldAlert, Mail } from "lucide-react" export function DeactivationScreen({ companyName }: { companyName?: string | null }) { return ( -
-
+
+
-
- -
+ + Acesso bloqueado +

Máquina desativada

-

- Esta máquina foi desativada temporariamente por um administrador da Rever. Enquanto estiver nessa situação, - o acesso ao portal e o envio de informações ficam bloqueados. +

+ Esta máquina foi desativada temporariamente pelos administradores. Enquanto isso, o acesso ao portal e o + envio de informações ficam indisponíveis.

{companyName ? ( - + {companyName} ) : null}
-
-
-

Como proceder?

-
    -
  • - 1. Caso precise restaurar o acesso, entre em contato com a equipe de suporte da Rever. -
  • -
  • - 2. Informe o identificador desta máquina e peça a reativação. -
  • + +
    +
    +

    Como regularizar

    +
      +
    • Entre em contato com o suporte da Rever e solicite a reativação.
    • +
    • Informe o nome do computador e seus dados de contato.
    -
    - - suporte@rever.com.br -
    + + + Falar com o suporte +
diff --git a/src/lib/auth-client.tsx b/src/lib/auth-client.tsx index 4e0c820..5cc579e 100644 --- a/src/lib/auth-client.tsx +++ b/src/lib/auth-client.tsx @@ -217,6 +217,57 @@ export function AuthProvider({ children }: { children: React.ReactNode }) { } }, [session?.user]) + // Poll machine session periodically to reflect admin changes (e.g., deactivation) + useEffect(() => { + const shouldPoll = Boolean(session?.user?.role === "machine") || Boolean(machineContext) + if (!shouldPoll) return + let cancelled = false + const tick = async () => { + try { + const response = await fetch("/api/machines/session", { credentials: "include" }) + if (!response.ok) return + const data = await response.json() + if (cancelled) return + const mc = data?.machine + if (mc && typeof mc === "object") { + setMachineContext((prev) => { + // only update when something changes to avoid re-renders + const next = { + machineId: mc.id, + tenantId: mc.tenantId, + persona: mc.persona ?? null, + assignedUserId: mc.assignedUserId ?? null, + assignedUserEmail: mc.assignedUserEmail ?? null, + assignedUserName: mc.assignedUserName ?? null, + assignedUserRole: mc.assignedUserRole ?? null, + companyId: mc.companyId ?? null, + isActive: (mc.isActive ?? true) as boolean, + } as MachineContext + return JSON.stringify(prev) === JSON.stringify(next) ? prev : next + }) + } + } catch { + /* ignore transient errors */ + } + } + const id = setInterval(tick, 15000) + // Also refresh when tab gains focus + const onFocus = () => tick() + if (typeof window !== "undefined") { + window.addEventListener("focus", onFocus) + document.addEventListener("visibilitychange", onFocus) + } + tick() + return () => { + cancelled = true + clearInterval(id) + if (typeof window !== "undefined") { + window.removeEventListener("focus", onFocus) + document.removeEventListener("visibilitychange", onFocus) + } + } + }, [session?.user?.role, machineContext]) + useEffect(() => { if (!session?.user || session.user.role === "machine" || convexUserId) return