Browse Source

fix pagePathRenameHandler

kosei-n 2 years ago
parent
commit
73994b4aff
1 changed files with 10 additions and 6 deletions
  1. 10 6
      apps/app/src/components/PageHeader/page-header-utils.ts

+ 10 - 6
apps/app/src/components/PageHeader/page-header-utils.ts

@@ -21,6 +21,10 @@ export const usePagePathRenameHandler = (
 
   const pagePathRenameHandler = useCallback(async(newPagePath, onRenameFinish, onRenameFailure) => {
 
+    if (currentPage == null) {
+      return;
+    }
+
     const onRenamed = (fromPath: string | undefined, toPath: string) => {
       mutatePageTree();
       mutatePageList();
@@ -30,30 +34,30 @@ export const usePagePathRenameHandler = (
       }
     };
 
-    if (newPagePath === currentPage?.path || newPagePath === '') {
+    if (newPagePath === currentPage.path || newPagePath === '') {
       onRenameFinish?.();
       return;
     }
 
     try {
       await apiv3Put('/pages/rename', {
-        pageId: currentPage?._id,
-        revisionId: currentPage?.revision._id,
+        pageId: currentPage._id,
+        revisionId: currentPage.revision._id,
         newPagePath,
       });
 
-      onRenamed(currentPage?.path, newPagePath);
+      onRenamed(currentPage.path, newPagePath);
       onRenameFinish?.();
 
       onRenameFinish?.();
 
-      toastSuccess(t('renamed_pages', { path: currentPage?.path }));
+      toastSuccess(t('renamed_pages', { path: currentPage.path }));
     }
     catch (err) {
       onRenameFailure?.();
       toastError(err);
     }
-  }, [currentPage?._id, currentPage?.path, currentPage?.revision._id, currentPagePath, mutateCurrentPage, t]);
+  }, [currentPage, currentPagePath, mutateCurrentPage, t]);
 
   return pagePathRenameHandler;
 };