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

+20 -9
View File
@@ -30,12 +30,14 @@ function WgPeerSheet({
open,
iface,
busy,
error,
onOpenChange,
onSubmit,
}: {
open: boolean
iface: WgIfaceWithServer | null
busy?: boolean
error?: string | null
onOpenChange: (v: boolean) => void
onSubmit: (form: WgPeerFormState) => void | Promise<void>
}) {
@@ -43,27 +45,33 @@ function WgPeerSheet({
const set = <K extends keyof WgPeerFormState>(k: K, v: WgPeerFormState[K]) =>
setForm((f) => ({ ...f, [k]: v }))
const [context, setContext] = useState({ open: false, iface })
if (context.open !== open || context.iface !== iface) {
setContext({ open, iface })
if (open) setForm(emptyPeerForm())
}
return (
<Sheet
open={open}
onOpenChange={(v) => {
if (v) setForm(emptyPeerForm())
if (busy) return
onOpenChange(v)
}}
>
<SheetContent side="right" className="w-full sm:max-w-md flex flex-col gap-0 p-0">
<SheetContent showCloseButton={!busy} side="right" className="w-full sm:max-w-md flex flex-col gap-0 p-0">
<SheetHeader className="px-6 pt-6 pb-4 border-b shrink-0">
<SheetTitle>Добавить пира</SheetTitle>
<SheetDescription>
{iface ? `${iface.name} · ${iface.serverName}` : "WireGuard peer"}
</SheetDescription>
</SheetHeader>
<div className="flex-1 overflow-y-auto px-6 py-5 flex flex-col gap-4">
<fieldset disabled={busy} aria-busy={busy} className="min-h-0 min-w-0 flex-1 overflow-y-auto px-6 py-5 flex flex-col gap-4">
<SectionTitle>Параметры пира</SectionTitle>
<FormField label="Public key" required>
<Input
className="font-mono text-xs"
value={form.publicKey}
aria-label="Public key" value={form.publicKey}
onChange={(e) => set("publicKey", e.target.value)}
/>
</FormField>
@@ -71,7 +79,7 @@ function WgPeerSheet({
<Input
className="font-mono"
placeholder="10.210.0.2/32"
value={form.allowedIps}
aria-label="Allowed IPs" value={form.allowedIps}
onChange={(e) => set("allowedIps", e.target.value)}
/>
</FormField>
@@ -79,26 +87,29 @@ function WgPeerSheet({
<Input
className="font-mono"
placeholder="1.2.3.4:13231"
value={form.endpoint}
aria-label="Endpoint" value={form.endpoint}
onChange={(e) => set("endpoint", e.target.value)}
/>
</FormField>
<FormField label="Keepalive (сек)">
<Input
className="font-mono"
value={form.keepalive}
aria-label="Keepalive (сек)" value={form.keepalive}
onChange={(e) => set("keepalive", e.target.value)}
/>
</FormField>
<FormField label="Комментарий">
<Input value={form.comment} onChange={(e) => set("comment", e.target.value)} />
<Input aria-label="Комментарий" value={form.comment} onChange={(e) => set("comment", e.target.value)} />
</FormField>
</div>
</fieldset>
{busy && <p role="status" className="px-6 text-sm text-muted-foreground">Ожидание подтверждения создания…</p>}
{error && <p role="alert" className="px-6 text-sm text-destructive">{error}</p>}
<SheetFooter className="px-6 py-4 border-t shrink-0 flex-row gap-2">
<SheetClose render={<Button variant="outline" className="flex-1" disabled={busy} />}>
Отмена
</SheetClose>
<Button
type="button"
className="flex-1"
disabled={busy || !form.publicKey.trim() || !form.allowedIps.trim()}
onClick={() => void onSubmit(form)}