ArchiveCreateModal.jsx 8.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243
  1. import React, { useState, useCallback } from 'react';
  2. import PropTypes from 'prop-types';
  3. import { withTranslation } from 'react-i18next';
  4. import {
  5. Modal, ModalHeader, ModalBody, ModalFooter,
  6. } from 'reactstrap';
  7. import AppContainer from '../services/AppContainer';
  8. import { withUnstatedContainers } from './UnstatedUtils';
  9. import { toastSuccess, toastError } from '../util/apiNotification';
  10. const ArchiveCreateModal = (props) => {
  11. const { t, appContainer } = props;
  12. const [isCommentDownload, setIsCommentDownload] = useState(false);
  13. const [isAttachmentFileDownload, setIsAttachmentFileDownload] = useState(false);
  14. const [isSubordinatedPageDownload, setIsSubordinatedPageDownload] = useState(false);
  15. const [fileType, setFileType] = useState('markDown');
  16. const [hierarchyType, setHierarchyType] = useState('allSubordinatedPage');
  17. const [hierarchyValue, setHierarchyValue] = useState(1);
  18. function changeIsCommentDownloadHandler() {
  19. setIsCommentDownload(!isCommentDownload);
  20. }
  21. function changeIsAttachmentFileDownloadHandler() {
  22. setIsAttachmentFileDownload(!isAttachmentFileDownload);
  23. }
  24. function changeIsSubordinatedPageDownloadHandler() {
  25. setIsSubordinatedPageDownload(!isSubordinatedPageDownload);
  26. }
  27. function closeModalHandler() {
  28. if (props.onClose == null) {
  29. return;
  30. }
  31. props.onClose();
  32. }
  33. const handleChangeFileType = useCallback(
  34. (filetype) => {
  35. setFileType(filetype);
  36. },
  37. [],
  38. );
  39. function handleChangeSubordinatedType(hierarchyType) {
  40. setHierarchyType(hierarchyType);
  41. }
  42. function handleHierarchyDepth(hierarchyValue) {
  43. setHierarchyValue(hierarchyValue);
  44. }
  45. async function done() {
  46. try {
  47. await appContainer.apiv3Post('/page/archive', {
  48. isCommentDownload,
  49. isAttachmentFileDownload,
  50. isSubordinatedPageDownload,
  51. fileType,
  52. hierarchyType,
  53. hierarchyValue,
  54. });
  55. toastSuccess(t('Submitted the request to create the archive'));
  56. }
  57. catch (e) {
  58. toastError(e);
  59. }
  60. }
  61. return (
  62. <Modal isOpen={props.isOpen} toggle={closeModalHandler}>
  63. <ModalHeader tag="h4" toggle={closeModalHandler} className="bg-primary text-white">
  64. {t('Create Archive Page')}
  65. </ModalHeader>
  66. <ModalBody>
  67. <div className="form-group">
  68. <div className="form-group">
  69. <label>{t('Target page')}</label>
  70. <br />
  71. <code>{props.path}</code>
  72. </div>
  73. <div className="custom-control-inline">
  74. <label>{t('File type')}: </label>
  75. </div>
  76. <div className="custom-control custom-radio custom-control-inline ">
  77. <input
  78. type="radio"
  79. className="custom-control-input"
  80. id="customRadio1"
  81. name="isFileType"
  82. value="customRadio1"
  83. checked={fileType === 'markDown'}
  84. onChange={() => {
  85. handleChangeFileType('markDown');
  86. }}
  87. />
  88. <label className="custom-control-label" htmlFor="customRadio1">
  89. MarkDown(.md)
  90. </label>
  91. </div>
  92. <div className="custom-control custom-radio custom-control-inline ">
  93. <input
  94. type="radio"
  95. className="custom-control-input"
  96. id="customRadio2"
  97. name="isFileType"
  98. value="customRadio2"
  99. checked={fileType === 'pdf'}
  100. onChange={() => {
  101. handleChangeFileType('pdf');
  102. }}
  103. />
  104. <label className="custom-control-label" htmlFor="customRadio2">
  105. PDF(.pdf)
  106. </label>
  107. </div>
  108. </div>
  109. <div className="my-1 custom-control custom-checkbox custom-checkbox-info">
  110. <input
  111. className="custom-control-input"
  112. name="comment"
  113. id="commentFile"
  114. type="checkbox"
  115. checked={isCommentDownload}
  116. onChange={changeIsCommentDownloadHandler}
  117. />
  118. <label className="custom-control-label" htmlFor="commentFile">
  119. {t('Include Comment')}
  120. </label>
  121. </div>
  122. <div className="my-1 custom-control custom-checkbox custom-checkbox-info">
  123. <input
  124. className="custom-control-input"
  125. id="downloadFile"
  126. type="checkbox"
  127. checked={isAttachmentFileDownload}
  128. onChange={changeIsAttachmentFileDownloadHandler}
  129. />
  130. <label className="custom-control-label" htmlFor="downloadFile">
  131. {t('Include Attachment File')}
  132. </label>
  133. </div>
  134. <div className="my-1 custom-control custom-checkbox custom-checkbox-info">
  135. <input
  136. className="custom-control-input"
  137. id="subordinatedFile"
  138. type="checkbox"
  139. checked={isSubordinatedPageDownload}
  140. onChange={changeIsSubordinatedPageDownloadHandler}
  141. />
  142. <label className="custom-control-label" htmlFor="subordinatedFile">
  143. {t('Include Subordinated Page')}
  144. </label>
  145. {isSubordinatedPageDownload && (
  146. <>
  147. <div className="FormGroup">
  148. <div className="my-1 custom-control custom-radio custom-control-inline ">
  149. <input
  150. type="radio"
  151. className="custom-control-input"
  152. id="customRadio3"
  153. name="isSubordinatedType"
  154. value="customRadio3"
  155. disabled={!isSubordinatedPageDownload}
  156. checked={hierarchyType === 'allSubordinatedPage'}
  157. onChange={() => {
  158. handleChangeSubordinatedType('allSubordinatedPage');
  159. }}
  160. />
  161. <label className="custom-control-label" htmlFor="customRadio3">
  162. {t('All Subordinated Page')}
  163. </label>
  164. </div>
  165. </div>
  166. <div className="FormGroup">
  167. <div className="my-1 custom-control custom-radio custom-control-inline">
  168. <input
  169. type="radio"
  170. className="custom-control-input"
  171. id="customRadio4"
  172. name="isSubordinatedType"
  173. value="customRadio4"
  174. disabled={!isSubordinatedPageDownload}
  175. checked={hierarchyType === 'decideHierarchy'}
  176. onChange={() => {
  177. handleChangeSubordinatedType('decideHierarchy');
  178. }}
  179. />
  180. <label className="my-1 custom-control-label" htmlFor="customRadio4">
  181. {t('Specify Hierarchy')}
  182. </label>
  183. </div>
  184. </div>
  185. <div className="my-1 custom-control costom-control-inline">
  186. <input
  187. type="number"
  188. min="0"
  189. max="10"
  190. disabled={hierarchyType === 'allSubordinatedPage'}
  191. value={hierarchyValue}
  192. placeholder="1"
  193. onChange={(e) => {
  194. handleHierarchyDepth(e.target.value);
  195. }}
  196. />
  197. </div>
  198. </>
  199. )}
  200. </div>
  201. </ModalBody>
  202. <ModalFooter>
  203. 合計{props.totalPages}ページを取得
  204. {props.errorMessage}
  205. <button type="button" className="btn btn-primary" onClick={done}>
  206. Done
  207. </button>
  208. </ModalFooter>
  209. </Modal>
  210. );
  211. };
  212. const ArchiveCreateModalWrapper = withUnstatedContainers(ArchiveCreateModal, [AppContainer]);
  213. ArchiveCreateModal.propTypes = {
  214. t: PropTypes.func.isRequired, // i18next
  215. appContainer: PropTypes.instanceOf(AppContainer).isRequired,
  216. isOpen: PropTypes.bool.isRequired,
  217. onClose: PropTypes.func,
  218. path: PropTypes.string.isRequired,
  219. totalPages: PropTypes.number,
  220. errorMessage: PropTypes.string,
  221. };
  222. export default withTranslation()(ArchiveCreateModalWrapper);