fix: Handle template delete and error cases

This commit is contained in:
Tom Moor
2026-02-22 16:54:14 -05:00
parent 86a106e8e9
commit ccde98ce82
3 changed files with 16 additions and 2 deletions
+8 -1
View File
@@ -18,7 +18,13 @@ import {
createActionWithChildren,
createInternalLinkAction,
} from "~/actions";
import { newDocumentPath, newTemplatePath, urlify } from "~/utils/routeHelpers";
import history from "~/utils/history";
import {
newDocumentPath,
newTemplatePath,
settingsPath,
urlify,
} from "~/utils/routeHelpers";
import { ActiveTemplateSection, TemplateSection } from "../sections";
import Template from "~/models/Template";
import { AvatarSize } from "~/components/Avatar";
@@ -57,6 +63,7 @@ export const deleteTemplate = createAction({
<ConfirmationDialog
onSubmit={async () => {
await template.delete();
history.push(settingsPath("templates"));
toast.success(t("Template deleted"));
}}
savingText={`${t("Deleting")}`}
+6 -1
View File
@@ -10,6 +10,7 @@ import Breadcrumb from "~/components/Breadcrumb";
import Button from "~/components/Button";
import CollectionIcon from "~/components/Icons/CollectionIcon";
import LoadingIndicator from "~/components/LoadingIndicator";
import Error404 from "~/scenes/Errors/Error404";
import Scene from "~/components/Scene";
import { TemplateForm } from "~/components/Template/TemplateForm";
import { createInternalLinkAction } from "~/actions";
@@ -29,7 +30,7 @@ const LoadingState = observer(function LoadingState() {
const { id } = useParams<{ id: string }>();
const { templates, ui } = useStores();
const template = templates.get(id);
const { request } = useRequest(() => templates.fetch(id));
const { request, error } = useRequest(() => templates.fetch(id));
useEffect(() => {
if (!template) {
@@ -46,6 +47,10 @@ const LoadingState = observer(function LoadingState() {
};
}, [template, ui]);
if (error) {
return <Error404 />;
}
if (!template) {
return <LoadingIndicator />;
}
+2
View File
@@ -479,6 +479,7 @@ export class ProsemirrorHelper {
node.attrs.href = env.URL + node.attrs.href;
}
if (node.content) {
node.content = node.content.filter(Boolean);
node.content.forEach(replace);
}
@@ -502,6 +503,7 @@ export class ProsemirrorHelper {
}
if (node.content) {
node.content = node.content.filter(Boolean);
node.content.forEach(replace);
}