fix(frontend): handle credential deletion errors with toast feedback

handleDeleteConfirm now catches API errors and shows a destructive
toast instead of silently failing. It also checks for
need_confirmation responses when the credential is still in use.
This commit is contained in:
Zamil Majdy
2026-04-02 17:03:00 +02:00
parent a49ac5ba13
commit 9ab6082a23

View File

@@ -4,6 +4,7 @@ import {
BlockIOCredentialsSubSchema,
CredentialsMetaInput,
} from "@/lib/autogpt-server-api/types";
import { toast } from "@/components/molecules/Toast/use-toast";
import { postV2InitiateOauthLoginForAnMcpServer } from "@/app/api/__generated__/endpoints/mcp/mcp";
import {
OAUTH_ERROR_FLOW_CANCELED,
@@ -299,7 +300,7 @@ export function useCredentialsInput({
setCredentialToDelete(credential);
}
async function handleDeleteConfirm() {
async function handleDeleteConfirm(force: boolean = false) {
if (
!credentialToDelete ||
!credentials ||
@@ -309,11 +310,32 @@ export function useCredentialsInput({
setIsDeletingCredential(true);
try {
await credentials.deleteCredentials(credentialToDelete.id);
if (selectedCredential?.id === credentialToDelete.id) {
onSelectCredential(undefined);
const result = await credentials.deleteCredentials(
credentialToDelete.id,
force,
);
if (result.deleted) {
if (selectedCredential?.id === credentialToDelete.id) {
onSelectCredential(undefined);
}
setCredentialToDelete(null);
} else if ("need_confirmation" in result && result.need_confirmation) {
toast({
title: "Credential is in use",
description: result.message,
variant: "destructive",
duration: 8000,
});
}
setCredentialToDelete(null);
} catch (error) {
const message =
error instanceof Error ? error.message : "Something went wrong";
toast({
title: "Failed to delete credential",
description: message,
variant: "destructive",
});
} finally {
setIsDeletingCredential(false);
}