From a6ddc114d9a1a385ba0d1d996b755eb24dc0e105 Mon Sep 17 00:00:00 2001 From: Rohit Saluja Date: Tue, 26 Mar 2024 18:53:03 +0530 Subject: [PATCH] fix: a condition is added for the reason in the handler --- .../[id]/super-delete-document-dialog.tsx | 16 +++++++++------- 1 file changed, 9 insertions(+), 7 deletions(-) diff --git a/apps/web/src/app/(dashboard)/admin/documents/[id]/super-delete-document-dialog.tsx b/apps/web/src/app/(dashboard)/admin/documents/[id]/super-delete-document-dialog.tsx index 346a4eccc..6d89c7e7b 100644 --- a/apps/web/src/app/(dashboard)/admin/documents/[id]/super-delete-document-dialog.tsx +++ b/apps/web/src/app/(dashboard)/admin/documents/[id]/super-delete-document-dialog.tsx @@ -34,13 +34,15 @@ export const SuperDeleteDocumentDialog = ({ document }: SuperDeleteDocumentDialo const handleDeleteDocument = async () => { try { - await deleteDocument({ id: document.id, userId: document.userId, reason }); - toast({ - title: 'Document deleted', - description: 'The Document has been deleted successfully.', - duration: 5000, - }); - router.push('/admin/documents'); + if (reason) { + await deleteDocument({ id: document.id, userId: document.userId, reason }); + toast({ + title: 'Document deleted', + description: 'The Document has been deleted successfully.', + duration: 5000, + }); + router.push('/admin/documents'); + } } catch (err) { if (err instanceof TRPCClientError && err.data?.code === 'BAD_REQUEST') { toast({