ArchiveCreateModal.jsx 6.4 KB

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