|
|
@@ -3,7 +3,7 @@ import { useCallback } from 'react';
|
|
|
import { useRouter } from 'next/router';
|
|
|
|
|
|
import { createPage } from '~/client/services/page-operation';
|
|
|
-import { useIsNotFound } from '~/stores/page';
|
|
|
+import { useIsNotFound, useSWRxCurrentPage } from '~/stores/page';
|
|
|
import { EditorMode, useEditorMode } from '~/stores/ui';
|
|
|
import loggerFactory from '~/utils/logger';
|
|
|
|
|
|
@@ -46,14 +46,27 @@ export const useCreatePageAndTransit = (): CreatePageAndTransit => {
|
|
|
const router = useRouter();
|
|
|
|
|
|
const { data: isNotFound } = useIsNotFound();
|
|
|
+ const { data: currentPage, isLoading } = useSWRxCurrentPage();
|
|
|
const { mutate: mutateEditorMode } = useEditorMode();
|
|
|
|
|
|
+ // const {
|
|
|
+ // path: currentPagePath,
|
|
|
+ // grant: currentPageGrant,
|
|
|
+ // grantedGroups: currentPageGrantedGroups,
|
|
|
+ // } = currentPage ?? {};
|
|
|
+
|
|
|
return useCallback(async(pagePath, opts = {}) => {
|
|
|
+ if (isLoading) {
|
|
|
+ return;
|
|
|
+ }
|
|
|
+
|
|
|
const {
|
|
|
onCreationStart, onCreated, onAborted, onError, onTerminated,
|
|
|
} = opts;
|
|
|
|
|
|
if (isNotFound == null || !isNotFound || pagePath == null) {
|
|
|
+ mutateEditorMode(EditorMode.Editor);
|
|
|
+
|
|
|
onAborted?.();
|
|
|
onTerminated?.();
|
|
|
return;
|
|
|
@@ -62,6 +75,27 @@ export const useCreatePageAndTransit = (): CreatePageAndTransit => {
|
|
|
try {
|
|
|
onCreationStart?.();
|
|
|
|
|
|
+ /**
|
|
|
+ * !! 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 shouldCreateUnderRoot = currentPagePath == null || currentPageGrant == null;
|
|
|
+ // const parentPath = shouldCreateUnderRoot
|
|
|
+ // ? '/'
|
|
|
+ // : currentPagePath;
|
|
|
+
|
|
|
+ // const params = {
|
|
|
+ // isSlackEnabled: false,
|
|
|
+ // slackChannels: '',
|
|
|
+ // grant: shouldCreateUnderRoot ? 1 : currentPageGrant,
|
|
|
+ // grantUserGroupIds: shouldCreateUnderRoot ? undefined : currentPageGrantedGroups,
|
|
|
+ // shouldGeneratePath: true,
|
|
|
+ // };
|
|
|
+
|
|
|
+ // !! NOTICE !! - if shouldGeneratePath is flagged, send the parent page path
|
|
|
+ // const response = await createPage(parentPath, '', params);
|
|
|
+
|
|
|
const params = {
|
|
|
isSlackEnabled: false,
|
|
|
slackChannels: '',
|
|
|
@@ -85,5 +119,5 @@ export const useCreatePageAndTransit = (): CreatePageAndTransit => {
|
|
|
onTerminated?.();
|
|
|
}
|
|
|
|
|
|
- }, [isNotFound, mutateEditorMode, router]);
|
|
|
+ }, [isLoading, isNotFound, mutateEditorMode, router]);
|
|
|
};
|