|
|
@@ -6,14 +6,16 @@ import { Modal, ModalHeader, ModalBody } from 'reactstrap';
|
|
|
|
|
|
import { withTranslation } from 'react-i18next';
|
|
|
import { format } from 'date-fns';
|
|
|
-import urljoin from 'url-join';
|
|
|
|
|
|
-import { userPageRoot, isCreatablePage } from '@commons/util/path-utils';
|
|
|
+import {
|
|
|
+ userPageRoot, isCreatablePage, generateEditorPath,
|
|
|
+} 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 { toastError } from '../util/apiNotification';
|
|
|
|
|
|
import PagePathAutoComplete from './PagePathAutoComplete';
|
|
|
|
|
|
@@ -70,6 +72,20 @@ const PageCreateModal = (props) => {
|
|
|
setTemplate(value);
|
|
|
}
|
|
|
|
|
|
+ /**
|
|
|
+ * join path, check if creatable, then redirect
|
|
|
+ * @param {string} paths
|
|
|
+ */
|
|
|
+ async function redirectToEditor(...paths) {
|
|
|
+ try {
|
|
|
+ const editorPath = await generateEditorPath(...paths);
|
|
|
+ window.location.href = editorPath;
|
|
|
+ }
|
|
|
+ catch (err) {
|
|
|
+ toastError(err);
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
/**
|
|
|
* access today page
|
|
|
*/
|
|
|
@@ -78,14 +94,14 @@ const PageCreateModal = (props) => {
|
|
|
if (tmpTodayInput1 === '') {
|
|
|
tmpTodayInput1 = t('Memo');
|
|
|
}
|
|
|
- window.location.href = encodeURI(urljoin(userPageRootPath, tmpTodayInput1, now, todayInput2, '#edit'));
|
|
|
+ redirectToEditor(userPageRootPath, tmpTodayInput1, now, todayInput2);
|
|
|
}
|
|
|
|
|
|
/**
|
|
|
* access input page
|
|
|
*/
|
|
|
function createInputPage() {
|
|
|
- window.location.href = encodeURI(urljoin(pageNameInput, '#edit'));
|
|
|
+ redirectToEditor(pageNameInput);
|
|
|
}
|
|
|
|
|
|
function ppacInputChangeHandler(value) {
|
|
|
@@ -101,14 +117,14 @@ const PageCreateModal = (props) => {
|
|
|
*/
|
|
|
function createTemplatePage(e) {
|
|
|
const pageName = (template === 'children') ? '_template' : '__template';
|
|
|
- window.location.href = encodeURI(urljoin(pathname, pageName, '#edit'));
|
|
|
+ redirectToEditor(pathname, pageName);
|
|
|
}
|
|
|
|
|
|
function renderCreateTodayForm() {
|
|
|
return (
|
|
|
<div className="row">
|
|
|
<fieldset className="col-12 mb-4">
|
|
|
- <h3 className="grw-modal-head pb-2">{ t("Create today's") }</h3>
|
|
|
+ <h3 className="grw-modal-head pb-2">{t("Create today's")}</h3>
|
|
|
|
|
|
<div className="d-sm-flex align-items-center justify-items-between">
|
|
|
|
|
|
@@ -139,7 +155,7 @@ const PageCreateModal = (props) => {
|
|
|
|
|
|
<div className="d-flex justify-content-end mt-1 mt-sm-0">
|
|
|
<button type="button" className="grw-btn-create-page btn btn-outline-primary rounded-pill text-nowrap ml-3" onClick={createTodayPage}>
|
|
|
- <i className="icon-fw icon-doc"></i>{ t('Create') }
|
|
|
+ <i className="icon-fw icon-doc"></i>{t('Create')}
|
|
|
</button>
|
|
|
</div>
|
|
|
|
|
|
@@ -154,7 +170,7 @@ const PageCreateModal = (props) => {
|
|
|
return (
|
|
|
<div className="row">
|
|
|
<fieldset className="col-12 mb-4">
|
|
|
- <h3 className="grw-modal-head pb-2">{ t('Create under') }</h3>
|
|
|
+ <h3 className="grw-modal-head pb-2">{t('Create under')}</h3>
|
|
|
|
|
|
<div className="d-sm-flex align-items-center justify-items-between">
|
|
|
|
|
|
@@ -185,7 +201,7 @@ const PageCreateModal = (props) => {
|
|
|
|
|
|
<div className="d-flex justify-content-end mt-1 mt-sm-0">
|
|
|
<button type="button" className="grw-btn-create-page btn btn-outline-primary rounded-pill text-nowrap ml-3" onClick={createInputPage}>
|
|
|
- <i className="icon-fw icon-doc"></i>{ t('Create') }
|
|
|
+ <i className="icon-fw icon-doc"></i>{t('Create')}
|
|
|
</button>
|
|
|
</div>
|
|
|
|
|
|
@@ -202,7 +218,7 @@ const PageCreateModal = (props) => {
|
|
|
<fieldset className="col-12">
|
|
|
|
|
|
<h3 className="grw-modal-head pb-2">
|
|
|
- { t('template.modal_label.Create template under')}<br />
|
|
|
+ {t('template.modal_label.Create template under')}<br />
|
|
|
<code className="h6">{pathname}</code>
|
|
|
</h3>
|
|
|
|
|
|
@@ -210,18 +226,18 @@ const PageCreateModal = (props) => {
|
|
|
|
|
|
<div id="dd-template-type" className="dropdown flex-fill">
|
|
|
<button id="template-type" type="button" className="btn btn-secondary btn dropdown-toggle w-100" data-toggle="dropdown">
|
|
|
- {template == null && t('template.option_label.select') }
|
|
|
+ {template == null && t('template.option_label.select')}
|
|
|
{template === 'children' && t('template.children.label')}
|
|
|
{template === 'decendants' && t('template.decendants.label')}
|
|
|
</button>
|
|
|
<div className="dropdown-menu" aria-labelledby="userMenu">
|
|
|
<button className="dropdown-item" type="button" onClick={() => onChangeTemplateHandler('children')}>
|
|
|
- { t('template.children.label') } (_template)<br className="d-block d-md-none" />
|
|
|
- <small className="text-muted text-wrap">- { t('template.children.desc') }</small>
|
|
|
+ {t('template.children.label')} (_template)<br className="d-block d-md-none" />
|
|
|
+ <small className="text-muted text-wrap">- {t('template.children.desc')}</small>
|
|
|
</button>
|
|
|
<button className="dropdown-item" type="button" onClick={() => onChangeTemplateHandler('decendants')}>
|
|
|
- { t('template.decendants.label') } (__template) <br className="d-block d-md-none" />
|
|
|
- <small className="text-muted">- { t('template.decendants.desc') }</small>
|
|
|
+ {t('template.decendants.label')} (__template) <br className="d-block d-md-none" />
|
|
|
+ <small className="text-muted">- {t('template.decendants.desc')}</small>
|
|
|
</button>
|
|
|
</div>
|
|
|
</div>
|
|
|
@@ -232,7 +248,7 @@ const PageCreateModal = (props) => {
|
|
|
className={`grw-btn-create-page btn btn-outline-primary rounded-pill text-nowrap ml-3 ${template == null && 'disabled'}`}
|
|
|
onClick={createTemplatePage}
|
|
|
>
|
|
|
- <i className="icon-fw icon-doc"></i>{ t('Edit') }
|
|
|
+ <i className="icon-fw icon-doc"></i>{t('Edit')}
|
|
|
</button>
|
|
|
</div>
|
|
|
|
|
|
@@ -252,7 +268,7 @@ const PageCreateModal = (props) => {
|
|
|
autoFocus={false}
|
|
|
>
|
|
|
<ModalHeader tag="h4" toggle={navigationContainer.closePageCreateModal} className="bg-primary text-light">
|
|
|
- { t('New Page') }
|
|
|
+ {t('New Page')}
|
|
|
</ModalHeader>
|
|
|
<ModalBody>
|
|
|
{renderCreateTodayForm()}
|