ArchiveCreateModal.jsx 8.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244
  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 '~/client/services/AppContainer';
  8. import { withUnstatedContainers } from './UnstatedUtils';
  9. import { toastSuccess, toastError } from '~/client/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. rootPagePath: props.path,
  49. isCommentDownload,
  50. isAttachmentFileDownload,
  51. isSubordinatedPageDownload,
  52. fileType,
  53. hierarchyType,
  54. hierarchyValue,
  55. });
  56. toastSuccess(t('Submitted the request to create the archive'));
  57. closeModalHandler();
  58. }
  59. catch (e) {
  60. toastError(e);
  61. }
  62. }
  63. return (
  64. <Modal isOpen={props.isOpen} toggle={closeModalHandler}>
  65. <ModalHeader tag="h4" toggle={closeModalHandler} className="bg-primary text-white">
  66. {t('Create Archive Page')}
  67. </ModalHeader>
  68. <ModalBody>
  69. <div className="form-group">
  70. <div className="form-group">
  71. <label>{t('Target page')}</label>
  72. <br />
  73. <code>{props.path}</code>
  74. </div>
  75. <div className="custom-control-inline">
  76. <label>{t('File type')}: </label>
  77. </div>
  78. <div className="custom-control custom-radio custom-control-inline ">
  79. <input
  80. type="radio"
  81. className="custom-control-input"
  82. id="customRadio1"
  83. name="isFileType"
  84. value="customRadio1"
  85. checked={fileType === 'markdown'}
  86. onChange={() => {
  87. handleChangeFileType('markdown');
  88. }}
  89. />
  90. <label className="custom-control-label" htmlFor="customRadio1">
  91. MarkDown(.md)
  92. </label>
  93. </div>
  94. <div className="custom-control custom-radio custom-control-inline ">
  95. <input
  96. type="radio"
  97. className="custom-control-input"
  98. id="customRadio2"
  99. name="isFileType"
  100. value="customRadio2"
  101. checked={fileType === 'pdf'}
  102. onChange={() => {
  103. handleChangeFileType('pdf');
  104. }}
  105. />
  106. <label className="custom-control-label" htmlFor="customRadio2">
  107. PDF(.pdf)
  108. </label>
  109. </div>
  110. </div>
  111. <div className="my-1 custom-control custom-checkbox custom-checkbox-info">
  112. <input
  113. className="custom-control-input"
  114. name="comment"
  115. id="commentFile"
  116. type="checkbox"
  117. checked={isCommentDownload}
  118. onChange={changeIsCommentDownloadHandler}
  119. />
  120. <label className="custom-control-label" htmlFor="commentFile">
  121. {t('Include Comment')}
  122. </label>
  123. </div>
  124. <div className="my-1 custom-control custom-checkbox custom-checkbox-info">
  125. <input
  126. className="custom-control-input"
  127. id="downloadFile"
  128. type="checkbox"
  129. checked={isAttachmentFileDownload}
  130. onChange={changeIsAttachmentFileDownloadHandler}
  131. />
  132. <label className="custom-control-label" htmlFor="downloadFile">
  133. {t('Include Attachment File')}
  134. </label>
  135. </div>
  136. <div className="my-1 custom-control custom-checkbox custom-checkbox-info">
  137. <input
  138. className="custom-control-input"
  139. id="subordinatedFile"
  140. type="checkbox"
  141. checked={isSubordinatedPageDownload}
  142. onChange={changeIsSubordinatedPageDownloadHandler}
  143. />
  144. <label className="custom-control-label" htmlFor="subordinatedFile">
  145. {t('Include Subordinated Page')}
  146. </label>
  147. {isSubordinatedPageDownload && (
  148. <>
  149. <div className="FormGroup">
  150. <div className="my-1 custom-control custom-radio custom-control-inline ">
  151. <input
  152. type="radio"
  153. className="custom-control-input"
  154. id="customRadio3"
  155. name="isSubordinatedType"
  156. value="customRadio3"
  157. disabled={!isSubordinatedPageDownload}
  158. checked={hierarchyType === 'allSubordinatedPage'}
  159. onChange={() => {
  160. handleChangeSubordinatedType('allSubordinatedPage');
  161. }}
  162. />
  163. <label className="custom-control-label" htmlFor="customRadio3">
  164. {t('All Subordinated Page')}
  165. </label>
  166. </div>
  167. </div>
  168. <div className="FormGroup">
  169. <div className="my-1 custom-control custom-radio custom-control-inline">
  170. <input
  171. type="radio"
  172. className="custom-control-input"
  173. id="customRadio4"
  174. name="isSubordinatedType"
  175. value="customRadio4"
  176. disabled={!isSubordinatedPageDownload}
  177. checked={hierarchyType === 'decideHierarchy'}
  178. onChange={() => {
  179. handleChangeSubordinatedType('decideHierarchy');
  180. }}
  181. />
  182. <label className="my-1 custom-control-label" htmlFor="customRadio4">
  183. {t('Specify Hierarchy')}
  184. </label>
  185. </div>
  186. </div>
  187. <div className="my-1 custom-control costom-control-inline">
  188. <input
  189. type="number"
  190. min="1"
  191. max="10"
  192. disabled={hierarchyType === 'allSubordinatedPage'}
  193. value={hierarchyValue}
  194. placeholder="1"
  195. onChange={(e) => {
  196. handleHierarchyDepth(e.target.value);
  197. }}
  198. />
  199. </div>
  200. </>
  201. )}
  202. </div>
  203. </ModalBody>
  204. <ModalFooter>
  205. {/* TO DO implement correct number at GW-3053 */}
  206. 合計{props.totalPages}ページ取得
  207. {props.errorMessage}
  208. <button type="button" className="btn btn-primary" onClick={done}>
  209. Done
  210. </button>
  211. </ModalFooter>
  212. </Modal>
  213. );
  214. };
  215. const ArchiveCreateModalWrapper = withUnstatedContainers(ArchiveCreateModal, [AppContainer]);
  216. ArchiveCreateModal.propTypes = {
  217. t: PropTypes.func.isRequired, // i18next
  218. appContainer: PropTypes.instanceOf(AppContainer).isRequired,
  219. isOpen: PropTypes.bool.isRequired,
  220. onClose: PropTypes.func,
  221. path: PropTypes.string.isRequired,
  222. totalPages: PropTypes.number,
  223. errorMessage: PropTypes.string,
  224. };
  225. export default withTranslation()(ArchiveCreateModalWrapper);