import React, { useState, useCallback } from 'react'; import PropTypes from 'prop-types'; import { withTranslation } from 'react-i18next'; import { Modal, ModalHeader, ModalBody, ModalFooter, } from 'reactstrap'; import AppContainer from '~/client/services/AppContainer'; import { toastSuccess, toastError } from '~/client/util/apiNotification'; import { apiv3Post } from '~/client/util/apiv3-client'; import { withUnstatedContainers } from './UnstatedUtils'; const ArchiveCreateModal = (props) => { const { t, appContainer } = props; const [isCommentDownload, setIsCommentDownload] = useState(false); const [isAttachmentFileDownload, setIsAttachmentFileDownload] = useState(false); const [isSubordinatedPageDownload, setIsSubordinatedPageDownload] = useState(false); const [fileType, setFileType] = useState('markdown'); const [hierarchyType, setHierarchyType] = useState('allSubordinatedPage'); const [hierarchyValue, setHierarchyValue] = useState(1); function changeIsCommentDownloadHandler() { setIsCommentDownload(!isCommentDownload); } function changeIsAttachmentFileDownloadHandler() { setIsAttachmentFileDownload(!isAttachmentFileDownload); } function changeIsSubordinatedPageDownloadHandler() { setIsSubordinatedPageDownload(!isSubordinatedPageDownload); } function closeModalHandler() { if (props.onClose == null) { return; } props.onClose(); } const handleChangeFileType = useCallback( (filetype) => { setFileType(filetype); }, [], ); function handleChangeSubordinatedType(hierarchyType) { setHierarchyType(hierarchyType); } function handleHierarchyDepth(hierarchyValue) { setHierarchyValue(hierarchyValue); } async function done() { try { await apiv3Post('/page/archive', { rootPagePath: props.path, isCommentDownload, isAttachmentFileDownload, isSubordinatedPageDownload, fileType, hierarchyType, hierarchyValue, }); toastSuccess(t('Submitted the request to create the archive')); closeModalHandler(); } catch (e) { toastError(e); } } return ( {t('Create Archive Page')}

{props.path}
{ handleChangeFileType('markdown'); }} />
{ handleChangeFileType('pdf'); }} />
{isSubordinatedPageDownload && ( <>
{ handleChangeSubordinatedType('allSubordinatedPage'); }} />
{ handleChangeSubordinatedType('decideHierarchy'); }} />
{ handleHierarchyDepth(e.target.value); }} />
)}
{/* TO DO implement correct number at GW-3053 */} 合計{props.totalPages}ページ取得 {props.errorMessage}
); }; const ArchiveCreateModalWrapper = withUnstatedContainers(ArchiveCreateModal, [AppContainer]); ArchiveCreateModal.propTypes = { t: PropTypes.func.isRequired, // i18next appContainer: PropTypes.instanceOf(AppContainer).isRequired, isOpen: PropTypes.bool.isRequired, onClose: PropTypes.func, path: PropTypes.string.isRequired, totalPages: PropTypes.number, errorMessage: PropTypes.string, }; export default withTranslation()(ArchiveCreateModalWrapper);