import React, { useState } from 'react'; import PropTypes from 'prop-types'; import { Modal, ModalHeader, ModalBody } from 'reactstrap'; import { withTranslation } from 'react-i18next'; import { format } from 'date-fns'; import urljoin from 'url-join'; import { userPageRoot } from '@commons/util/path-utils'; import { pathUtils } from 'growi-commons'; import AppContainer from '../services/AppContainer'; import NavigationContainer from '../services/NavigationContainer'; import { withUnstatedContainers } from './UnstatedUtils'; import PagePathAutoComplete from './PagePathAutoComplete'; const PageCreateModal = (props) => { const { t, appContainer, navigationContainer } = props; const config = appContainer.getConfig(); const isReachable = config.isSearchServiceReachable; const pathname = decodeURI(window.location.pathname); const userPageRootPath = userPageRoot(appContainer.currentUser); const parentPath = pathUtils.addTrailingSlash(pathname); const now = format(new Date(), 'yyyy/MM/dd'); const [todayInput1, setTodayInput1] = useState(t('Memo')); const [todayInput2, setTodayInput2] = useState(''); const [pageNameInput, setPageNameInput] = useState(parentPath); const [template, setTemplate] = useState(null); function transitBySubmitEvent(e, transitHandler) { // prevent page transition by submit e.preventDefault(); transitHandler(); } /** * change todayInput1 * @param {string} value */ function onChangeTodayInput1Handler(value) { setTodayInput1(value); } /** * change todayInput2 * @param {string} value */ function onChangeTodayInput2Handler(value) { setTodayInput2(value); } /** * change pageNameInput * @param {string} value */ function onChangePageNameInputHandler(value) { setPageNameInput(value); } /** * change template * @param {string} value */ function onChangeTemplateHandler(value) { setTemplate(value); } /** * access today page */ function createTodayPage() { let tmpTodayInput1 = todayInput1; if (tmpTodayInput1 === '') { tmpTodayInput1 = t('Memo'); } window.location.href = encodeURI(urljoin(userPageRootPath, tmpTodayInput1, now, todayInput2, '#edit')); } /** * access input page */ function createInputPage() { window.location.href = encodeURI(urljoin(pageNameInput, '#edit')); } function ppacInputChangeHandler(value) { setPageNameInput(value); } function ppacSubmitHandler() { createInputPage(); } /** * access template page */ function createTemplatePage(e) { const pageName = (template === 'children') ? '_template' : '__template'; window.location.href = encodeURI(urljoin(pathname, pageName, '#edit')); } function renderCreateTodayForm() { return (