UploadSurat.js 5.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192
  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. };
  70. }
  71. onDrop = (files) => {
  72. this.setState({
  73. files: files.map((file) =>
  74. Object.assign(file, {
  75. preview: URL.createObjectURL(file),
  76. })
  77. ),
  78. stat: "Added " + files.length + " file(s)",
  79. });
  80. this.props.setUploadSuratSanksi(this.state);
  81. };
  82. uploadFiles = (e) => {
  83. e.preventDefault();
  84. e.stopPropagation();
  85. this.setState({
  86. stat: this.state.files.length ? "Dropzone ready to upload " + this.state.files.length + " file(s)" : "No files added.",
  87. });
  88. this.props.setUploadSuratSanksi(this.state);
  89. };
  90. clearFiles = (e) => {
  91. e.preventDefault();
  92. e.stopPropagation();
  93. this.setState({
  94. stat: this.state.files.length ? this.state.files.length + " file(s) cleared." : "No files to clear.",
  95. });
  96. this.setState({
  97. files: [],
  98. });
  99. this.props.setUploadSuratSanksi(this.state);
  100. };
  101. setNomorSanksi = (e) => {
  102. this.setState({ nomorSanksi: e.target.value });
  103. this.props.setUploadSuratSanksi(this.state);
  104. };
  105. setKeterangan = (e) => {
  106. this.setState({ keterangan: e.target.value });
  107. this.props.setUploadSuratSanksi(this.state);
  108. };
  109. render() {
  110. const { files } = this.state;
  111. const thumbs = files.map((file, index) => (
  112. <div md={3} key={index}>
  113. {/* <img className="img-fluid mb-2" src={file.preview} alt="Item" /> */}
  114. <span className="text-left">{index + 1}. {file.name}</span>
  115. </div>
  116. ));
  117. return (
  118. <form className="form-horizontal" method="get" action="/" onSubmit={this.onSubmit}>
  119. <FormGroup row>
  120. <label className="col-md-2 col-form-label">Nomor Surat:</label>
  121. <div className="col-md-10">
  122. <Input type="text" value={this.state.nomorSanksi} onChange={this.setNomorSanksi} />
  123. </div>
  124. </FormGroup>
  125. <FormGroup row className="mt-3">
  126. <label className="col-md-2 col-form-label">Keterangan</label>
  127. <div className="col-md-10">
  128. <Input type="textarea" value={this.state.keterangan} onChange={this.setKeterangan} required />
  129. {/* <span className="form-text">Deskripsi pelaporan minimum karakter 50 maksimum 200 karakter</span> */}
  130. </div>
  131. </FormGroup>
  132. <FormGroup row className="mt-3">
  133. <label className="col-md-2 col-form-label">List sanksi </label>
  134. <div className="col-md-10">
  135. <Select
  136. options={listSanksi}
  137. formatOptionLabel={formatOptionLabel}
  138. isMulti
  139. />
  140. </div>
  141. </FormGroup>
  142. <TmtDate />
  143. <FormGroup row>
  144. <label className="col-md-2 col-form-label">Dokumen Surat Sanksi<span className="text-danger">*</span>:</label>
  145. <div className="col-md-10">
  146. <DropzoneWrapper className="" onDrop={this.onDrop}>
  147. {({ getRootProps, getInputProps, isDragActive }) => {
  148. return (
  149. <div {...getRootProps()} className={"dropzone card" + (isDragActive ? "dropzone-drag-active" : "")}>
  150. <input {...getInputProps()} />
  151. <div className="dropzone-style-1">
  152. <div className="center-ver-hor dropzone-previews flex">{this.state.files.length > 0 ? <Row><span className="text-left">{thumbs}</span></Row> :
  153. <div className="text-center fa-2x icon-cloud-upload mr-2 ">
  154. <h5 className="text-center dz-default dz-message">Klik untuk upload dokumen</h5>
  155. </div>
  156. }
  157. </div>
  158. </div>
  159. <div className="d-flex align-items-center">
  160. <small className="ml-auto">
  161. <button type="button" className="btn btn-link" onClick={this.clearFiles}>
  162. Reset dokumen
  163. </button>
  164. </small>
  165. </div>
  166. </div>
  167. );
  168. }}
  169. </DropzoneWrapper>
  170. {/* <span className="form-text">Multiple files upload</span> */}
  171. <p className="mrgn-top-5">
  172. Ukuran setiap dokumen maksimal 15mb
  173. </p>
  174. </div>
  175. </FormGroup>
  176. </form>
  177. );
  178. }
  179. }
  180. export default UploadSurat;