import React, { Component } from "react"; import { Row, Col, Input, FormGroup, Label, Progress, Button } from "reactstrap"; import Select from "react-select"; import Swal from "sweetalert2"; import * as Yup from "yup"; import { connect } from "react-redux"; import { Formik, Form, Field, ErrorMessage } from "formik"; import { updateLaporan } from "../../actions/pelaporan" import { getCsrf } from "../../actions/security"; import { ToastContainer, toast } from "react-toastify"; import Router from "next/router"; import { createLog } from "../../actions/log"; const checkIfFilesAreTooBig = (files) => { let valid = true; if (files) { files.map((file) => { if (file.size > 15 * 1024 * 1024) { valid = false; } }); } return valid; }; let Dropzone = null; class DropzoneWrapper extends Component { state = { isClient: false, }; componentDidMount = () => { Dropzone = require("react-dropzone").default; this.setState({ isClient: true }); }; render() { return Dropzone ? {this.props.children} : null; } } const ditutupSchema = Yup.object().shape({ keterangan: Yup.string().required("Harus diisi"), dokumen: Yup.array().test("filesize", "Maksimal ukuran dokumen 15mb", checkIfFilesAreTooBig), }); const status = [ { value: "Sanksi", label: "Sanksi", className: "State-ACT" }, { value: "Ditutup", label: "Ditutup", className: "State-ACT" }, ]; export class Redudansi extends Component { constructor(props) { super(props); const tmt_awal = new Date(); this.state = { files: [], keterangan: "", selectedOption: null, }; } async componentDidMount() { this.defaultStatus(); } defaultStatus = async () => { return this.setState({ selectedOption: status[0] }); }; handleChangeSelect = (selectedOption) => this.setState({ selectedOption }, this.setDataStatusLaporan); // handleChangeSelect = (selectedOption) => { // this.state.selectedOption = selectedOption // this.setDataStatusLaporan() // } getStatus = () => (status); onDrop = (selectedFile) => { this.setState({ selectedFile: selectedFile.map((file) => Object.assign(file, { preview: URL.createObjectURL(file), }) ), stat: "Added " + selectedFile.length + " file(s)", }); const selectFile = this.state.selectedFile this.setState(prevState => ({ files: [...prevState.files, ...selectFile] })) }; logDitutup = async () => { const getToken = await getCsrf(); const _csrf = getToken.token; const { token } = this.props; await createLog(token, { aktivitas: `Berhasil menutup laporan, id: ${this.props.id}`, _csrf: _csrf, menu: "Sanksi" }); } handleTutupLaporan = async (data, value) => { if (this.props.role === 2024) { Swal.fire({ icon: 'error', title: 'Oops...', html: 'Maaf anda tidak memiliki akses untuk menyelesaikan

proses ini.

', confirmButtonColor: "#3e3a8e", confirmButtonText: 'Oke' }) } else { const getToken = await getCsrf(); const _csrf = getToken.token; const { token } = this.props; const formdata = new FormData(); formdata.append("keterangan", data.keterangan); this.state.files.forEach((e) => { formdata.append("dokumen", e); }); formdata.append("aktif", "false"); await toast.promise(updateLaporan(token, this.props.id, formdata, _csrf + `&redudansi=true`), { pending: "Loading", success: { render: "success", autoClose: 1000 }, error: "Error", }); await this.logDitutup() await Router.push({ pathname: "/app/sanksi", }); } }; setDataStatusLaporan = () => { this.props.setDataStatusLaporan(this.state) } render() { const { files, selectedOption } = this.state; const removeFile = file => () => { const newFiles = [...files] newFiles.splice(newFiles.indexOf(file), 1) this.setState({ files: newFiles, }); } const thumbs = files.map((file, index) => (

  {file.name} ); }} )} {thumbs}

Ukuran setiap dokumen maksimal 15mb

)} )} ); } } // const mapStateToProps = (state) => ({ user: state.user, token: state.token }); // export default connect(mapStateToProps)(Redudansi); export default Redudansi