feat(documents): delete document from context menu

This commit is contained in:
Ruslan Bakiev
2026-02-23 14:27:00 +07:00
parent 68cbe7bc64
commit 6ad53e64c5
4 changed files with 160 additions and 1 deletions

View File

@@ -25,6 +25,7 @@ import createCalendarEventMutation from "~~/graphql/operations/create-calendar-e
import archiveCalendarEventMutation from "~~/graphql/operations/archive-calendar-event.graphql?raw";
import createCommunicationMutation from "~~/graphql/operations/create-communication.graphql?raw";
import createWorkspaceDocumentMutation from "~~/graphql/operations/create-workspace-document.graphql?raw";
import deleteWorkspaceDocumentMutation from "~~/graphql/operations/delete-workspace-document.graphql?raw";
import updateCommunicationTranscriptMutation from "~~/graphql/operations/update-communication-transcript.graphql?raw";
import updateFeedDecisionMutation from "~~/graphql/operations/update-feed-decision.graphql?raw";
import chatConversationsQuery from "~~/graphql/operations/chat-conversations.graphql?raw";
@@ -3155,6 +3156,7 @@ const selectedContactRecentMessages = computed(() => {
const documentSearch = ref("");
const documentSortMode = ref<DocumentSortMode>("updatedAt");
const documentDeletingId = ref("");
const documentSortOptions: Array<{ value: DocumentSortMode; label: string }> = [
{ value: "updatedAt", label: "Updated" },
{ value: "title", label: "Title" },
@@ -3210,6 +3212,36 @@ function openDocumentsTab(push = false) {
syncPathFromUi(push);
}
async function deleteWorkspaceDocumentById(documentIdInput: string) {
const documentId = safeTrim(documentIdInput);
if (!documentId) return;
if (documentDeletingId.value === documentId) return;
const target = documents.value.find((doc) => doc.id === documentId);
const targetLabel = safeTrim(target?.title) || "this document";
if (process.client && !window.confirm(`Delete ${targetLabel}?`)) return;
documentDeletingId.value = documentId;
try {
await gqlFetch<{ deleteWorkspaceDocument: { ok: boolean; id: string } }>(deleteWorkspaceDocumentMutation, {
id: documentId,
});
documents.value = documents.value.filter((doc) => doc.id !== documentId);
clientTimelineItems.value = clientTimelineItems.value.filter((item) => {
const isDocumentEntry = String(item.contentType).toLowerCase() === "document";
if (!isDocumentEntry) return true;
return item.contentId !== documentId && item.document?.id !== documentId;
});
if (selectedDocumentId.value === documentId) {
selectedDocumentId.value = "";
}
} finally {
if (documentDeletingId.value === documentId) {
documentDeletingId.value = "";
}
}
}
const peopleListMode = ref<"contacts" | "deals">("contacts");
const peopleSearch = ref("");
const peopleSortMode = ref<PeopleSortMode>("lastContact");
@@ -5454,6 +5486,7 @@ async function decideFeedCard(card: FeedCard, decision: "accepted" | "rejected")
@update:document-sort-mode="documentSortMode = $event"
@select-document="selectedDocumentId = $event"
@update-selected-document-body="updateSelectedDocumentBody"
@delete-document="deleteWorkspaceDocumentById"
/>
<CrmChangeReviewOverlay