ArchiveCreateModal.jsx 8.2 KB

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