hooks promises

This commit is contained in:
headlesdev
2025-05-20 00:06:32 +02:00
parent 6301997eac
commit ca1d60b058
7 changed files with 88 additions and 46 deletions

View File

@@ -22,7 +22,7 @@ export default function EditNetwork({ onNetworkEdited, siteId, network }: EditNe
const [success, setSuccess] = useState("");
const { editNetwork } = useNetworks();
const handleEdit = () => {
const handleEdit = async () => {
try {
const response = editNetwork({
id: network.id,
@@ -32,17 +32,22 @@ export default function EditNetwork({ onNetworkEdited, siteId, network }: EditNe
ipv6Subnet: editIpv6Subnet,
gateway: editGateway
});
if (response) {
if (typeof response === "string") {
setError(response)
return
}
setTimeout(() => {
if (onNetworkEdited) {
try{
const successMessage = await response
if (onNetworkEdited && successMessage) {
onNetworkEdited()
setSuccess("Network edited successfully")
setSuccess(successMessage)
}
}, 500);
} catch (err) {
} catch (apiError: any) {
setError(apiError)
}
} catch (err: any) {
setError("Failed to edit network")
}
};