UploadSurat.js 7.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263
  1. import React, { Component } from "react";
  2. import { Row, Col, Input, FormGroup } from "reactstrap";
  3. import Select from "react-select";
  4. import DatePicker from "react-datepicker";
  5. import "react-datepicker/dist/react-datepicker.css";
  6. import ms from "ms";
  7. import TmtDate from "./TmtDate";
  8. import { addDays, addMonths } from 'date-fns';
  9. let Dropzone = null;
  10. class DropzoneWrapper extends Component {
  11. state = {
  12. isClient: false,
  13. };
  14. componentDidMount = () => {
  15. Dropzone = require("react-dropzone").default;
  16. this.setState({ isClient: true });
  17. };
  18. render() {
  19. return Dropzone ? <Dropzone {...this.props}>{this.props.children}</Dropzone> : null;
  20. }
  21. }
  22. const data = [
  23. {
  24. value: "Sanksi Administratif Sedang",
  25. // label_sanksi: "- Sanksi Administratif ringan"
  26. },
  27. {
  28. sanksi: "Penghentian Pembinaan PT",
  29. value: "Penghentian Pembinaan PT",
  30. label_sanksi: "- Sanksi Administratif Berat",
  31. },
  32. {
  33. sanksi: "Pencabutan Izin Perguruan Tinggi Swasta",
  34. value: "Pencabutan Izin Perguruan Tinggi Swasta",
  35. label_sanksi: "- Sanksi Administratif Berat",
  36. },
  37. {
  38. sanksi: "Penghentian Pembinaan Program Studi",
  39. value: "Penghentian Pembinaan Program Studi",
  40. label_sanksi: "- Sanksi Administratif Berat",
  41. },
  42. {
  43. sanksi: "Pencabutan Izin Program Studi",
  44. value: "Pencabutan Izin Program Studi",
  45. label_sanksi: "- Sanksi Administratif Berat",
  46. },
  47. {
  48. sanksi: "Pembubaran Perguruan Tinggi Negeri",
  49. value: "Pembubaran Perguruan Tinggi Negeri",
  50. label_sanksi: "- Sanksi Administratif Berat",
  51. },
  52. ];
  53. const listSanksi = data.map((d) => ({
  54. value: d.value,
  55. label: d.sanksi,
  56. label_sanksi: d.label_sanksi,
  57. }));
  58. const formatOptionLabel = ({ value, sanksi, label_sanksi }) => (
  59. <div style={{ display: "flex" }}>
  60. <span className="">{value}</span>
  61. <div style={{ marginLeft: "10px", color: "#adaca8" }}>{label_sanksi}</div>
  62. </div>
  63. );
  64. export class UploadSurat extends Component {
  65. constructor(props) {
  66. super(props);
  67. const tmt_awal = new Date();
  68. this.state = {
  69. files: [],
  70. nomorSanksi: "",
  71. keterangan: "",
  72. listSanksi: "",
  73. maxDay: "",
  74. isiTmt: "",
  75. awalsanksi: "",
  76. akhirsanksi: "",
  77. };
  78. }
  79. onDrop = (files) => {
  80. this.setState({
  81. files: files.map((file) =>
  82. Object.assign(file, {
  83. preview: URL.createObjectURL(file),
  84. })
  85. ),
  86. stat: "Added " + files.length + " file(s)",
  87. });
  88. this.props.setUploadSuratSanksi(this.state);
  89. };
  90. uploadFiles = (e) => {
  91. e.preventDefault();
  92. e.stopPropagation();
  93. this.setState({
  94. stat: this.state.files.length ? "Dropzone ready to upload " + this.state.files.length + " file(s)" : "No files added.",
  95. });
  96. this.props.setUploadSuratSanksi(this.state);
  97. };
  98. clearFiles = (e) => {
  99. e.preventDefault();
  100. e.stopPropagation();
  101. this.setState({
  102. stat: this.state.files.length ? this.state.files.length + " file(s) cleared." : "No files to clear.",
  103. });
  104. this.setState({
  105. files: [],
  106. });
  107. this.props.setUploadSuratSanksi(this.state);
  108. };
  109. setNomorSanksi = (e) => {
  110. this.setState({ nomorSanksi: e.target.value });
  111. this.props.setUploadSuratSanksi(this.state);
  112. };
  113. setKeterangan = (e) => {
  114. this.setState({ keterangan: e.target.value });
  115. this.props.setUploadSuratSanksi(this.state);
  116. };
  117. setListSanksi = (ls) => {
  118. this.setState({ listSanksi: ls.target.value });
  119. this.props.setUploadSuratSanksi(this.state);
  120. };
  121. handleChangeListSanksi = (listSanksi) => {
  122. this.setState({ listSanksi });
  123. this.props.setUploadSuratSanksi(this.state);
  124. };
  125. handleTmtDate = (startDate) => {
  126. this.setState({ startDate });
  127. this.props.setUploadSuratSanksi(this.state);
  128. };
  129. render() {
  130. const { files } = this.state;
  131. const thumbs = files.map((file, index) => (
  132. <div md={3} key={index}>
  133. {/* <img className="img-fluid mb-2" src={file.preview} alt="Item" /> */}
  134. <span className="text-left">
  135. {index + 1}. {file.name}
  136. </span>
  137. </div>
  138. ));
  139. return (
  140. <form className="form-horizontal" method="get" action="/" onSubmit={this.onSubmit}>
  141. <FormGroup row>
  142. <label className="col-md-2 col-form-label">Nomor Surat:</label>
  143. <div className="col-md-10">
  144. <Input type="text" value={this.state.nomorSanksi} onChange={this.setNomorSanksi} />
  145. </div>
  146. </FormGroup>
  147. <FormGroup row className="mt-3">
  148. <label className="col-md-2 col-form-label">Keterangan</label>
  149. <div className="col-md-10">
  150. <Input type="textarea" value={this.state.keterangan} onChange={this.setKeterangan} required />
  151. {/* <span className="form-text">Deskripsi pelaporan minimum karakter 50 maksimum 200 karakter</span> */}
  152. </div>
  153. </FormGroup>
  154. {/* <TmtDate setTmt={this.handleTmtDate} /> */}
  155. {/* <TmtDate /> */}
  156. <FormGroup row className="mt-3">
  157. <label className="col-md-2 col-form-label">Isi TMT</label>
  158. <span className="col-sm-3 float-left">
  159. <DatePicker
  160. selected={this.state.awalsanksi}
  161. onChange={(awalsanksi) => {
  162. this.setState({ awalsanksi })
  163. this.props.setUploadSuratSanksi(this.state);
  164. }}
  165. dateFormat="dd/MM/yyyy"
  166. maxDate={this.state.startDay}
  167. placeholderText="Dari Tanggal"
  168. />
  169. </span>
  170. <span className="col-sm-3 float-right">
  171. <DatePicker
  172. selected={this.state.akhirsanksi}
  173. onChange={(akhirsanksi) => {
  174. this.setState({ akhirsanksi })
  175. this.props.setUploadSuratSanksi(this.state);
  176. }}
  177. dateFormat="dd/MM/yyyy"
  178. minDate={this.state.awalsanksi}
  179. maxDate={addMonths(new Date(this.state.awalsanksi), 6)}
  180. placeholderText="Sampai tanggal"
  181. />
  182. </span>
  183. </FormGroup>
  184. <FormGroup row className="mt-1">
  185. <label className="col-md-2 col-form-label">TMT berlaku</label>
  186. <div className="col-md-10 mt-2">
  187. <b>{this.state.awalsanksi ? moment(this.state.awalsanksi).format("DD-MM-YYYY") : "-"}</b> hingga <b>{this.state.akhirsanksi ? moment(this.state.akhirsanksi).format("DD-MM-YYYY") : "-"}</b>
  188. </div>
  189. </FormGroup>
  190. <FormGroup row className="mt-3">
  191. <label className="col-md-2 col-form-label">List sanksi </label>
  192. <div className="col-md-10">
  193. <Select
  194. options={listSanksi}
  195. formatOptionLabel={formatOptionLabel}
  196. isMulti
  197. onChange={(e) => {
  198. this.handleChangeListSanksi(e);
  199. }}
  200. />
  201. </div>
  202. </FormGroup>
  203. <FormGroup row>
  204. <label className="col-md-2 col-form-label">
  205. Dokumen Surat Sanksi<span className="text-danger">*</span>:
  206. </label>
  207. <div className="col-md-10">
  208. <DropzoneWrapper className="" onDrop={this.onDrop}>
  209. {({ getRootProps, getInputProps, isDragActive }) => {
  210. return (
  211. <div {...getRootProps()} className={"dropzone card" + (isDragActive ? "dropzone-drag-active" : "")}>
  212. <input {...getInputProps()} />
  213. <div className="dropzone-style-1">
  214. <div className="center-ver-hor dropzone-previews flex">
  215. {this.state.files.length > 0 ? (
  216. <Row>
  217. <span className="text-left">{thumbs}</span>
  218. </Row>
  219. ) : (
  220. <div className="text-center fa-2x icon-cloud-upload mr-2 ">
  221. <h5 className="text-center dz-default dz-message">Klik untuk upload dokumen</h5>
  222. </div>
  223. )}
  224. </div>
  225. </div>
  226. <div className="d-flex align-items-center">
  227. <small className="ml-auto">
  228. <button type="button" className="btn btn-link" onClick={this.clearFiles}>
  229. Reset dokumen
  230. </button>
  231. </small>
  232. </div>
  233. </div>
  234. );
  235. }}
  236. </DropzoneWrapper>
  237. {/* <span className="form-text">Multiple files upload</span> */}
  238. <p className="mrgn-top-5">Ukuran setiap dokumen maksimal 15mb</p>
  239. </div>
  240. </FormGroup>
  241. </form>
  242. );
  243. }
  244. }
  245. export default UploadSurat;