ArchiveCreateModal.jsx 8.2 KB

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