Shun Miyazawa 3 лет назад
Родитель
Сommit
da6b36532c

+ 18 - 0
packages/app/src/components/NotCreatablePage.tsx

@@ -0,0 +1,18 @@
+import React, { FC } from 'react';
+
+import { useTranslation } from 'next-i18next';
+
+export const NotCreatablePage: FC = () => {
+  const { t } = useTranslation();
+
+  return (
+    <div className="row not-found-message-row">
+      <div className="col-md-12">
+        <h2 className="text-muted">
+          <i className="icon-ban mr-1" aria-hidden="true"></i>
+          { t('not_creatable_page.could_not_creata_path') }
+        </h2>
+      </div>
+    </div>
+  );
+};

+ 3 - 19
packages/app/src/components/Page/DisplaySwitcher.tsx

@@ -16,6 +16,7 @@ import { EditorMode, useEditorMode } from '~/stores/ui';
 
 import CountBadge from '../Common/CountBadge';
 import PageListIcon from '../Icons/PageListIcon';
+import { NotCreatablePage } from '../NotCreatablePage';
 import NotFoundPage from '../NotFoundPage';
 import { Page } from '../Page';
 // import PageEditor from '../PageEditor';
@@ -58,24 +59,6 @@ const DisplaySwitcher = (): JSX.Element => {
 
   const revision = currentPage?.revision;
 
-  const renderNotFoundPage = () => {
-    if (isNotFound && isNotCreatable) {
-      return (
-        <div className="row not-found-message-row">
-          <div className="col-md-12">
-            <h2 className="text-muted">
-              <i className="icon-ban" aria-hidden="true"></i>
-                Couldn&apos;t create path
-            </h2>
-          </div>
-        </div>
-      );
-    }
-    if (isNotFound) {
-      return <NotFoundPage />;
-    }
-  };
-
   return (
     <>
       <TabContent activeTab={editorMode}>
@@ -134,7 +117,8 @@ const DisplaySwitcher = (): JSX.Element => {
             <div className="flex-grow-1 flex-basis-0 mw-0">
               { isUserPage && <UserInfo pageUser={pageUser} />}
               { !isNotFound && <Page /> }
-              { renderNotFoundPage() }
+              { isNotFound && !isNotCreatable && <NotFoundPage /> }
+              { isNotFound && isNotCreatable && <NotCreatablePage /> }
             </div>
 
           </div>

+ 2 - 5
packages/app/src/pages/[[...path]].page.tsx

@@ -357,14 +357,11 @@ async function injectRoutingInformation(context: GetServerSidePropsContext, prop
   else if (page == null) {
     props.isNotFound = true;
 
+    props.IsNotCreatable = !isCreatablePage(currentPathname);
+
     // check the page is forbidden or just does not exist.
     const count = isPermalink ? await Page.count({ _id: pageId }) : await Page.count({ path: currentPathname });
     props.isForbidden = count > 0;
-
-    if (!isCreatablePage(currentPathname)) {
-      props.IsNotCreatable = true;
-    }
-
   }
   else {
     // /62a88db47fed8b2d94f30000 ==> /path/to/page