feat: add "Copy document" dialog (#6009)
This commit is contained in:
@@ -9,7 +9,6 @@ import { DateFilter, NavigationNode, PublicTeam } from "@shared/types";
|
||||
import { subtractDate } from "@shared/utils/date";
|
||||
import { bytesToHumanReadable } from "@shared/utils/files";
|
||||
import naturalSort from "@shared/utils/naturalSort";
|
||||
import { DocumentValidation } from "@shared/validations";
|
||||
import RootStore from "~/stores/RootStore";
|
||||
import Store from "~/stores/base/Store";
|
||||
import Document from "~/models/Document";
|
||||
@@ -558,26 +557,21 @@ export default class DocumentsStore extends Store<Document> {
|
||||
};
|
||||
|
||||
@action
|
||||
duplicate = async (document: Document): Promise<Document> => {
|
||||
const append = " (duplicate)";
|
||||
const res = await client.post("/documents.create", {
|
||||
publish: document.isTemplate,
|
||||
parentDocumentId: null,
|
||||
collectionId: document.isTemplate ? document.collectionId : null,
|
||||
template: document.isTemplate,
|
||||
title: `${document.title.slice(
|
||||
0,
|
||||
DocumentValidation.maxTitleLength - append.length
|
||||
)}${append}`,
|
||||
text: document.text,
|
||||
duplicate = async (
|
||||
document: Document,
|
||||
options?: {
|
||||
title?: string;
|
||||
recursive?: boolean;
|
||||
}
|
||||
): Promise<Document[]> => {
|
||||
const res = await client.post("/documents.duplicate", {
|
||||
id: document.id,
|
||||
...options,
|
||||
});
|
||||
invariant(res?.data, "Data should be available");
|
||||
const collection = this.getCollectionForDocument(document);
|
||||
if (collection) {
|
||||
await collection.refresh();
|
||||
}
|
||||
|
||||
this.addPolicies(res.policies);
|
||||
return this.add(res.data);
|
||||
return res.data.documents.map(this.add);
|
||||
};
|
||||
|
||||
@action
|
||||
|
||||
Reference in New Issue
Block a user