mirror of
https://github.com/crocofied/CoreControl.git
synced 2025-12-29 16:14:43 +00:00
hooks promises
This commit is contained in:
@@ -26,16 +26,24 @@ export default function EditSite({ site, onSiteEdited }: EditSiteProps) {
|
||||
|
||||
const handleEditSite = async () => {
|
||||
try {
|
||||
const result = await editSite({ id: site.id, name, description, networks: site.networks })
|
||||
if (result) {
|
||||
const result = editSite({ id: site.id, name, description, networks: site.networks })
|
||||
|
||||
if (typeof result === "string") {
|
||||
setError(result)
|
||||
return
|
||||
}
|
||||
if (onSiteEdited) {
|
||||
onSiteEdited()
|
||||
setSuccess("Site edited successfully")
|
||||
|
||||
try {
|
||||
const successMessage = await result
|
||||
if (onSiteEdited && successMessage) {
|
||||
onSiteEdited()
|
||||
setSuccess(successMessage)
|
||||
}
|
||||
} catch (apiError) {
|
||||
setError(typeof apiError === "string" ? apiError : "Failed to edit site")
|
||||
}
|
||||
} catch (err) {
|
||||
console.error("Error in handleEditSite:", err)
|
||||
setError("Failed to edit site")
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user