|
@@ -1,5 +1,6 @@
|
|
|
import { useCallback, useState } from 'react';
|
|
import { useCallback, useState } from 'react';
|
|
|
|
|
|
|
|
|
|
+import type { PageGrant, IGrantedGroup } from '@growi/core';
|
|
|
import { useRouter } from 'next/router';
|
|
import { useRouter } from 'next/router';
|
|
|
|
|
|
|
|
import { createPage, exist } from '~/client/services/page-operation';
|
|
import { createPage, exist } from '~/client/services/page-operation';
|
|
@@ -7,6 +8,8 @@ import { toastError } from '~/client/util/toastr';
|
|
|
|
|
|
|
|
export const useOnNewButtonClicked = (
|
|
export const useOnNewButtonClicked = (
|
|
|
currentPagePath?: string,
|
|
currentPagePath?: string,
|
|
|
|
|
+ currentPageGrant?: PageGrant,
|
|
|
|
|
+ currentPageGrantedGroups?: IGrantedGroup[],
|
|
|
isLoading?: boolean,
|
|
isLoading?: boolean,
|
|
|
): {
|
|
): {
|
|
|
onClickHandler: () => Promise<void>,
|
|
onClickHandler: () => Promise<void>,
|
|
@@ -21,19 +24,25 @@ export const useOnNewButtonClicked = (
|
|
|
try {
|
|
try {
|
|
|
setIsPageCreating(true);
|
|
setIsPageCreating(true);
|
|
|
|
|
|
|
|
- const parentPath = currentPagePath == null
|
|
|
|
|
|
|
+ /**
|
|
|
|
|
+ * !! NOTICE !! - Verification of page createable or not is checked on the server side.
|
|
|
|
|
+ * since the new page path is not generated on the client side.
|
|
|
|
|
+ * need shouldGeneratePath flag.
|
|
|
|
|
+ */
|
|
|
|
|
+ const shouldUseRootPath = currentPagePath == null || currentPageGrant == null;
|
|
|
|
|
+ const parentPath = shouldUseRootPath
|
|
|
? '/'
|
|
? '/'
|
|
|
: currentPagePath;
|
|
: currentPagePath;
|
|
|
|
|
|
|
|
const params = {
|
|
const params = {
|
|
|
isSlackEnabled: false,
|
|
isSlackEnabled: false,
|
|
|
slackChannels: '',
|
|
slackChannels: '',
|
|
|
- grant: 4,
|
|
|
|
|
- // grant: currentPage?.grant || 1,
|
|
|
|
|
- // grantUserGroupId: currentPage?.grantedGroup?._id,
|
|
|
|
|
|
|
+ grant: shouldUseRootPath ? 1 : currentPageGrant,
|
|
|
|
|
+ grantUserGroupIds: shouldUseRootPath ? undefined : currentPageGrantedGroups,
|
|
|
shouldGeneratePath: true,
|
|
shouldGeneratePath: true,
|
|
|
};
|
|
};
|
|
|
|
|
|
|
|
|
|
+ // !! NOTICE !! - if shouldGeneratePath is flagged, send the parent page path
|
|
|
const response = await createPage(parentPath, '', params);
|
|
const response = await createPage(parentPath, '', params);
|
|
|
|
|
|
|
|
router.push(`/${response.page.id}#edit`);
|
|
router.push(`/${response.page.id}#edit`);
|
|
@@ -44,7 +53,7 @@ export const useOnNewButtonClicked = (
|
|
|
finally {
|
|
finally {
|
|
|
setIsPageCreating(false);
|
|
setIsPageCreating(false);
|
|
|
}
|
|
}
|
|
|
- }, [currentPagePath, isLoading, router]);
|
|
|
|
|
|
|
+ }, [currentPageGrant, currentPageGrantedGroups, currentPagePath, isLoading, router]);
|
|
|
|
|
|
|
|
return { onClickHandler, isPageCreating };
|
|
return { onClickHandler, isPageCreating };
|
|
|
};
|
|
};
|