From d8911ee97b30c412b84d11a079adedb0f7cb5f55 Mon Sep 17 00:00:00 2001 From: Rohit Saluja Date: Tue, 12 Mar 2024 20:16:48 +0530 Subject: [PATCH] feat: added the dialog delete file --- .../documents/[id]/delete-document-dialog.tsx | 113 +++++++++++++++++- 1 file changed, 112 insertions(+), 1 deletion(-) diff --git a/apps/web/src/app/(dashboard)/admin/documents/[id]/delete-document-dialog.tsx b/apps/web/src/app/(dashboard)/admin/documents/[id]/delete-document-dialog.tsx index 339659ccc..aacb49d65 100644 --- a/apps/web/src/app/(dashboard)/admin/documents/[id]/delete-document-dialog.tsx +++ b/apps/web/src/app/(dashboard)/admin/documents/[id]/delete-document-dialog.tsx @@ -1,11 +1,122 @@ 'use client'; +import { useState } from 'react'; + +import { useRouter } from 'next/navigation'; + import type { Document } from '@documenso/prisma/client'; +import { TRPCClientError } from '@documenso/trpc/client'; +import { trpc } from '@documenso/trpc/react'; +import { Alert, AlertDescription, AlertTitle } from '@documenso/ui/primitives/alert'; +import { Button } from '@documenso/ui/primitives/button'; +import { + Dialog, + DialogContent, + DialogDescription, + DialogFooter, + DialogHeader, + DialogTitle, + DialogTrigger, +} from '@documenso/ui/primitives/dialog'; +import { Input } from '@documenso/ui/primitives/input'; +import { useToast } from '@documenso/ui/primitives/use-toast'; export type DeleteDocumentDialogProps = { document: Document; }; export const DeleteDocumentDialog = ({ document }: DeleteDocumentDialogProps) => { - return
; + const router = useRouter(); + const { toast } = useToast(); + const [reason, setReason] = useState(''); + const { mutateAsync: deleteDocument, isLoading: isDeletingDocument } = + trpc.admin.deleteDocument.useMutation(); + + const handleDeleteDocument = async () => { + try { + await deleteDocument({ id: 1, userId: 1 }); + 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({ + title: 'An error occurred', + description: err.message, + variant: 'destructive', + }); + } else { + toast({ + title: 'An unknown error occurred', + variant: 'destructive', + description: + err.message ?? + 'We encountered an unknown error while attempting to delete your document. Please try again later.', + }); + } + } + }; + + return ( +
+
+ +
+ Delete Account + + Delete the users account and all its contents. This action is irreversible and will + cancel their subscription, so proceed with caution. + +
+ +
+ + + + + + + + Delete Account + + + + This action is not reversible. Please be certain. + + + + +
+ To confirm, please the reason + + setReason(e.target.value)} + /> +
+ + + + +
+
+
+
+
+
+ ); };