fix(ui): защитить форму импорта WireGuard во время запроса

This commit is contained in:
Denozordec committed 2026-09-29 08:22:58 +07:00
1 parent efc6da1249
commit ec6ec52965
6 files changed
+89 -16

No files matched your search

+10 -3
View File
@@ -192,6 +192,8 @@ function WireGuardPageContent({ selectedServerId, selectedInterfaceId, allInterf
const [search, setSearch] = useState("")
const [createOpen, setCreateOpen] = useState(false)
const [importOpen, setImportOpen] = useState(false)
const importLock = useRef(false)
const [importError, setImportError] = useState<string | null>(null)
const [exportIface, setExportIface] = useState<WgIfaceWithServer | null>(null)
const [exportInitialTab, setExportInitialTab] = useState<"rsc" | "conf" | "peer">("rsc")
const [exportPeerId, setExportPeerId] = useState<string | null>(null)
@@ -443,10 +445,13 @@ function WireGuardPageContent({ selectedServerId, selectedInterfaceId, allInterf
format: "auto" | "rsc" | "conf"
dryRun: boolean
}) {
if (importLock.current) return
if (!isLive) {
toast.info("Импорт на роутер доступен только в live-режиме")
return
}
importLock.current = true
setImportError(null)
setBusy(true)
try {
const res = await importWireGuard(backendUrl, {
@@ -467,8 +472,9 @@ function WireGuardPageContent({ selectedServerId, selectedInterfaceId, allInterf
setImportOpen(false)
await loadLive()
} catch (e) {
toast.error(e instanceof Error ? e.message : "Ошибка импорта")
setImportError(e instanceof Error ? e.message : "Ошибка импорта")
} finally {
importLock.current = false
setBusy(false)
}
}
@@ -647,7 +653,7 @@ function WireGuardPageContent({ selectedServerId, selectedInterfaceId, allInterf
</Button>
</>
)}
<Button size="sm" variant="outline" onClick={() => setImportOpen(true)}>
<Button size="sm" variant="outline" onClick={() => { setImportError(null); setImportOpen(true) }}>
<UploadIcon className="size-4" />
Импорт
</Button>
@@ -874,7 +880,8 @@ function WireGuardPageContent({ selectedServerId, selectedInterfaceId, allInterf
/>
<WgImportSheet
open={importOpen}
onOpenChange={setImportOpen}
onOpenChange={v => { if (!importLock.current) setImportOpen(v) }}
error={importError}
servers={serverOptions}
defaultServerId={sheetServerId}
busy={busy}