|
|
@@ -9,6 +9,7 @@ import { withTranslation } from 'react-i18next';
|
|
|
import { debounce } from 'throttle-debounce';
|
|
|
import { withUnstatedContainers } from './UnstatedUtils';
|
|
|
import { toastError } from '~/client/util/apiNotification';
|
|
|
+import { usePageDuplicateModalStatus, usePageDuplicateModalOpened } from '~/stores/ui';
|
|
|
|
|
|
import AppContainer from '~/client/services/AppContainer';
|
|
|
import PagePathAutoComplete from './PagePathAutoComplete';
|
|
|
@@ -20,12 +21,16 @@ const LIMIT_FOR_LIST = 10;
|
|
|
|
|
|
const PageDuplicateModal = (props) => {
|
|
|
const {
|
|
|
- t, appContainer, pageId, path,
|
|
|
+ t, appContainer,
|
|
|
} = props;
|
|
|
|
|
|
const config = appContainer.getConfig();
|
|
|
const isReachable = config.isSearchServiceReachable;
|
|
|
const { crowi } = appContainer.config;
|
|
|
+ const { data: pagesDataToDuplicate, close: closeDuplicateModal } = usePageDuplicateModalStatus();
|
|
|
+ const { data: isOpened } = usePageDuplicateModalOpened();
|
|
|
+
|
|
|
+ const { path, pageId } = pagesDataToDuplicate;
|
|
|
|
|
|
const [pageNameInput, setPageNameInput] = useState(path);
|
|
|
|
|
|
@@ -50,14 +55,14 @@ const PageDuplicateModal = (props) => {
|
|
|
|
|
|
// eslint-disable-next-line react-hooks/exhaustive-deps
|
|
|
const checkExistPathsDebounce = useCallback(
|
|
|
- debounce(1000, checkExistPaths), [],
|
|
|
+ debounce(1000, checkExistPaths), [pageId, path],
|
|
|
);
|
|
|
|
|
|
useEffect(() => {
|
|
|
- if (pageNameInput !== path) {
|
|
|
+ if (pageId != null && pageNameInput !== path) {
|
|
|
checkExistPathsDebounce(pageNameInput, subordinatedPages);
|
|
|
}
|
|
|
- }, [pageNameInput, subordinatedPages, path, checkExistPathsDebounce]);
|
|
|
+ }, [pageNameInput, subordinatedPages, path, pageId, checkExistPathsDebounce]);
|
|
|
|
|
|
/**
|
|
|
* change pageNameInput for PagePathAutoComplete
|
|
|
@@ -94,10 +99,11 @@ const PageDuplicateModal = (props) => {
|
|
|
}, [appContainer, path, t]);
|
|
|
|
|
|
useEffect(() => {
|
|
|
- if (props.isOpen) {
|
|
|
+ if (isOpened) {
|
|
|
getSubordinatedList();
|
|
|
+ setPageNameInput(path);
|
|
|
}
|
|
|
- }, [props.isOpen, getSubordinatedList]);
|
|
|
+ }, [isOpened, getSubordinatedList, path]);
|
|
|
|
|
|
function changeIsDuplicateRecursivelyWithoutExistPathHandler() {
|
|
|
setIsDuplicateRecursivelyWithoutExistPath(!isDuplicateRecursivelyWithoutExistPath);
|
|
|
@@ -120,8 +126,8 @@ const PageDuplicateModal = (props) => {
|
|
|
}
|
|
|
|
|
|
return (
|
|
|
- <Modal size="lg" isOpen={props.isOpen} toggle={props.onClose} className="grw-duplicate-page" autoFocus={false}>
|
|
|
- <ModalHeader tag="h4" toggle={props.onClose} className="bg-primary text-light">
|
|
|
+ <Modal size="lg" isOpen={isOpened} toggle={closeDuplicateModal} className="grw-duplicate-page" autoFocus={false}>
|
|
|
+ <ModalHeader tag="h4" toggle={closeDuplicateModal} className="bg-primary text-light">
|
|
|
{ t('modal_duplicate.label.Duplicate page') }
|
|
|
</ModalHeader>
|
|
|
<ModalBody>
|
|
|
@@ -188,7 +194,7 @@ const PageDuplicateModal = (props) => {
|
|
|
)}
|
|
|
</div>
|
|
|
<div>
|
|
|
- {isDuplicateRecursively && <ComparePathsTable path={path} subordinatedPages={subordinatedPages} newPagePath={pageNameInput} />}
|
|
|
+ {isDuplicateRecursively && path != null && <ComparePathsTable path={path} subordinatedPages={subordinatedPages} newPagePath={pageNameInput} />}
|
|
|
{isDuplicateRecursively && existingPaths.length !== 0 && <DuplicatePathsTable existingPaths={existingPaths} oldPagePath={pageNameInput} />}
|
|
|
</div>
|
|
|
</div>
|
|
|
@@ -219,12 +225,6 @@ const PageDuplicateModallWrapper = withUnstatedContainers(PageDuplicateModal, [A
|
|
|
PageDuplicateModal.propTypes = {
|
|
|
t: PropTypes.func.isRequired, // i18next
|
|
|
appContainer: PropTypes.instanceOf(AppContainer).isRequired,
|
|
|
-
|
|
|
- isOpen: PropTypes.bool.isRequired,
|
|
|
- onClose: PropTypes.func.isRequired,
|
|
|
-
|
|
|
- pageId: PropTypes.string.isRequired,
|
|
|
- path: PropTypes.string.isRequired,
|
|
|
};
|
|
|
|
|
|
export default withTranslation()(PageDuplicateModallWrapper);
|