Sites & Network Finally Statement

This commit is contained in:
headlesdev 2025-05-20 20:06:32 +02:00
parent 4f182ca21d
commit b4d43bc0dd
5 changed files with 47 additions and 45 deletions

View File

@ -41,6 +41,11 @@ export default function AddNetwork({ onNetworkAdded, siteId }: AddNetworkProps)
} }
} catch (apiError: any) { } catch (apiError: any) {
setError(apiError) setError(apiError)
} finally {
setName("")
setIpv4Subnet("")
setIpv6Subnet("")
setGateway("")
} }
}; };

View File

@ -32,6 +32,9 @@ export default function AddSite({ onSiteAdded }: AddSiteProps) {
} }
} catch (apiError: any) { } catch (apiError: any) {
setError(apiError) setError(apiError)
} finally {
setName("")
setDescription("")
} }
}; };

View File

@ -16,7 +16,6 @@ export default function DeleteNetwork({ networkId, onNetworkDeleted }: DeleteNet
const { deleteNetwork } = useNetworks(); const { deleteNetwork } = useNetworks();
const handleDelete = async () => { const handleDelete = async () => {
try {
const response = deleteNetwork(networkId); const response = deleteNetwork(networkId);
if (typeof response === "string") { if (typeof response === "string") {
setError(response) setError(response)
@ -32,9 +31,6 @@ export default function DeleteNetwork({ networkId, onNetworkDeleted }: DeleteNet
} catch (apiError: any) { } catch (apiError: any) {
setError(apiError) setError(apiError)
} }
} catch (err) {
setError("Failed to delete network")
}
}; };
return ( return (

View File

@ -23,7 +23,6 @@ export default function EditNetwork({ onNetworkEdited, siteId, network }: EditNe
const { editNetwork } = useNetworks(); const { editNetwork } = useNetworks();
const handleEdit = async () => { const handleEdit = async () => {
try {
const response = editNetwork({ const response = editNetwork({
id: network.id, id: network.id,
siteId, siteId,
@ -45,10 +44,11 @@ export default function EditNetwork({ onNetworkEdited, siteId, network }: EditNe
} }
} catch (apiError: any) { } catch (apiError: any) {
setError(apiError) setError(apiError)
} } finally {
setEditName("")
} catch (err: any) { setEditIpv4Subnet("")
setError("Failed to edit network") setEditIpv6Subnet("")
setEditGateway("")
} }
}; };

View File

@ -25,7 +25,6 @@ export default function EditSite({ site, onSiteEdited }: EditSiteProps) {
}, [site]) }, [site])
const handleEditSite = async () => { const handleEditSite = async () => {
try {
const result = editSite({ id: site.id, name, description, networks: site.networks }) const result = editSite({ id: site.id, name, description, networks: site.networks })
if (typeof result === "string") { if (typeof result === "string") {
@ -41,10 +40,9 @@ export default function EditSite({ site, onSiteEdited }: EditSiteProps) {
} }
} catch (apiError) { } catch (apiError) {
setError(typeof apiError === "string" ? apiError : "Failed to edit site") setError(typeof apiError === "string" ? apiError : "Failed to edit site")
} } finally {
} catch (err) { setName("")
console.error("Error in handleEditSite:", err) setDescription("")
setError("Failed to edit site")
} }
} }