import React, { Component } from "react"; import Router from "next/router"; import Link from "next/link"; import Select from "react-select"; import DetailSanksi from "@/components/Main/DetailSanksi"; import Header from "@/components/Main/Header"; import DetailPT from "@/components/Main/DetailPT"; import PermohonanPT from "@/components/Main/PermohonanPT"; import Riwayat from "@/components/PencabutanSanksi/Riwayat"; import { getOneSanksi } from "@/actions/sanksi"; import { addJawabanCabutSanksi } from "@/actions/cabutSanksi"; import ContentWrapper from "@/components/Layout/ContentWrapper"; import { Row, Col, Card, CardBody, FormGroup, Button, Input, Modal, ModalHeader, ModalBody, ModalFooter } from "reactstrap"; import { getPT } from "@/actions/PT"; import Loader from "@/components/Common/Loader"; import { toast } from "react-toastify"; import { connect } from "react-redux"; import { Formik, Form, Field, ErrorMessage } from "formik"; import * as Yup from "yup"; import { getCsrf } from "../../../actions/security"; import Swal from "sweetalert2"; import RiwayatPerbaikan from "../../../components/PencabutanSanksi/RiwayatPerbaikan"; import { getAllCatatan } from "../../../actions/catatan"; import TableRiwayatCatatan from "../../../components/Main/TableRiwayatCatatan"; const checkIfFilesAreTooBig = (files) => { let valid = true; if (files) { files.map((file) => { if (file.size > 15 * 1024 * 1024) { valid = false; } }); } return valid; }; const checkIfFilesAreCorrectType = (files) => { let valid = true; if (files) { files.map((file) => { if (!["image/jpeg", "image/png"].includes(file.type)) { valid = false; } }); } return valid; }; const jawabanCabutSanksiSchema = Yup.object().shape({ status: Yup.string().required("Harap Diisi"), keterangan: Yup.string().max(200).notRequired(), dokumen: Yup.array().notRequired().test("filesize", "Maksimal ukuran dokumen 15mb", checkIfFilesAreTooBig), }); 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 selectInstanceId = 1; class JawabanPencabutanSanksi extends Component { constructor(props) { super(props); this.state = { selectedOption: null, files: [], keterangan: "", sanksi: {}, pt: null, data: {}, selectedFile: {}, }; } static getInitialProps = async ({ query }) => ({ query }); componentDidMount = async () => { const { query, token } = this.props; const idSanksi = query.id; const sanksi = await getOneSanksi(token, query.id); const Catatan = await getAllCatatan(token, idSanksi,"Pencabutan Sanksi") const pt = sanksi.data?.laporan?.pt; this.setState({ sanksi, pt,Catatan }); }; toggleModal = () => { this.setState({ modal: !this.state.modal, }); }; handleChangeSelect = (selectedOption) => { this.setState({ selectedOption }); }; 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] })) }; uploadFiles = (e) => { e.preventDefault(); e.stopPropagation(); this.setState({ stat: this.state.files.length ? "Dropzone ready to upload " + this.state.files.length + " file(s)" : "No files added.", }); }; clearFiles = (e) => { e.preventDefault(); e.stopPropagation(); this.setState({ stat: this.state.files.length ? this.state.files.length + " file(s) cleared." : "No files to clear.", }); this.setState({ files: [], }); }; setKeterangan = (e) => { this.setState({ keterangan: e.target.value }); }; handleSimpan = async () => { if (this.props?.user?.role.id === 2024) { Swal.fire({ icon: 'error', title: 'Oops...', html: 'Maaf anda tidak memiliki akses untuk menyelesaikan

proses ini.

', confirmButtonColor: "#3e3a8e", confirmButtonText: 'Oke' // footer: 'Why do I have this issue?' }) } else { const getToken = await getCsrf(); const _csrf = getToken.token; const { data } = this.state; const { token, query } = this.props; const formdata = new FormData(); formdata.append("status", data.status); formdata.append("keterangan", data.keterangan); this.state.files.forEach((e) => { formdata.append("dokumen", e); }); const toastid = toast.loading("Please wait..."); const added = await addJawabanCabutSanksi(token, query.id, formdata, _csrf); if (!added) { toast.update(toastid, { render: "Error", type: "error", isLoading: false, autoClose: true, closeButton: true }); } else { toast.update(toastid, { render: "Success", type: "success", isLoading: false, autoClose: true, closeButton: true }); Router.push({ pathname: "/app/pencabutan-sanksi", }); } } }; render() { const { files, selectedOption, sanksi, pt,Catatan } = 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} {sanksi.data ? ( {sanksi.data?.pengajuan?.cabut_sanksi && < PermohonanPT data={sanksi.data?.pengajuan?.cabut_sanksi} role={this.props.user.role.id} /> }

Jawaban

{ this.setState({ data }); if (sanksi.data.jawaban?.cabut_sanksi) this.toggleModal(); else await this.handleSimpan(); }} > {({ isSubmitting }) => (
{({ field, form }) => ( } {/* Deskripsi pelaporan minimum karakter 50 maksimum 200 karakter */}
) : ( "" )} {selectedOption && selectedOption.value === "Rekomendasi Perbaikan" ? (
{({ field, form, meta }) => ( { this.onDrop(e); form.setFieldValue(field.name, e); }} > {({ getRootProps, getInputProps, isDragActive }) => { return (
{this.state.files.length > 0 ?
Klik untuk tambah file
:
Klik untuk upload dokumen
}
); }}
)}
{thumbs}

Ukuran setiap dokumen maksimal 15mb

) : (
{({ field, form, meta }) => ( { this.onDrop(e); form.setFieldValue(field.name, e); }} > {({ getRootProps, getInputProps, isDragActive }) => { return (
{this.state.files.length > 0 ?
Klik untuk tambah file
:
Klik untuk upload dokumen
}
); }}
)}
{thumbs}

Ukuran setiap dokumen maksimal 15mb

)}
)}
) : ( )} {pt ? : } {sanksi.data && ( )} {Catatan?.data && ( )} {sanksi.data && ( )} Apakah anda yakin ingin mengubah jawaban sebelumnya? {" "} ); } } const mapStateToProps = (state) => ({ user: state.user, token: state.token }); export default connect(mapStateToProps)(JawabanPencabutanSanksi);