ryoji-s 2 anni fa
parent
commit
9d5279567b

+ 2 - 7
apps/app/src/components/Sidebar/PageCreateButton.tsx

@@ -1,6 +1,5 @@
 import React, { useCallback, useState } from 'react';
 
-import { isCreatablePage } from '@growi/core/dist/utils/page-path-utils';
 import { useRouter } from 'next/router';
 
 import { apiv3Post } from '~/client/util/apiv3-client';
@@ -32,18 +31,14 @@ export const PageCreateButton = React.memo((): JSX.Element => {
     try {
       setIsCreating(true);
 
-      const parentPath = currentPage == null || isCreatablePage(currentPage.path)
+      const parentPath = currentPage == null
         ? '/'
         : currentPage.path;
 
       const response = await apiv3Post('/pages/', {
         path: parentPath,
-        body: undefined,
         grant: currentPage?.grant || 1,
-        grantUserGroupId: currentPage?.grantedGroup || null,
-        isSlackEnabled: false,
-        slackChannels: '',
-        pageTags: [],
+        grantUserGroupId: currentPage?.grantedGroup,
         shouldGeneratePath: true,
       });
 

+ 7 - 7
apps/app/src/server/routes/apiv3/pages.js

@@ -239,15 +239,11 @@ module.exports = (crowi) => {
     return [];
   }
 
-  async function checkIsPathExists(path) {
-    const Page = mongoose.model('Page');
-    const response = await Page.findByPath(path);
-    return response != null;
-  }
-
   async function generateUniquePath(basePath, index = 1) {
+    const Page = mongoose.model('Page');
     const path = basePath + index;
-    const isPathExists = await checkIsPathExists(path);
+    const response = await Page.findByPath(path);
+    const isPathExists = response != null;
     if (isPathExists) {
       return generateUniquePath(basePath, index + 1);
     }
@@ -325,6 +321,10 @@ module.exports = (crowi) => {
         const defaultTitle = '/Untitled';
         const basePath = path === rootPath ? defaultTitle : path + defaultTitle;
         path = await generateUniquePath(basePath);
+
+        if (!isCreatablePage(path)) {
+          path = await generateUniquePath(defaultTitle);
+        }
       }
       catch (err) {
         return res.apiv3Err(new ErrorV3('Failed to generate unique path'));