mirror of
https://github.com/crocofied/CoreControl.git
synced 2025-12-29 16:14:43 +00:00
hooks promises
This commit is contained in:
@@ -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")
|
||||
}
|
||||
};
|
||||
|
||||
Reference in New Issue
Block a user