|
|
@@ -1,16 +1,20 @@
|
|
|
-import React, { useState } from 'react';
|
|
|
-import PropTypes from 'prop-types';
|
|
|
-
|
|
|
+import React, { useState, FC } from 'react';
|
|
|
+import toastr from 'toastr';
|
|
|
import {
|
|
|
Modal, ModalHeader, ModalBody, ModalFooter,
|
|
|
} from 'reactstrap';
|
|
|
+import { useTranslation } from 'react-i18next';
|
|
|
|
|
|
-import { withTranslation } from 'react-i18next';
|
|
|
-
|
|
|
-import { apiPost } from '~/client/util/apiv1-client';
|
|
|
+// import { apiPost } from '~/client/util/apiv1-client';
|
|
|
|
|
|
import ApiErrorMessageList from './PageManagement/ApiErrorMessageList';
|
|
|
|
|
|
+export type IPageForPageDeleteModal = {
|
|
|
+ pageId: string,
|
|
|
+ revisionId: string,
|
|
|
+ path: string
|
|
|
+}
|
|
|
+
|
|
|
const deleteIconAndKey = {
|
|
|
completely: {
|
|
|
color: 'danger',
|
|
|
@@ -24,9 +28,18 @@ const deleteIconAndKey = {
|
|
|
},
|
|
|
};
|
|
|
|
|
|
-const PageDeleteModal = (props) => {
|
|
|
+type Props = {
|
|
|
+ isOpen: boolean,
|
|
|
+ pages: IPageForPageDeleteModal[],
|
|
|
+ isDeleteCompletelyModal: boolean,
|
|
|
+ isAbleToDeleteCompletely: boolean,
|
|
|
+ onClose?: () => void,
|
|
|
+}
|
|
|
+
|
|
|
+const PageDeleteModal: FC<Props> = (props: Props) => {
|
|
|
+ const { t } = useTranslation('');
|
|
|
const {
|
|
|
- t, isOpen, onClose, isDeleteCompletelyModal, pageId, revisionId, path, isAbleToDeleteCompletely,
|
|
|
+ isOpen, onClose, isDeleteCompletelyModal, pages, isAbleToDeleteCompletely,
|
|
|
} = props;
|
|
|
const [isDeleteRecursively, setIsDeleteRecursively] = useState(true);
|
|
|
const [isDeleteCompletely, setIsDeleteCompletely] = useState(isDeleteCompletelyModal && isAbleToDeleteCompletely);
|
|
|
@@ -46,27 +59,29 @@ const PageDeleteModal = (props) => {
|
|
|
}
|
|
|
|
|
|
async function deletePage() {
|
|
|
- setErrs(null);
|
|
|
-
|
|
|
- try {
|
|
|
- // control flag
|
|
|
- // If is it not true, Request value must be `null`.
|
|
|
- const recursively = isDeleteRecursively ? true : null;
|
|
|
- const completely = isDeleteCompletely ? true : null;
|
|
|
-
|
|
|
- const response = await apiPost('/pages.remove', {
|
|
|
- page_id: pageId,
|
|
|
- revision_id: revisionId,
|
|
|
- recursively,
|
|
|
- completely,
|
|
|
- });
|
|
|
-
|
|
|
- const trashPagePath = response.page.path;
|
|
|
- window.location.href = encodeURI(trashPagePath);
|
|
|
- }
|
|
|
- catch (err) {
|
|
|
- setErrs(err);
|
|
|
- }
|
|
|
+ toastr.warning(t('search_result.currently_not_implemented'));
|
|
|
+ // Todo implement page delete function at https://redmine.weseek.co.jp/issues/82222
|
|
|
+ // setErrs(null);
|
|
|
+
|
|
|
+ // try {
|
|
|
+ // // control flag
|
|
|
+ // // If is it not true, Request value must be `null`.
|
|
|
+ // const recursively = isDeleteRecursively ? true : null;
|
|
|
+ // const completely = isDeleteCompletely ? true : null;
|
|
|
+
|
|
|
+ // const response = await apiPost('/pages.remove', {
|
|
|
+ // page_id: pageId,
|
|
|
+ // revision_id: revisionId,
|
|
|
+ // recursively,
|
|
|
+ // completely,
|
|
|
+ // });
|
|
|
+
|
|
|
+ // const trashPagePath = response.page.path;
|
|
|
+ // window.location.href = encodeURI(trashPagePath);
|
|
|
+ // }
|
|
|
+ // catch (err) {
|
|
|
+ // setErrs(err);
|
|
|
+ // }
|
|
|
}
|
|
|
|
|
|
async function deleteButtonHandler() {
|
|
|
@@ -80,12 +95,13 @@ const PageDeleteModal = (props) => {
|
|
|
className="custom-control-input"
|
|
|
id="deleteRecursively"
|
|
|
type="checkbox"
|
|
|
- checked={isDeleteRecursively}
|
|
|
+ // checked={isDeleteRecursively}
|
|
|
+ checked={false}
|
|
|
onChange={changeIsDeleteRecursivelyHandler}
|
|
|
+ disabled // Todo: enable this at https://redmine.weseek.co.jp/issues/82222
|
|
|
/>
|
|
|
<label className="custom-control-label" htmlFor="deleteRecursively">
|
|
|
{ t('modal_delete.delete_recursively') }
|
|
|
- <p className="form-text text-muted mt-0"><code>{path}</code> { t('modal_delete.recursively') }</p>
|
|
|
</label>
|
|
|
</div>
|
|
|
);
|
|
|
@@ -105,11 +121,14 @@ const PageDeleteModal = (props) => {
|
|
|
name="completely"
|
|
|
id="deleteCompletely"
|
|
|
type="checkbox"
|
|
|
- disabled
|
|
|
+ // disabled={!isAbleToDeleteCompletely}
|
|
|
+ disabled // Todo: will be implemented at https://redmine.weseek.co.jp/issues/82222
|
|
|
checked={isDeleteCompletely}
|
|
|
onChange={changeIsDeleteCompletelyHandler}
|
|
|
/>
|
|
|
- <label className="custom-control-label text-danger" htmlFor="deleteCompletely">
|
|
|
+ {/* ↓↓ undo this comment out at https://redmine.weseek.co.jp/issues/82222 ↓↓ */}
|
|
|
+ {/* <label className="custom-control-label text-danger" htmlFor="deleteCompletely"> */}
|
|
|
+ <label className="custom-control-label" htmlFor="deleteCompletely">
|
|
|
{ t('modal_delete.delete_completely')}
|
|
|
<p className="form-text text-muted mt-0"> { t('modal_delete.completely') }</p>
|
|
|
</label>
|
|
|
@@ -132,7 +151,11 @@ const PageDeleteModal = (props) => {
|
|
|
<ModalBody>
|
|
|
<div className="form-group">
|
|
|
<label>{ t('modal_delete.deleting_page') }:</label><br />
|
|
|
- <code>{ path }</code>
|
|
|
+ {/* Todo: change the way to show path on modal when too many pages are selected */}
|
|
|
+ {/* https://redmine.weseek.co.jp/issues/82787 */}
|
|
|
+ {pages.map((page) => {
|
|
|
+ return <div><code>{ page.path }</code></div>;
|
|
|
+ })}
|
|
|
</div>
|
|
|
{renderDeleteRecursivelyForm()}
|
|
|
{!isDeleteCompletelyModal && renderDeleteCompletelyForm()}
|
|
|
@@ -149,21 +172,4 @@ const PageDeleteModal = (props) => {
|
|
|
);
|
|
|
};
|
|
|
|
|
|
-PageDeleteModal.propTypes = {
|
|
|
- t: PropTypes.func.isRequired, // i18next
|
|
|
-
|
|
|
- isOpen: PropTypes.bool.isRequired,
|
|
|
- onClose: PropTypes.func.isRequired,
|
|
|
-
|
|
|
- pageId: PropTypes.string.isRequired,
|
|
|
- revisionId: PropTypes.string.isRequired,
|
|
|
- path: PropTypes.string.isRequired,
|
|
|
- isDeleteCompletelyModal: PropTypes.bool,
|
|
|
- isAbleToDeleteCompletely: PropTypes.bool,
|
|
|
-};
|
|
|
-
|
|
|
-PageDeleteModal.defaultProps = {
|
|
|
- isDeleteCompletelyModal: false,
|
|
|
-};
|
|
|
-
|
|
|
-export default withTranslation()(PageDeleteModal);
|
|
|
+export default PageDeleteModal;
|