Skip to content

armgit / papra

Public Imported from GitHub
0

The minimalistic document archiving platform.

refactor(documents): added confirmation modal on document deletion (#64)

Corentin THOMASSET36cb2b1829a6
diff --git a/apps/papra-client/src/modules/documents/components/document-management-dropdown.component.tsx b/apps/papra-client/src/modules/documents/components/document-management-dropdown.component.tsx
index 717f521e..4e039504 100644
--- a/apps/papra-client/src/modules/documents/components/document-management-dropdown.component.tsx
+++ b/apps/papra-client/src/modules/documents/components/document-management-dropdown.component.tsx
@@ -1,5 +1,7 @@
import type { DropdownMenuSubTriggerProps } from '@kobalte/core/dropdown-menu';
import type { Component } from 'solid-js';
+import type { Document } from '../documents.types';
+import { useConfirmModal } from '@/modules/shared/confirm';
import { queryClient } from '@/modules/shared/query/query-client';
import { Button } from '@/modules/ui/components/button';
import { DropdownMenu, DropdownMenuContent, DropdownMenuItem, DropdownMenuTrigger } from '@/modules/ui/components/dropdown-menu';
@@ -7,14 +9,39 @@ import { createToast } from '@/modules/ui/components/sonner';
import { A } from '@solidjs/router';
import { deleteDocument } from '../documents.services';
-export const DocumentManagementDropdown: Component<{ documentId: string; organizationId: string }> = (props) => {
+export const DocumentManagementDropdown: Component<{ document: Document }> = (props) => {
+ const { confirm } = useConfirmModal();
+
const deleteDoc = async () => {
+ const isConfirmed = await confirm({
+ title: 'Delete document',
+ message: (
+ <>
+ Are you sure you want to delete
+ {' '}
+ <span class="font-bold">{props.document.name}</span>
+ ?
+ </>
+ ),
+ confirmButton: {
+ text: 'Delete document',
+ variant: 'destructive',
+ },
+ cancelButton: {
+ text: 'Cancel',
+ },
+ });
+
+ if (!isConfirmed) {
+ return;
+ }
+
await deleteDocument({
- documentId: props.documentId,
- organizationId: props.organizationId,
+ documentId: props.document.id,
+ organizationId: props.document.organizationId,
});
- await queryClient.invalidateQueries({ queryKey: ['organizations', props.organizationId, 'documents'] });
+ await queryClient.invalidateQueries({ queryKey: ['organizations', props.document.organizationId, 'documents'] });
createToast({ type: 'success', message: 'Document deleted' });
};
@@ -31,7 +58,7 @@ export const DocumentManagementDropdown: Component<{ documentId: string; organiz
<DropdownMenuItem
class="cursor-pointer "
as={A}
- href={`/organizations/${props.organizationId}/documents/${props.documentId}`}
+ href={`/organizations/${props.document.organizationId}/documents/${props.document.id}`}
>
<div class="i-tabler-info-circle size-4 mr-2"></div>
<span>Document details</span>
diff --git a/apps/papra-client/src/modules/documents/components/documents-list.component.tsx b/apps/papra-client/src/modules/documents/components/documents-list.component.tsx
index 0a8205c8..746d8f03 100644
--- a/apps/papra-client/src/modules/documents/components/documents-list.component.tsx
+++ b/apps/papra-client/src/modules/documents/components/documents-list.component.tsx
@@ -36,7 +36,7 @@ export const standardActionsColumn: ColumnDef<Document> = {
id: 'actions',
cell: data => (
<div class="flex items-center justify-end">
- <DocumentManagementDropdown documentId={data.row.original.id} organizationId={data.row.original.organizationId} />
+ <DocumentManagementDropdown document={data.row.original} />
</div>
),
};
diff --git a/apps/papra-client/src/modules/documents/pages/documents.page.tsx b/apps/papra-client/src/modules/documents/pages/documents.page.tsx
index 46f2d55f..e6ffb5fc 100644
--- a/apps/papra-client/src/modules/documents/pages/documents.page.tsx
+++ b/apps/papra-client/src/modules/documents/pages/documents.page.tsx
@@ -56,7 +56,7 @@ const DocumentCard: Component<{ document: Document; organizationId?: string }> =
</div>
<div>
- <DocumentManagementDropdown documentId={props.document.id} organizationId={getOrganizationId()} />
+ <DocumentManagementDropdown document={props.document} />
</div>
</div>
);