fix(ui): подтверждать переключение туннелей GRE

This commit is contained in:
Denozordec committed 2026-09-30 00:42:28 +07:00
1 parent 780d5e9237
commit 66b439cc2e
5 files changed
+78 -7

No files matched your search

+15 -3
View File
@@ -275,6 +275,9 @@ function GrePageContent({ selectedServerId, selectedTunnelId, allTunnelsHref, on
const [tunnelMode, setTunnelMode] = useState<"create" | "edit">("create")
const [editingTunnel, setEditingTunnel] = useState<GreTunnel | null>(null)
const [pendingDelete, setPendingDelete] = useState<GreTunnel | null>(null)
const toggleLock = useRef(false)
const [toggleStatus, setToggleStatus] = useState<string | null>(null)
const [toggleError, setToggleError] = useState<string | null>(null)
const deleteLock = useRef(false)
const [deleteError, setDeleteError] = useState<string | null>(null)
const [mutateBusy, setMutateBusy] = useState(false)
@@ -484,10 +487,13 @@ function GrePageContent({ selectedServerId, selectedTunnelId, allTunnelsHref, on
}
async function toggleTunnel(t: GreTunnel) {
if (!isLive || mutationsLocked) return
if (!isLive || mutationsLocked || toggleLock.current) return
toggleLock.current = true
setToggleError(null)
setToggleStatus(`Ожидание изменения ${t.name}…`)
setMutateBusy(true)
try {
await apiFetch("/api/gre/tunnels", {
const result = await apiFetch<{ ok: boolean }>("/api/gre/tunnels", {
method: "PATCH",
body: JSON.stringify({
serverId: t.serverId,
@@ -497,11 +503,14 @@ function GrePageContent({ selectedServerId, selectedTunnelId, allTunnelsHref, on
remoteAddress: t.remoteAddress,
}),
})
if (result?.ok !== true) throw new Error("Сервер не подтвердил изменение туннеля")
toast.success(t.enabled ? `Выключен ${t.name}` : `Включён ${t.name}`)
await loadLive()
} catch (err) {
toast.error("Не удалось изменить туннель", { description: String(err) })
setToggleError(`${t.name}: ${err instanceof Error ? err.message : "Не удалось изменить туннель"}`)
} finally {
toggleLock.current = false
setToggleStatus(null)
setMutateBusy(false)
}
}
@@ -719,6 +728,9 @@ function GrePageContent({ selectedServerId, selectedTunnelId, allTunnelsHref, on
]}
/>
{toggleStatus && <p role="status" className="text-sm text-muted-foreground">{toggleStatus}</p>}
{toggleError && <p role="alert" className="text-sm text-destructive">{toggleError}</p>}
{/* Page tabs */}
<div className="flex items-center gap-1 border-b">
{(["tunnels", "pools"] as PageTab[]).map((tab) => (