diff --git a/app/actions/definitions/documents.tsx b/app/actions/definitions/documents.tsx
index 9768de49d3..abd84f40d1 100644
--- a/app/actions/definitions/documents.tsx
+++ b/app/actions/definitions/documents.tsx
@@ -16,6 +16,7 @@ import * as React from "react";
import { Trans } from "react-i18next";
import getDataTransferFiles from "@shared/utils/getDataTransferFiles";
import ConfirmationDialog from "~/components/ConfirmationDialog";
+import DocumentTemplatizeDialog from "~/components/DocumentTemplatizeDialog";
import { createAction } from "~/actions";
import { DocumentSection } from "~/actions/sections";
import history from "~/utils/history";
@@ -312,44 +313,13 @@ export const createTemplate = createAction({
if (!activeDocumentId) {
return;
}
- const document = stores.documents.get(activeDocumentId);
- if (!document) {
- return;
- }
event?.preventDefault();
event?.stopPropagation();
stores.dialogs.openModal({
title: t("Create template"),
isCentered: true,
- content: (
- {
- const template = await document?.templatize();
- if (template) {
- history.push(documentUrl(template));
- stores.toasts.showToast(
- t("Template created, go ahead and customize it"),
- {
- type: "info",
- }
- );
- }
- }}
- submitText={t("Create template")}
- savingText={`${t("Creating")}…`}
- >
- ,
- }}
- />
-
- ),
+ content: ,
});
},
});
diff --git a/app/components/DocumentTemplatizeDialog.tsx b/app/components/DocumentTemplatizeDialog.tsx
new file mode 100644
index 0000000000..873f9f1783
--- /dev/null
+++ b/app/components/DocumentTemplatizeDialog.tsx
@@ -0,0 +1,53 @@
+import invariant from "invariant";
+import { observer } from "mobx-react";
+import * as React from "react";
+import { useTranslation, Trans } from "react-i18next";
+import { useHistory } from "react-router-dom";
+import ConfirmationDialog from "~/components/ConfirmationDialog";
+import useStores from "~/hooks/useStores";
+import useToasts from "~/hooks/useToasts";
+import { documentUrl } from "~/utils/routeHelpers";
+
+type Props = {
+ documentId: string;
+};
+
+function DocumentTemplatizeDialog({ documentId }: Props) {
+ // const [isSaving, setIsSaving] = useState();
+ const history = useHistory();
+ const { showToast } = useToasts();
+ const { t } = useTranslation();
+ const { documents } = useStores();
+ const document = documents.get(documentId);
+ invariant(document, "Document must exist");
+
+ const handleSubmit = React.useCallback(async () => {
+ const template = await document?.templatize();
+ if (template) {
+ history.push(documentUrl(template));
+ showToast(t("Template created, go ahead and customize it"), {
+ type: "info",
+ });
+ }
+ }, [document, showToast, history, t]);
+
+ return (
+
+ ,
+ }}
+ />
+
+ );
+}
+
+export default observer(DocumentTemplatizeDialog);
diff --git a/shared/i18n/locales/en_US/translation.json b/shared/i18n/locales/en_US/translation.json
index 5f506cf2dd..bfe5048e76 100644
--- a/shared/i18n/locales/en_US/translation.json
+++ b/shared/i18n/locales/en_US/translation.json
@@ -25,9 +25,6 @@
"Import document": "Import document",
"Templatize": "Templatize",
"Create template": "Create template",
- "Template created, go ahead and customize it": "Template created, go ahead and customize it",
- "Creating": "Creating",
- "Creating a template from {{titleWithDefault}} is a non-destructive action – we'll make a copy of the document and turn it into a template that can be used as a starting point for new documents.": "Creating a template from {{titleWithDefault}} is a non-destructive action – we'll make a copy of the document and turn it into a template that can be used as a starting point for new documents.",
"Search documents for \"{{searchQuery}}\"": "Search documents for \"{{searchQuery}}\"",
"Home": "Home",
"Drafts": "Drafts",
@@ -100,6 +97,9 @@
"{{ completed }} task done": "{{ completed }} task done",
"{{ completed }} task done_plural": "{{ completed }} tasks done",
"{{ completed }} of {{ total }} tasks": "{{ completed }} of {{ total }} tasks",
+ "Template created, go ahead and customize it": "Template created, go ahead and customize it",
+ "Creating": "Creating",
+ "Creating a template from {{titleWithDefault}} is a non-destructive action – we'll make a copy of the document and turn it into a template that can be used as a starting point for new documents.": "Creating a template from {{titleWithDefault}} is a non-destructive action – we'll make a copy of the document and turn it into a template that can be used as a starting point for new documents.",
"Currently editing": "Currently editing",
"Currently viewing": "Currently viewing",
"Viewed {{ timeAgo }} ago": "Viewed {{ timeAgo }} ago",