fix(ui): подтверждать создание интерфейса и пира WireGuard

This commit is contained in:
Denozordec committed 2026-09-29 08:30:07 +07:00
1 parent ec6ec52965
commit 8fff3d7fff
8 files changed
+166 -52

No files matched your search

+25 -13
View File
@@ -192,7 +192,9 @@ function WireGuardPageContent({ selectedServerId, selectedInterfaceId, allInterf
const [search, setSearch] = useState("")
const [createOpen, setCreateOpen] = useState(false)
const [importOpen, setImportOpen] = useState(false)
const importLock = useRef(false)
const formLock = useRef(false)
const [createError, setCreateError] = useState<string | null>(null)
const [peerError, setPeerError] = useState<string | null>(null)
const [importError, setImportError] = useState<string | null>(null)
const [exportIface, setExportIface] = useState<WgIfaceWithServer | null>(null)
const [exportInitialTab, setExportInitialTab] = useState<"rsc" | "conf" | "peer">("rsc")
@@ -400,10 +402,13 @@ function WireGuardPageContent({ selectedServerId, selectedInterfaceId, allInterf
}, [displayServers, displayIfaces])
async function handleCreate(form: WgCreateFormState) {
if (formLock.current) return
if (!isLive) {
toast.info("Создание на роутер доступно только в live-режиме")
return
}
formLock.current = true
setCreateError(null)
setBusy(true)
try {
const ep = parseEndpoint(form.peerEndpoint)
@@ -433,8 +438,9 @@ function WireGuardPageContent({ selectedServerId, selectedInterfaceId, allInterf
setCreateOpen(false)
await loadLive()
} catch (e) {
toast.error(e instanceof Error ? e.message : "Ошибка создания")
setCreateError(e instanceof Error ? e.message : "Ошибка создания")
} finally {
formLock.current = false
setBusy(false)
}
}
@@ -445,12 +451,12 @@ function WireGuardPageContent({ selectedServerId, selectedInterfaceId, allInterf
format: "auto" | "rsc" | "conf"
dryRun: boolean
}) {
if (importLock.current) return
if (formLock.current) return
if (!isLive) {
toast.info("Импорт на роутер доступен только в live-режиме")
return
}
importLock.current = true
formLock.current = true
setImportError(null)
setBusy(true)
try {
@@ -474,7 +480,7 @@ function WireGuardPageContent({ selectedServerId, selectedInterfaceId, allInterf
} catch (e) {
setImportError(e instanceof Error ? e.message : "Ошибка импорта")
} finally {
importLock.current = false
formLock.current = false
setBusy(false)
}
}
@@ -539,11 +545,14 @@ function WireGuardPageContent({ selectedServerId, selectedInterfaceId, allInterf
}
async function handleAddPeer(form: WgPeerFormState) {
if (formLock.current) return
if (sourceUnavailable(peerIface?.serverId)) return
if (!isLive || !peerIface) {
toast.info("Доступно только в live-режиме")
return
}
formLock.current = true
setPeerError(null)
setBusy(true)
try {
const ep = parseEndpoint(form.endpoint)
@@ -564,8 +573,9 @@ function WireGuardPageContent({ selectedServerId, selectedInterfaceId, allInterf
setPeerIface(null)
await loadLive()
} catch (e) {
toast.error(e instanceof Error ? e.message : "Ошибка")
setPeerError(e instanceof Error ? e.message : "Ошибка")
} finally {
formLock.current = false
setBusy(false)
}
}
@@ -605,7 +615,7 @@ function WireGuardPageContent({ selectedServerId, selectedInterfaceId, allInterf
}
const emptyCreateAction = (
<Button size="sm" onClick={() => setCreateOpen(true)}>
<Button size="sm" onClick={() => { setCreateError(null); setCreateOpen(true) }}>
<PlusIcon className="size-4" />
Новый интерфейс
</Button>
@@ -657,7 +667,7 @@ function WireGuardPageContent({ selectedServerId, selectedInterfaceId, allInterf
<UploadIcon className="size-4" />
Импорт
</Button>
<Button size="sm" onClick={() => setCreateOpen(true)}>
<Button size="sm" onClick={() => { setCreateError(null); setCreateOpen(true) }}>
<PlusIcon className="size-4" />
Новый интерфейс
</Button>
@@ -776,7 +786,7 @@ function WireGuardPageContent({ selectedServerId, selectedInterfaceId, allInterf
compactServer={compactServer}
emptyAction={emptyCreateAction}
onExport={(iface) => openExport(iface, "rsc")}
onAddPeer={selectedSourceError ? undefined : setPeerIface}
onAddPeer={selectedSourceError ? undefined : iface => { setPeerError(null); setPeerIface(iface) }}
onToggle={selectedSourceError ? undefined : handleToggle}
onDelete={selectedSourceError ? undefined : (iface) => setPendingDelete({ kind: "iface", iface })}
onDeletePeer={selectedSourceError ? undefined : (iface, peerId) => setPendingDelete({ kind: "peer", iface, peerId })}
@@ -798,7 +808,7 @@ function WireGuardPageContent({ selectedServerId, selectedInterfaceId, allInterf
compactServer={compactServer}
emptyAction={
scopedIfaces.length === 1 ? (
<Button size="sm" disabled={selectedSourceError} onClick={() => setPeerIface(scopedIfaces[0])}>
<Button size="sm" disabled={selectedSourceError} onClick={() => { setPeerError(null); setPeerIface(scopedIfaces[0]) }}>
<PlusIcon className="size-4" />
Добавить пира
</Button>
@@ -872,7 +882,8 @@ function WireGuardPageContent({ selectedServerId, selectedInterfaceId, allInterf
<WgCreateSheet
open={createOpen}
onOpenChange={setCreateOpen}
onOpenChange={v => { if (!formLock.current) setCreateOpen(v) }}
error={createError}
servers={serverOptions}
defaultServerId={sheetServerId}
busy={busy}
@@ -880,7 +891,7 @@ function WireGuardPageContent({ selectedServerId, selectedInterfaceId, allInterf
/>
<WgImportSheet
open={importOpen}
onOpenChange={v => { if (!importLock.current) setImportOpen(v) }}
onOpenChange={v => { if (!formLock.current) setImportOpen(v) }}
error={importError}
servers={serverOptions}
defaultServerId={sheetServerId}
@@ -891,7 +902,8 @@ function WireGuardPageContent({ selectedServerId, selectedInterfaceId, allInterf
open={!!peerIface}
iface={peerIface}
busy={busy}
onOpenChange={(v) => { if (!v) setPeerIface(null) }}
onOpenChange={(v) => { if (!v && !formLock.current) setPeerIface(null) }}
error={peerError}
onSubmit={handleAddPeer}
/>
<WgExportSheet