feat: add agent reset flow and document machine handover
This commit is contained in:
parent
28796bf105
commit
25d2a9b062
6 changed files with 196 additions and 8 deletions
|
|
@ -2280,6 +2280,7 @@ export function MachineDetails({ machine }: MachineDetailsProps) {
|
|||
[editingRemoteAccessClientId, remoteAccessEntries]
|
||||
)
|
||||
const [togglingActive, setTogglingActive] = useState(false)
|
||||
const [isResettingAgent, setIsResettingAgent] = useState(false)
|
||||
const [showAllWindowsSoftware, setShowAllWindowsSoftware] = useState(false)
|
||||
const jsonText = useMemo(() => {
|
||||
const payload = {
|
||||
|
|
@ -2569,6 +2570,34 @@ export function MachineDetails({ machine }: MachineDetailsProps) {
|
|||
}
|
||||
}
|
||||
|
||||
const handleResetAgent = useCallback(async () => {
|
||||
if (!machine) return
|
||||
toast.dismiss("machine-reset")
|
||||
toast.loading("Resetando agente...", { id: "machine-reset" })
|
||||
setIsResettingAgent(true)
|
||||
try {
|
||||
const response = await fetch("/api/admin/machines/reset-agent", {
|
||||
method: "POST",
|
||||
headers: { "Content-Type": "application/json" },
|
||||
credentials: "include",
|
||||
body: JSON.stringify({ machineId: machine.id }),
|
||||
})
|
||||
const payload = (await response.json().catch(() => null)) as { error?: string; revoked?: number } | null
|
||||
if (!response.ok) {
|
||||
const message = payload?.error ?? "Falha ao resetar agente."
|
||||
throw new Error(message)
|
||||
}
|
||||
const revokedLabel = typeof payload?.revoked === "number" && payload.revoked > 0 ? ` (${payload.revoked} token(s) revogados)` : ""
|
||||
toast.success(`Agente resetado${revokedLabel}. Reprovisione o agente na máquina.`, { id: "machine-reset" })
|
||||
router.refresh()
|
||||
} catch (error) {
|
||||
const message = error instanceof Error ? error.message : "Falha ao resetar agente."
|
||||
toast.error(message, { id: "machine-reset" })
|
||||
} finally {
|
||||
setIsResettingAgent(false)
|
||||
}
|
||||
}, [machine, router])
|
||||
|
||||
const handleCopyRemoteIdentifier = useCallback(async (identifier: string | null | undefined) => {
|
||||
if (!identifier) return
|
||||
try {
|
||||
|
|
@ -2702,6 +2731,16 @@ export function MachineDetails({ machine }: MachineDetailsProps) {
|
|||
<ShieldCheck className="size-4" />
|
||||
Ajustar acesso
|
||||
</Button>
|
||||
<Button
|
||||
size="sm"
|
||||
variant="outline"
|
||||
className="gap-2 border-dashed border-amber-300 text-amber-700 hover:border-amber-400 hover:text-amber-800"
|
||||
onClick={handleResetAgent}
|
||||
disabled={isResettingAgent}
|
||||
>
|
||||
<RefreshCcw className={cn("size-4", isResettingAgent && "animate-spin")} />
|
||||
{isResettingAgent ? "Resetando agente..." : "Resetar agente"}
|
||||
</Button>
|
||||
<Button
|
||||
size="sm"
|
||||
variant={isActiveLocal ? "outline" : "default"}
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue