diff --git a/app/actions/definitions/templates.tsx b/app/actions/definitions/templates.tsx
new file mode 100644
index 0000000000..8f57d2fdc6
--- /dev/null
+++ b/app/actions/definitions/templates.tsx
@@ -0,0 +1,57 @@
+import { TrashIcon } from "outline-icons";
+import * as React from "react";
+import { Trans } from "react-i18next";
+import { toast } from "sonner";
+import ConfirmationDialog from "~/components/ConfirmationDialog";
+import { createAction } from "~/actions";
+import { TemplateSection } from "../sections";
+
+export const deleteTemplate = createAction({
+ name: ({ t }) => `${t("Delete")}…`,
+ analyticsName: "Delete template",
+ section: TemplateSection,
+ icon: ,
+ dangerous: true,
+ visible: ({ activeTemplateId, stores }) => {
+ if (!activeTemplateId) {
+ return false;
+ }
+ return !!stores.policies.abilities(activeTemplateId).delete;
+ },
+ perform: ({ activeTemplateId, stores, t }) => {
+ if (activeTemplateId) {
+ const template = stores.templates.get(activeTemplateId);
+ if (!template) {
+ return;
+ }
+
+ stores.dialogs.openModal({
+ title: t("Delete {{ documentName }}", {
+ documentName: t("template"),
+ }),
+ content: (
+ {
+ await template.delete();
+ toast.success(t("Template deleted"));
+ }}
+ savingText={`${t("Deleting")}…`}
+ danger
+ >
+ ,
+ }}
+ />
+
+ ),
+ });
+ }
+ },
+});
+
+export const rootTemplateActions = [];
diff --git a/app/actions/root.ts b/app/actions/root.ts
index 7d64029a65..f31c95761e 100644
--- a/app/actions/root.ts
+++ b/app/actions/root.ts
@@ -6,16 +6,18 @@ import { rootNotificationActions } from "./definitions/notifications";
import { rootRevisionActions } from "./definitions/revisions";
import { rootSettingsActions } from "./definitions/settings";
import { rootTeamActions } from "./definitions/teams";
+import { rootTemplateActions } from "./definitions/templates";
import { rootUserActions } from "./definitions/users";
export default [
...rootCollectionActions,
+ ...rootDeveloperActions,
...rootDocumentActions,
- ...rootUserActions,
...rootNavigationActions,
...rootNotificationActions,
...rootRevisionActions,
...rootSettingsActions,
- ...rootDeveloperActions,
...rootTeamActions,
+ ...rootTemplateActions,
+ ...rootUserActions,
];
diff --git a/app/actions/sections.ts b/app/actions/sections.ts
index 2046eb3d52..5201f17cc7 100644
--- a/app/actions/sections.ts
+++ b/app/actions/sections.ts
@@ -42,6 +42,8 @@ UserSection.priority = 0.5;
export const TeamSection = ({ t }: ActionContext) => t("Workspace");
+export const TemplateSection = ({ t }: ActionContext) => t("Template");
+
export const RecentSearchesSection = ({ t }: ActionContext) =>
t("Recent searches");
diff --git a/app/menus/TemplateMenu.tsx b/app/menus/TemplateMenu.tsx
index ef607f0eb6..1d9ff5dd28 100644
--- a/app/menus/TemplateMenu.tsx
+++ b/app/menus/TemplateMenu.tsx
@@ -1,28 +1,34 @@
import { observer } from "mobx-react";
-import { DuplicateIcon, EditIcon, TrashIcon } from "outline-icons";
+import { DuplicateIcon, EditIcon } from "outline-icons";
import * as React from "react";
import { useTranslation } from "react-i18next";
-import { useHistory } from "react-router-dom";
import { useMenuState } from "reakit/Menu";
import Template from "~/models/Template";
import ContextMenu from "~/components/ContextMenu";
import OverflowMenuButton from "~/components/ContextMenu/OverflowMenuButton";
import ContextMenuTemplate from "~/components/ContextMenu/Template";
+import { actionToMenuItem } from "~/actions";
+import { deleteTemplate } from "~/actions/definitions/templates";
+import useActionContext from "~/hooks/useActionContext";
import usePolicy from "~/hooks/usePolicy";
import useStores from "~/hooks/useStores";
type Props = {
template: Template;
+ onEdit?: () => void;
};
-function TemplateMenu({ template }: Props) {
+function TemplateMenu({ template, onEdit }: Props) {
const menu = useMenuState({
modal: true,
});
const { templates } = useStores();
const { t } = useTranslation();
- const history = useHistory();
const can = usePolicy(template);
+ const context = useActionContext({
+ isContextMenu: true,
+ activeTemplateId: template.id,
+ });
return (
<>
@@ -33,10 +39,10 @@ function TemplateMenu({ template }: Props) {
items={[
{
type: "button",
- title: t("Edit"),
+ title: `${t("Edit")}…`,
visible: !!can.update,
icon: ,
- onClick: () => history.push(`/settings/templates/${template.id}`),
+ onClick: () => onEdit?.(),
},
{
type: "button",
@@ -48,14 +54,7 @@ function TemplateMenu({ template }: Props) {
{
type: "separator",
},
- {
- type: "button",
- title: `${t("Delete")}…`,
- visible: !!can.delete,
- icon: ,
- dangerous: true,
- onClick: () => templates.delete(template),
- },
+ actionToMenuItem(deleteTemplate, context),
]}
/>
diff --git a/app/scenes/Settings/components/TemplatesTable.tsx b/app/scenes/Settings/components/TemplatesTable.tsx
index 7a6970883b..01ed6d95ba 100644
--- a/app/scenes/Settings/components/TemplatesTable.tsx
+++ b/app/scenes/Settings/components/TemplatesTable.tsx
@@ -104,7 +104,9 @@ export function TemplatesTable(props: Props) {
{
type: "action",
id: "action",
- component: (template) => ,
+ component: (template) => (
+
+ ),
width: "50px",
},
]),
diff --git a/app/types.ts b/app/types.ts
index a940e08cdc..32ac434f32 100644
--- a/app/types.ts
+++ b/app/types.ts
@@ -87,8 +87,10 @@ export type ActionContext = {
isCommandBar: boolean;
isButton: boolean;
sidebarContext?: SidebarContextType;
+ // TODO: Refactor this to data structure of active models
activeCollectionId?: string | undefined;
activeDocumentId: string | undefined;
+ activeTemplateId: string | undefined;
currentUserId: string | undefined;
currentTeamId: string | undefined;
location: Location;
diff --git a/shared/i18n/locales/en_US/translation.json b/shared/i18n/locales/en_US/translation.json
index 1cde7ba6f6..834d2c5176 100644
--- a/shared/i18n/locales/en_US/translation.json
+++ b/shared/i18n/locales/en_US/translation.json
@@ -130,6 +130,9 @@
"New workspace": "New workspace",
"Create a workspace": "Create a workspace",
"Login to workspace": "Login to workspace",
+ "Template deleted": "Template deleted",
+ "Deleting": "Deleting",
+ "Are you sure about that? Deleting the {{ templateName }} template is permanent.": "Are you sure about that? Deleting the {{ templateName }} template is permanent.",
"Invite people": "Invite people",
"Invite to workspace": "Invite to workspace",
"Promote to {{ role }}": "Promote to {{ role }}",
@@ -147,6 +150,7 @@
"Notification": "Notification",
"People": "People",
"Workspace": "Workspace",
+ "Template": "Template",
"Recent searches": "Recent searches",
"currently editing": "currently editing",
"currently viewing": "currently viewing",
@@ -164,7 +168,6 @@
"Create": "Create",
"Collection deleted": "Collection deleted",
"I’m sure – Delete": "I’m sure – Delete",
- "Deleting": "Deleting",
"Are you sure about that? Deleting the {{collectionName}} collection is permanent and cannot be restored, however all published documents within will be moved to the trash.": "Are you sure about that? Deleting the {{collectionName}} collection is permanent and cannot be restored, however all published documents within will be moved to the trash.",
"Also, {{collectionName}} is being used as the start view – deleting it will reset the start view to the Home page.": "Also, {{collectionName}} is being used as the start view – deleting it will reset the start view to the Home page.",
"Sorry, an error occurred saving the collection": "Sorry, an error occurred saving the collection",