From e5e405a26c0f15b86a8fab441084d016a37226fb Mon Sep 17 00:00:00 2001 From: Aamir Azad Date: Thu, 11 Jul 2024 13:29:07 -0400 Subject: [PATCH] Delete status tost as well as document delete logic --- src/components/audio-preview.tsx | 13 +++++++++++- src/components/document-viewer.tsx | 33 ++++++++++++++++++++++++++++++ 2 files changed, 45 insertions(+), 1 deletion(-) diff --git a/src/components/audio-preview.tsx b/src/components/audio-preview.tsx index 971bbba..d031476 100644 --- a/src/components/audio-preview.tsx +++ b/src/components/audio-preview.tsx @@ -29,6 +29,7 @@ import { TooltipProvider, TooltipTrigger, } from "@/components/ui/tooltip"; +import { toast } from "sonner"; const queryClient = new QueryClient(); @@ -249,9 +250,19 @@ function AudioInfo({ id }: AudioInfoProps) { Cancel { - await deleteWhishperRecording( + const response = await deleteWhishperRecording( `${userData.whishperURL}/api/transcriptions/${id}`, ); + if (response.ok) { + toast("Recording deleted", { + description: "The recording has been deleted.", + }); + } else { + toast("Error deleting recording", { + description: + "An error occurred while deleting the recording.", + }); + } }} > Continue diff --git a/src/components/document-viewer.tsx b/src/components/document-viewer.tsx index 8b31740..8d45381 100644 --- a/src/components/document-viewer.tsx +++ b/src/components/document-viewer.tsx @@ -97,6 +97,39 @@ const fetchUserData = async (): Promise => { return data; }; +async function deleteDocument(documentId: number) { + const userData = await getUserData(); + if (!userData) { + console.error("Error getting user data"); + return; + } + const body = { + documents: [documentId], + method: "delete", + }; + try { + const response = await fetch( + `${userData.paperlessURL}/api/documents/bulk_edit/ `, + { + method: "POST", + headers: { + "Content-Type": "application/json", + Authorization: `Token ${userData.paperlessToken}`, + }, + body: JSON.stringify(body), + }, + ); + if (!response.ok) { + console.error("Failed to delete document"); + return; + } + console.log("Document deleted successfully"); + } catch (error) { + console.error("Error deleting document:", error); + return null; + } +} + function DocumentViewer(props: { id: number }) { const router = useRouter();