|
|
@@ -27,9 +27,10 @@ const PageDuplicateModal = (props) => {
|
|
|
const config = appContainer.getConfig();
|
|
|
const isReachable = config.isSearchServiceReachable;
|
|
|
const { crowi } = appContainer.config;
|
|
|
- const { data: pagesDataToDuplicate, close: closeDuplicateModal } = usePageDuplicateModal();
|
|
|
+ const { data: duplicateModalData, close: closeDuplicateModal } = usePageDuplicateModal();
|
|
|
|
|
|
- const { isOpened, path, pageId } = pagesDataToDuplicate;
|
|
|
+ const { isOpened, page } = duplicateModalData;
|
|
|
+ const { pageId, path } = page;
|
|
|
|
|
|
const [pageNameInput, setPageNameInput] = useState(path);
|
|
|
|
|
|
@@ -40,7 +41,7 @@ const PageDuplicateModal = (props) => {
|
|
|
const [isDuplicateRecursivelyWithoutExistPath, setIsDuplicateRecursivelyWithoutExistPath] = useState(true);
|
|
|
const [existingPaths, setExistingPaths] = useState([]);
|
|
|
|
|
|
- const checkExistPaths = async(newParentPath) => {
|
|
|
+ const checkExistPaths = useCallback(async(newParentPath) => {
|
|
|
try {
|
|
|
const res = await appContainer.apiv3Get('/page/exist-paths', { fromPath: path, toPath: newParentPath });
|
|
|
const { existPaths } = res.data;
|
|
|
@@ -50,15 +51,18 @@ const PageDuplicateModal = (props) => {
|
|
|
setErrs(err);
|
|
|
toastError(t('modal_rename.label.Fail to get exist path'));
|
|
|
}
|
|
|
- };
|
|
|
+ }, [appContainer, path, t]);
|
|
|
|
|
|
- // eslint-disable-next-line react-hooks/exhaustive-deps
|
|
|
- const checkExistPathsDebounce = useCallback(
|
|
|
- debounce(1000, checkExistPaths), [pageId, path],
|
|
|
- );
|
|
|
+
|
|
|
+ const checkExistPathsDebounce = useCallback(() => {
|
|
|
+ debounce(1000, checkExistPaths);
|
|
|
+ }, [checkExistPaths]);
|
|
|
|
|
|
useEffect(() => {
|
|
|
- if (pageId != null && pageNameInput !== path) {
|
|
|
+ if (path == null) {
|
|
|
+ return;
|
|
|
+ }
|
|
|
+ if (pageId != null && path != null && pageNameInput !== path) {
|
|
|
checkExistPathsDebounce(pageNameInput, subordinatedPages);
|
|
|
}
|
|
|
}, [pageNameInput, subordinatedPages, path, pageId, checkExistPathsDebounce]);
|
|
|
@@ -78,7 +82,7 @@ const PageDuplicateModal = (props) => {
|
|
|
*/
|
|
|
function inputChangeHandler(value) {
|
|
|
setErrs(null);
|
|
|
- setPageNameInput(value);
|
|
|
+ setPageNameInput(value ?? '');
|
|
|
}
|
|
|
|
|
|
function changeIsDuplicateRecursivelyHandler() {
|