Skip to content

fix(site): Display delete template error from the API #6589

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
Mar 14, 2023
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
fix(site): Display delete template error from the API
  • Loading branch information
BrunoQuaresma committed Mar 13, 2023
commit 9c0ee4b5e752ee908767eaa0822981a58820caed
13 changes: 10 additions & 3 deletions site/src/components/TemplateLayout/deleteTemplate.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
import { deleteTemplate } from "api/api"
import { getErrorMessage } from "api/errors"
import { Template } from "api/typesGenerated"
import { displayError } from "components/GlobalSnackbar/utils"
import { useState } from "react"

type DeleteTemplateState =
Expand All @@ -21,9 +23,14 @@ export const useDeleteTemplate = (template: Template, onDelete: () => void) => {
}

const confirmDelete = async () => {
setState({ status: "deleting" })
await deleteTemplate(template.id)
onDelete()
try {
setState({ status: "deleting" })
await deleteTemplate(template.id)
onDelete()
} catch (e) {
setState({ status: "confirming" })
displayError(getErrorMessage(e, "Failed to delete template"))
}
}

return {
Expand Down