From 5f4acb755e3eca299f9081e20afb5766c572ac5f Mon Sep 17 00:00:00 2001 From: xtcnet Date: Sun, 8 Mar 2026 10:29:37 +0700 Subject: [PATCH] fix: resolve cancel and close buttons not working on server modals --- .../modals/WireGuardLinkedServersModal.tsx | 121 ++++++------- frontend/src/modals/WireGuardServerModal.tsx | 161 +++++++++--------- 2 files changed, 131 insertions(+), 151 deletions(-) diff --git a/frontend/src/modals/WireGuardLinkedServersModal.tsx b/frontend/src/modals/WireGuardLinkedServersModal.tsx index cdaf2fe..2c3e61a 100644 --- a/frontend/src/modals/WireGuardLinkedServersModal.tsx +++ b/frontend/src/modals/WireGuardLinkedServersModal.tsx @@ -2,17 +2,19 @@ import { IconDeviceFloppy, IconX, } from "@tabler/icons-react"; +import EasyModal, { useModal } from "ez-modal-react"; import { useState, useEffect } from "react"; +import Modal from "react-bootstrap/Modal"; import type { WgInterface } from "src/api/backend/wireguard"; +import { Button } from "src/components"; interface WireGuardLinkedServersModalProps { wgInterface: WgInterface; allInterfaces: WgInterface[]; - onHide?: () => void; - resolve?: (data: { linked_servers: number[] }) => void; } -function WireGuardLinkedServersModal({ wgInterface, allInterfaces, onHide, resolve }: WireGuardLinkedServersModalProps) { +const WireGuardLinkedServersModal = EasyModal.create(({ wgInterface, allInterfaces }: WireGuardLinkedServersModalProps) => { + const modal = useModal(); // A map or set to manage checked status easily const [selected, setSelected] = useState>(new Set()); @@ -33,77 +35,64 @@ function WireGuardLinkedServersModal({ wgInterface, allInterfaces, onHide, resol }; const onSave = () => { - if (resolve) { - resolve({ linked_servers: Array.from(selected) }); - } - if (onHide) { - onHide(); - } + modal.resolve({ linked_servers: Array.from(selected) }); + modal.hide(); + }; + + const handleClose = () => { + modal.resolve(null); + modal.hide(); }; const availableServers = allInterfaces.filter(i => i.id !== wgInterface.id); return ( -
-
-
-
-
- Linked Servers for {wgInterface.name} -
- -
-
-

- Select the WireGuard servers that clients from {wgInterface.name} will be allowed to communicate with. -

+ + + + Linked Servers for {wgInterface.name} + + + +

+ Select the WireGuard servers that clients from {wgInterface.name} will be allowed to communicate with. +

- {availableServers.length === 0 ? ( -
- There are no other servers available to link to. -
- ) : ( -
- {availableServers.map(server => ( - - ))} -
- )} + {availableServers.length === 0 ? ( +
+ There are no other servers available to link to.
-
- - + ) : ( +
+ {availableServers.map(server => ( + + ))}
-
-
-
+ )} + + + + + + ); -} +}); export default WireGuardLinkedServersModal; diff --git a/frontend/src/modals/WireGuardServerModal.tsx b/frontend/src/modals/WireGuardServerModal.tsx index 531f717..660f365 100644 --- a/frontend/src/modals/WireGuardServerModal.tsx +++ b/frontend/src/modals/WireGuardServerModal.tsx @@ -2,19 +2,21 @@ import { IconDeviceFloppy, IconX, } from "@tabler/icons-react"; +import EasyModal, { useModal } from "ez-modal-react"; import { useEffect } from "react"; +import Modal from "react-bootstrap/Modal"; import { useForm } from "react-hook-form"; +import { Button } from "src/components"; interface WireGuardServerModalProps { wgInterface?: any; - onHide?: () => void; - resolve?: (data: any) => void; } const WG_DEFAULT_MTU = 1420; const WG_DEFAULT_DNS = "1.1.1.1, 8.8.8.8"; -function WireGuardServerModal({ wgInterface, onHide, resolve }: WireGuardServerModalProps) { +const WireGuardServerModal = EasyModal.create(({ wgInterface }: WireGuardServerModalProps) => { + const modal = useModal(); const { register, handleSubmit, @@ -44,95 +46,84 @@ function WireGuardServerModal({ wgInterface, onHide, resolve }: WireGuardServerM ...data, mtu: Number(data.mtu) || WG_DEFAULT_MTU, }; - if (resolve) { - resolve(submitData); - } - if (onHide) { - onHide(); - } + modal.resolve(submitData); + modal.hide(); + }; + + const handleClose = () => { + modal.resolve(null); + modal.hide(); }; return ( -
-
-
-
-
- {wgInterface ? `Edit Server: ${wgInterface.name}` : "New WireGuard Server"} -
- + + + + + {wgInterface ? `Edit Server: ${wgInterface.name}` : "New WireGuard Server"} + + + +
+ + + {errors.host && ( +
{errors.host.message as string}
+ )} + + The public IP or hostname domain that clients will use to connect. + +
+ +
+ + + Comma separated list. Assigned to clients.
-
-
- - - {errors.host && ( -
{errors.host.message as string}
- )} - - The public IP or hostname domain that clients will use to connect. - -
- -
- - - Comma separated list. Assigned to clients. -
-
- - -
+
+ + +
-
- - -
+
+ +
-
- - -
- -
-
+ + + + + + + ); -} +}); export default WireGuardServerModal;