ArchiveCreateModal.jsx 7.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216
  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. const ArchiveCreateModal = (props) => {
  8. const { t } = props;
  9. const [isCommentDownload, setIsCommentDownload] = useState(false);
  10. const [isFileDownload, setIsFileDownload] = useState(false);
  11. const [isSubordinatedPageDownload, setIsSubordinatedPageDownload] = useState(false);
  12. const [fileType, setFileType] = useState('markDown');
  13. const [hierarchyType, setHierarchyType] = useState('allSubordinatedPage');
  14. const [hierarchyValue, setHierarchyValue] = useState(1);
  15. function changeIsCommentDownloadHandler() {
  16. setIsCommentDownload(!isCommentDownload);
  17. }
  18. function changeIsFileDownloadHandler() {
  19. setIsFileDownload(!isFileDownload);
  20. }
  21. function changeIsSubordinatedPageDownloadHandler() {
  22. setIsSubordinatedPageDownload(!isSubordinatedPageDownload);
  23. }
  24. function closeModalHandler() {
  25. if (props.onClose == null) {
  26. return;
  27. }
  28. props.onClose();
  29. }
  30. const handleChangeFileType = useCallback(
  31. (filetype) => {
  32. setFileType(filetype);
  33. },
  34. [],
  35. );
  36. function handleChangeSubordinatedType(hierarchyType) {
  37. setHierarchyType(hierarchyType);
  38. }
  39. function handleHierarchyType(hierarchyValue) {
  40. setHierarchyValue(hierarchyValue);
  41. }
  42. return (
  43. <Modal isOpen={props.isOpen} toggle={closeModalHandler}>
  44. <ModalHeader tag="h4" toggle={closeModalHandler} className="bg-primary text-white">
  45. {t('Create Archive Page')}
  46. </ModalHeader>
  47. <ModalBody>
  48. <div className="form-group">
  49. <div className="form-group">
  50. <label>{t('Target page')}</label>
  51. <br />
  52. <code>{props.path}</code>
  53. </div>
  54. <div className="custom-control-inline">
  55. <label>{t('File type')}: </label>
  56. </div>
  57. <div className="custom-control custom-radio custom-control-inline ">
  58. <input
  59. type="radio"
  60. className="custom-control-input"
  61. id="customRadio1"
  62. name="isFileType"
  63. value="customRadio1"
  64. checked={fileType === 'markDown'}
  65. onChange={() => {
  66. handleChangeFileType('markDown');
  67. }}
  68. />
  69. <label className="custom-control-label" htmlFor="customRadio1">
  70. MarkDown(.md)
  71. </label>
  72. </div>
  73. <div className="custom-control custom-radio custom-control-inline ">
  74. <input
  75. type="radio"
  76. className="custom-control-input"
  77. id="customRadio2"
  78. name="isFileType"
  79. value="customRadio2"
  80. checked={fileType === 'pdf'}
  81. onChange={() => {
  82. handleChangeFileType('pdf');
  83. }}
  84. />
  85. <label className="custom-control-label" htmlFor="customRadio2">
  86. PDF(.pdf)
  87. </label>
  88. </div>
  89. </div>
  90. <div className="my-1 custom-control custom-checkbox custom-checkbox-info">
  91. <input
  92. className="custom-control-input"
  93. name="comment"
  94. id="commentFile"
  95. type="checkbox"
  96. checked={isCommentDownload}
  97. onChange={changeIsCommentDownloadHandler}
  98. />
  99. <label className="custom-control-label" htmlFor="commentFile">
  100. {t('Include Comment')}
  101. </label>
  102. </div>
  103. <div className="my-1 custom-control custom-checkbox custom-checkbox-info">
  104. <input
  105. className="custom-control-input"
  106. id="downloadFile"
  107. type="checkbox"
  108. checked={isFileDownload}
  109. onChange={changeIsFileDownloadHandler}
  110. />
  111. <label className="custom-control-label" htmlFor="downloadFile">
  112. {t('Include Attachment File')}
  113. </label>
  114. </div>
  115. <div className="my-1 custom-control custom-checkbox custom-checkbox-info">
  116. <input
  117. className="custom-control-input"
  118. id="subordinatedFile"
  119. type="checkbox"
  120. checked={isSubordinatedPageDownload}
  121. onChange={changeIsSubordinatedPageDownloadHandler}
  122. />
  123. <label className="custom-control-label" htmlFor="subordinatedFile">
  124. {t('Include Subordinated Page')}
  125. </label>
  126. {isSubordinatedPageDownload && (
  127. <>
  128. <div className="FormGroup">
  129. <div className="my-1 custom-control custom-radio custom-control-inline ">
  130. <input
  131. type="radio"
  132. className="custom-control-input"
  133. id="customRadio3"
  134. name="isSubordinatedType"
  135. value="customRadio3"
  136. disabled={!isSubordinatedPageDownload}
  137. checked={hierarchyType === 'allSubordinatedPage'}
  138. onChange={() => {
  139. handleChangeSubordinatedType('allSubordinatedPage');
  140. }}
  141. />
  142. <label className="custom-control-label" htmlFor="customRadio3">
  143. {t('All Subordinated Page')}
  144. </label>
  145. </div>
  146. </div>
  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="customRadio4"
  153. name="isSubordinatedType"
  154. value="customRadio4"
  155. disabled={!isSubordinatedPageDownload}
  156. checked={hierarchyType === 'decideHierarchy'}
  157. onChange={() => {
  158. handleChangeSubordinatedType('decideHierarchy');
  159. }}
  160. />
  161. <label className="my-1 custom-control-label" htmlFor="customRadio4">
  162. {t('Specify Hierarchy')}
  163. </label>
  164. </div>
  165. </div>
  166. <div className="my-1 custom-control costom-control-inline">
  167. <input
  168. type="number"
  169. min="0"
  170. max="10"
  171. disabled={hierarchyType === 'allSubordinatedPage'}
  172. value={hierarchyValue}
  173. placeholder="1"
  174. onChange={(e) => {
  175. handleHierarchyType(e.target.value);
  176. }}
  177. />
  178. </div>
  179. </>
  180. )}
  181. </div>
  182. </ModalBody>
  183. <ModalFooter>
  184. <button type="button" className="btn btn-primary">
  185. Done
  186. </button>
  187. </ModalFooter>
  188. </Modal>
  189. );
  190. };
  191. ArchiveCreateModal.propTypes = {
  192. t: PropTypes.func.isRequired, // i18next
  193. isOpen: PropTypes.bool.isRequired,
  194. onClose: PropTypes.func,
  195. path: PropTypes.string.isRequired,
  196. };
  197. export default withTranslation()(ArchiveCreateModal);