UploadSurat.js 5.5 KB

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