ryoji-s hace 2 años
padre
commit
79d438e1a9

+ 3 - 1
apps/app/src/components/Sidebar/PageCreateButton/PageCreateButton.tsx

@@ -35,7 +35,9 @@ export const PageCreateButton = React.memo((): JSX.Element => {
     ? null
     : generateTodaysPath(currentUser, t('create_page_dropdown.todays.memo'));
 
-  const { onClickHandler: onClickNewButton, isPageCreating: isNewPageCreating } = useOnNewButtonClicked(currentPage, isLoading);
+  const { onClickHandler: onClickNewButton, isPageCreating: isNewPageCreating } = useOnNewButtonClicked(
+    currentPage?.path, currentPage?.grant, currentPage?.grantedGroups, isLoading,
+  );
   // TODO: https://redmine.weseek.co.jp/issues/138806
   const { onClickHandler: onClickTodaysButton, isPageCreating: isTodaysPageCreating } = useOnTodaysButtonClicked(todaysPath);
   // TODO: https://redmine.weseek.co.jp/issues/138805

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

@@ -1,13 +1,15 @@
 import { useCallback, useState } from 'react';
 
-import type { IPagePopulatedToShowRevision } from '@growi/core';
+import type { PageGrant, IGrantedGroup } from '@growi/core';
 import { useRouter } from 'next/router';
 
 import { createPage, exist } from '~/client/services/page-operation';
 import { toastError } from '~/client/util/toastr';
 
 export const useOnNewButtonClicked = (
-    currentPage?: IPagePopulatedToShowRevision | null,
+    currentPagePath?: string,
+    currentPageGrant?: PageGrant,
+    currentPageGrantedGroups?: IGrantedGroup[],
     isLoading?: boolean,
 ): {
   onClickHandler: () => Promise<void>,
@@ -27,16 +29,16 @@ export const useOnNewButtonClicked = (
        * since the new page path is not generated on the client side.
        * need shouldGeneratePath flag.
        */
-      const shouldUseRootPath = currentPage?.path == null;
+      const shouldUseRootPath = currentPagePath == null || currentPageGrant == null;
       const parentPath = shouldUseRootPath
         ? '/'
-        : currentPage.path;
+        : currentPagePath;
 
       const params = {
         isSlackEnabled: false,
         slackChannels: '',
-        grant: shouldUseRootPath ? 1 : currentPage.grant,
-        grantUserGroupIds: shouldUseRootPath ? undefined : currentPage.grantedGroups,
+        grant: shouldUseRootPath ? 1 : currentPageGrant,
+        grantUserGroupIds: shouldUseRootPath ? undefined : currentPageGrantedGroups,
         shouldGeneratePath: true,
       };
 
@@ -51,7 +53,7 @@ export const useOnNewButtonClicked = (
     finally {
       setIsPageCreating(false);
     }
-  }, [currentPage, isLoading, router]);
+  }, [currentPageGrant, currentPageGrantedGroups, currentPagePath, isLoading, router]);
 
   return { onClickHandler, isPageCreating };
 };