|
@@ -9,6 +9,7 @@ import {
|
|
|
import { useTranslation } from 'react-i18next';
|
|
import { useTranslation } from 'react-i18next';
|
|
|
|
|
|
|
|
import { debounce } from 'throttle-debounce';
|
|
import { debounce } from 'throttle-debounce';
|
|
|
|
|
+import { pagePathUtils } from '@growi/core';
|
|
|
import { usePageRenameModal } from '~/stores/modal';
|
|
import { usePageRenameModal } from '~/stores/modal';
|
|
|
import { toastError } from '~/client/util/apiNotification';
|
|
import { toastError } from '~/client/util/apiNotification';
|
|
|
|
|
|
|
@@ -29,6 +30,7 @@ const isV5Compatible = (meta: unknown): boolean => {
|
|
|
const PageRenameModal = (): JSX.Element => {
|
|
const PageRenameModal = (): JSX.Element => {
|
|
|
const { t } = useTranslation();
|
|
const { t } = useTranslation();
|
|
|
|
|
|
|
|
|
|
+ const { isUsersHomePage } = pagePathUtils;
|
|
|
const { data: siteUrl } = useSiteUrl();
|
|
const { data: siteUrl } = useSiteUrl();
|
|
|
const { data: renameModalData, close: closeRenameModal } = usePageRenameModal();
|
|
const { data: renameModalData, close: closeRenameModal } = usePageRenameModal();
|
|
|
|
|
|
|
@@ -53,6 +55,7 @@ const PageRenameModal = (): JSX.Element => {
|
|
|
const [isRemainMetadata, setIsRemainMetadata] = useState(false);
|
|
const [isRemainMetadata, setIsRemainMetadata] = useState(false);
|
|
|
const [expandOtherOptions, setExpandOtherOptions] = useState(false);
|
|
const [expandOtherOptions, setExpandOtherOptions] = useState(false);
|
|
|
const [subordinatedError] = useState(null);
|
|
const [subordinatedError] = useState(null);
|
|
|
|
|
+ const [isMatchedWithUserHomePagePath, setIsMatchedWithUserHomePagePath] = useState(false);
|
|
|
|
|
|
|
|
const updateSubordinatedList = useCallback(async() => {
|
|
const updateSubordinatedList = useCallback(async() => {
|
|
|
if (page == null) {
|
|
if (page == null) {
|
|
@@ -135,11 +138,21 @@ const PageRenameModal = (): JSX.Element => {
|
|
|
return debounce(1000, checkExistPaths);
|
|
return debounce(1000, checkExistPaths);
|
|
|
}, [checkExistPaths]);
|
|
}, [checkExistPaths]);
|
|
|
|
|
|
|
|
|
|
+ const checkIsUsersHomePageDebounce = useMemo(() => {
|
|
|
|
|
+ const checkIsPagePathRenameable = () => {
|
|
|
|
|
+ setIsMatchedWithUserHomePagePath(isUsersHomePage(pageNameInput));
|
|
|
|
|
+ };
|
|
|
|
|
+
|
|
|
|
|
+ return debounce(1000, checkIsPagePathRenameable);
|
|
|
|
|
+ }, [isUsersHomePage, pageNameInput]);
|
|
|
|
|
+
|
|
|
useEffect(() => {
|
|
useEffect(() => {
|
|
|
if (page != null && pageNameInput !== page.data.path) {
|
|
if (page != null && pageNameInput !== page.data.path) {
|
|
|
checkExistPathsDebounce(page.data.path, pageNameInput);
|
|
checkExistPathsDebounce(page.data.path, pageNameInput);
|
|
|
|
|
+ checkIsUsersHomePageDebounce(pageNameInput);
|
|
|
}
|
|
}
|
|
|
- }, [pageNameInput, subordinatedPages, checkExistPathsDebounce, page]);
|
|
|
|
|
|
|
+ }, [pageNameInput, subordinatedPages, checkExistPathsDebounce, page, checkIsUsersHomePageDebounce]);
|
|
|
|
|
+
|
|
|
|
|
|
|
|
/**
|
|
/**
|
|
|
* change pageNameInput
|
|
* change pageNameInput
|
|
@@ -176,9 +189,18 @@ const PageRenameModal = (): JSX.Element => {
|
|
|
const { path } = page.data;
|
|
const { path } = page.data;
|
|
|
const isTargetPageDuplicate = existingPaths.includes(pageNameInput);
|
|
const isTargetPageDuplicate = existingPaths.includes(pageNameInput);
|
|
|
|
|
|
|
|
- const submitButtonDisabled = isV5Compatible(page.meta)
|
|
|
|
|
- ? existingPaths.length !== 0 // v5 data
|
|
|
|
|
- : !isRenameRecursively; // v4 data
|
|
|
|
|
|
|
+ let submitButtonDisabled = false;
|
|
|
|
|
+
|
|
|
|
|
+ if (isMatchedWithUserHomePagePath) {
|
|
|
|
|
+ submitButtonDisabled = true;
|
|
|
|
|
+ }
|
|
|
|
|
+ else if (isV5Compatible(page.meta)) {
|
|
|
|
|
+ submitButtonDisabled = existingPaths.length !== 0; // v5 data
|
|
|
|
|
+ }
|
|
|
|
|
+ else {
|
|
|
|
|
+ submitButtonDisabled = !isRenameRecursively; // v4 data
|
|
|
|
|
+ }
|
|
|
|
|
+
|
|
|
|
|
|
|
|
return (
|
|
return (
|
|
|
<Modal size="lg" isOpen={isOpened} toggle={closeRenameModal} autoFocus={false}>
|
|
<Modal size="lg" isOpen={isOpened} toggle={closeRenameModal} autoFocus={false}>
|
|
@@ -212,6 +234,9 @@ const PageRenameModal = (): JSX.Element => {
|
|
|
{ isTargetPageDuplicate && (
|
|
{ isTargetPageDuplicate && (
|
|
|
<p className="text-danger">Error: Target path is duplicated.</p>
|
|
<p className="text-danger">Error: Target path is duplicated.</p>
|
|
|
) }
|
|
) }
|
|
|
|
|
+ { isMatchedWithUserHomePagePath && (
|
|
|
|
|
+ <p className="text-danger">Error: Cannot move to directory under /user page.</p>
|
|
|
|
|
+ ) }
|
|
|
|
|
|
|
|
{ !isV5Compatible(page.meta) && (
|
|
{ !isV5Compatible(page.meta) && (
|
|
|
<>
|
|
<>
|