UploadSurat.js 5.9 KB

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