import React, { useState, useEffect, useCallback } from 'react'; import PropTypes from 'prop-types'; import { Modal, ModalHeader, ModalBody, ModalFooter, } from 'reactstrap'; import { withTranslation } from 'react-i18next'; import { withUnstatedContainers } from './UnstatedUtils'; import AppContainer from '../services/AppContainer'; import PageContainer from '../services/PageContainer'; import PagePathAutoComplete from './PagePathAutoComplete'; import ApiErrorMessageList from './PageManagement/ApiErrorMessageList'; const PageDuplicateModal = (props) => { const { t, appContainer, pageContainer } = props; const config = appContainer.getConfig(); const isReachable = config.isSearchServiceReachable; const { pageId, path } = pageContainer.state; const { crowi } = appContainer.config; const [pageNameInput, setPageNameInput] = useState(path); const [errs, setErrs] = useState(null); const [subordinatedPaths, setSubordinatedPaths] = useState([]); const [getSubordinatedError, setGetSuborinatedError] = useState(null); const [isDuplicateRecursively, setIsDuplicateRecursively] = useState(true); const [isDuplicateRecursivelyWithoutExistPath, setIsDuplicateRecursivelyWithoutExistPath] = useState(true); const [isExist, setIsExist] = useState(false); const [existPaths, setExistPaths] = useState([]); const dummyExistPaths = ['/test146']; /** * change pageNameInput for PagePathAutoComplete * @param {string} value */ function ppacInputChangeHandler(value) { setPageNameInput(value); } /** * change pageNameInput * @param {string} value */ function inputChangeHandler(value) { setPageNameInput(value); } function changeIsDuplicateRecursivelyHandler() { setIsDuplicateRecursively(!isDuplicateRecursively); } function changeIsDuplicateRecursivelyWithoutExistPathHandler() { setIsDuplicateRecursivelyWithoutExistPath(!isDuplicateRecursivelyWithoutExistPath); } function changeIsExistHandler() { setIsExist(true); } function checkExistPath() { subordinatedPaths.map((duplicatedNewPath) => { const existPath = dummyExistPaths.includes(duplicatedNewPath); // dummyExistPaths is dummy data if (existPath) { changeIsExistHandler(); setExistPaths(existPaths.push(duplicatedNewPath)); } }); return existPaths; } function createSubordinatedList() { return subordinatedPaths.map((duplicatedNewPath) => { const existPath = existPaths.includes(duplicatedNewPath); let result; if (existPath) { result =
{path}