diff --git a/app/(main)/wireguard/page.tsx b/app/(main)/wireguard/page.tsx index df497d5e..60e8a3ec 100644 --- a/app/(main)/wireguard/page.tsx +++ b/app/(main)/wireguard/page.tsx @@ -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(null) const [exportIface, setExportIface] = useState(null) const [exportInitialTab, setExportInitialTab] = useState<"rsc" | "conf" | "peer">("rsc") const [exportPeerId, setExportPeerId] = useState(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 )} - @@ -874,7 +880,8 @@ function WireGuardPageContent({ selectedServerId, selectedInterfaceId, allInterf /> { if (!importLock.current) setImportOpen(v) }} + error={importError} servers={serverOptions} defaultServerId={sheetServerId} busy={busy} diff --git a/components/wireguard/wg-import-sheet.tsx b/components/wireguard/wg-import-sheet.tsx index 5601f74a..ccbf1692 100644 --- a/components/wireguard/wg-import-sheet.tsx +++ b/components/wireguard/wg-import-sheet.tsx @@ -1,6 +1,6 @@ "use client" -import { useEffect, useMemo, useState } from "react" +import { useMemo, useState } from "react" import { FormField, SectionTitle } from "@/components/form-kit" import { Button } from "@/components/ui/button" import { @@ -17,6 +17,7 @@ function WgImportSheet({ onOpenChange, servers, busy, + error, defaultServerId, onImport, }: { @@ -24,6 +25,7 @@ function WgImportSheet({ onOpenChange: (v: boolean) => void servers: ServerOption[] busy?: boolean + error?: string | null defaultServerId?: string onImport: (args: { serverId: string @@ -43,10 +45,11 @@ function WgImportSheet({ [content], ) - useEffect(() => { - if (!open) return - setServerId(defaultServerId ?? "") - }, [open, defaultServerId]) + const [context, setContext] = useState({ open: false, defaultServerId }) + if (context.open !== open || context.defaultServerId !== defaultServerId) { + setContext({ open, defaultServerId }) + if (open) setServerId(defaultServerId ?? "") + } function runPreview() { setParseError(null) @@ -73,6 +76,7 @@ function WgImportSheet({ { + if (busy) return if (v) { setServerId(defaultServerId ?? "") } else { @@ -84,7 +88,7 @@ function WgImportSheet({ onOpenChange(v) }} > - + Импорт конфига WireGuard @@ -92,10 +96,11 @@ function WgImportSheet({ -
+
setFormat(e.target.value as "auto" | "rsc" | "conf")} > @@ -135,6 +141,7 @@ function WgImportSheet({