|
@@ -29,11 +29,10 @@ const PageRenameModal = (props) => {
|
|
|
} = props;
|
|
} = props;
|
|
|
|
|
|
|
|
const { crowi } = appContainer.config;
|
|
const { crowi } = appContainer.config;
|
|
|
- const { data: pagesDataToRename, close: closeRenameModal } = usePageRenameModal();
|
|
|
|
|
|
|
+ const { data: renameModalData, close: closeRenameModal } = usePageRenameModal();
|
|
|
|
|
|
|
|
- const {
|
|
|
|
|
- isOpened, path, revisionId, pageId,
|
|
|
|
|
- } = pagesDataToRename;
|
|
|
|
|
|
|
+ const { isOpened, page } = renameModalData;
|
|
|
|
|
+ const { pageId, revisionId, path } = page;
|
|
|
|
|
|
|
|
const [pageNameInput, setPageNameInput] = useState('');
|
|
const [pageNameInput, setPageNameInput] = useState('');
|
|
|
|
|
|
|
@@ -83,7 +82,7 @@ const PageRenameModal = (props) => {
|
|
|
}, [isOpened, path, updateSubordinatedList]);
|
|
}, [isOpened, path, updateSubordinatedList]);
|
|
|
|
|
|
|
|
|
|
|
|
|
- const checkExistPaths = async(newParentPath) => {
|
|
|
|
|
|
|
+ const checkExistPaths = useCallback(async(newParentPath) => {
|
|
|
try {
|
|
try {
|
|
|
const res = await apiv3Get('/page/exist-paths', { fromPath: path, toPath: newParentPath });
|
|
const res = await apiv3Get('/page/exist-paths', { fromPath: path, toPath: newParentPath });
|
|
|
const { existPaths } = res.data;
|
|
const { existPaths } = res.data;
|
|
@@ -93,15 +92,15 @@ const PageRenameModal = (props) => {
|
|
|
setErrs(err);
|
|
setErrs(err);
|
|
|
toastError(t('modal_rename.label.Fail to get exist path'));
|
|
toastError(t('modal_rename.label.Fail to get exist path'));
|
|
|
}
|
|
}
|
|
|
- };
|
|
|
|
|
|
|
+ }, [path, t]);
|
|
|
|
|
|
|
|
// eslint-disable-next-line react-hooks/exhaustive-deps
|
|
// eslint-disable-next-line react-hooks/exhaustive-deps
|
|
|
- const checkExistPathsDebounce = useCallback(
|
|
|
|
|
- debounce(1000, checkExistPaths), [path],
|
|
|
|
|
- );
|
|
|
|
|
|
|
+ const checkExistPathsDebounce = useCallback(() => {
|
|
|
|
|
+ debounce(1000, checkExistPaths);
|
|
|
|
|
+ }, [checkExistPaths]);
|
|
|
|
|
|
|
|
useEffect(() => {
|
|
useEffect(() => {
|
|
|
- if (pageId != null && pageNameInput !== path) {
|
|
|
|
|
|
|
+ if (pageId != null && path != null && pageNameInput !== path) {
|
|
|
checkExistPathsDebounce(pageNameInput, subordinatedPages);
|
|
checkExistPathsDebounce(pageNameInput, subordinatedPages);
|
|
|
}
|
|
}
|
|
|
}, [pageNameInput, subordinatedPages, pageId, path, checkExistPathsDebounce]);
|
|
}, [pageNameInput, subordinatedPages, pageId, path, checkExistPathsDebounce]);
|