|
|
@@ -0,0 +1,98 @@
|
|
|
+import React, { useState } from 'react';
|
|
|
+import {
|
|
|
+ Modal, ModalHeader, ModalBody, ModalFooter,
|
|
|
+} from 'reactstrap';
|
|
|
+import { useTranslation } from 'react-i18next';
|
|
|
+
|
|
|
+import { apiv3Post } from '~/client/util/apiv3-client';
|
|
|
+import { useLegacyPrivatePagesMigrationModal } from '~/stores/modal';
|
|
|
+
|
|
|
+import ApiErrorMessageList from './PageManagement/ApiErrorMessageList';
|
|
|
+
|
|
|
+
|
|
|
+type Props = {
|
|
|
+
|
|
|
+}
|
|
|
+
|
|
|
+export const LegacyPrivatePagesMigrationModal = (props: Props): JSX.Element => {
|
|
|
+ const { t } = useTranslation();
|
|
|
+
|
|
|
+ const { data: status, close } = useLegacyPrivatePagesMigrationModal();
|
|
|
+
|
|
|
+ const isOpened = status?.isOpened ?? false;
|
|
|
+
|
|
|
+ const [isRecursively, setIsRecursively] = useState(true);
|
|
|
+
|
|
|
+ // eslint-disable-next-line @typescript-eslint/no-unused-vars
|
|
|
+ const [errs, setErrs] = useState<Error[] | null>(null);
|
|
|
+
|
|
|
+ async function submit() {
|
|
|
+ if (status == null || status.pages == null || status.pages.length === 0) {
|
|
|
+ return;
|
|
|
+ }
|
|
|
+
|
|
|
+ const { pages, onSubmited } = status;
|
|
|
+ const pageIds = pages.map(page => page.pageId);
|
|
|
+ try {
|
|
|
+ await apiv3Post<void>('/legacy-pages-migration', {
|
|
|
+ pageIds,
|
|
|
+ isRecursively: isRecursively ? true : undefined,
|
|
|
+ });
|
|
|
+
|
|
|
+ if (onSubmited != null) {
|
|
|
+ onSubmited(pages, isRecursively);
|
|
|
+ }
|
|
|
+ }
|
|
|
+ catch (err) {
|
|
|
+ setErrs([err]);
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
+ function renderForm() {
|
|
|
+ return (
|
|
|
+ <div className="custom-control custom-checkbox custom-checkbox-warning">
|
|
|
+ <input
|
|
|
+ className="custom-control-input"
|
|
|
+ id="deleteRecursively"
|
|
|
+ type="checkbox"
|
|
|
+ onChange={e => setIsRecursively(e.target.checked)}
|
|
|
+ />
|
|
|
+ <label className="custom-control-label" htmlFor="deleteRecursively">
|
|
|
+ { t('modal_delete.delete_recursively') }
|
|
|
+ </label>
|
|
|
+ </div>
|
|
|
+ );
|
|
|
+ }
|
|
|
+
|
|
|
+ const renderPageIds = () => {
|
|
|
+ if (status != null && status.pages != null) {
|
|
|
+ return status.pages.map(page => <div key={page.pageId}><code>{ page.path }</code></div>);
|
|
|
+ }
|
|
|
+ return <></>;
|
|
|
+ };
|
|
|
+
|
|
|
+ return (
|
|
|
+ <Modal size="lg" isOpen={isOpened} toggle={close} className="grw-create-page">
|
|
|
+ <ModalHeader tag="h4" toggle={close} className="bg-primary text-light">
|
|
|
+ Convert
|
|
|
+ </ModalHeader>
|
|
|
+ <ModalBody>
|
|
|
+ <div className="form-group grw-scrollable-modal-body pb-1">
|
|
|
+ <label>{ t('modal_delete.deleting_page') }:</label><br />
|
|
|
+ {/* Todo: change the way to show path on modal when too many pages are selected */}
|
|
|
+ {/* https://redmine.weseek.co.jp/issues/82787 */}
|
|
|
+ {renderPageIds()}
|
|
|
+ </div>
|
|
|
+ {renderForm()}
|
|
|
+ </ModalBody>
|
|
|
+ <ModalFooter>
|
|
|
+ <ApiErrorMessageList errs={errs} />
|
|
|
+ <button type="button" className="btn btn-primary" onClick={submit}>
|
|
|
+ <i className="icon-fw icon-refresh" aria-hidden="true"></i>
|
|
|
+ Convert
|
|
|
+ </button>
|
|
|
+ </ModalFooter>
|
|
|
+ </Modal>
|
|
|
+
|
|
|
+ );
|
|
|
+};
|