import React, { useState } from 'react'; import { useTranslation } from 'next-i18next'; import { Modal, ModalHeader, ModalBody, ModalFooter, } from 'reactstrap'; import { apiv3Post } from '~/client/util/apiv3-client'; import { usePrivateLegacyPagesMigrationModal } from '~/stores/modal'; import ApiErrorMessageList from './PageManagement/ApiErrorMessageList'; export const PrivateLegacyPagesMigrationModal = (): JSX.Element => { const { t } = useTranslation(); const { data: status, close } = usePrivateLegacyPagesMigrationModal(); const isOpened = status?.isOpened ?? false; const [isRecursively, setIsRecursively] = useState(true); // eslint-disable-next-line @typescript-eslint/no-unused-vars const [errs, setErrs] = useState(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('/pages/legacy-pages-migration', { pageIds, isRecursively: isRecursively ? true : undefined, }); if (onSubmited != null) { onSubmited(pages, isRecursively); } } catch (err) { setErrs([err]); } } function renderForm() { return (
{ setIsRecursively(e.target.checked); }} />
); } const renderPageIds = () => { if (status != null && status.pages != null) { return status.pages.map(page =>
{ page.path }
); } return <>; }; return ( { t('private_legacy_pages.modal.title') }

{/* Todo: change the way to show path on modal when too many pages are selected */} {/* https://redmine.weseek.co.jp/issues/82787 */} {renderPageIds()}
{renderForm()}
); };