import React, { Component } from "react";
import { insertPemeriksaan } from "@/actions/pemeriksaan";
import { Row, Col, Card, CardBody, FormGroup, Input, Button, Progress } from "reactstrap";
import { toast } from "react-toastify";
import { Formik, Form, Field, ErrorMessage } from "formik";
import * as Yup from "yup";
import { connect } from "react-redux";
import { getOneSanksi, addRekomendasiDelegasi } from "@/actions/sanksi";
import moment from "moment";
import 'moment/locale/id';
import { getCsrf } from "../../actions/security";
import Swal from "sweetalert2";
moment.locale('id');
const selectInstanceId = 1;
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 rekomendasiSchema = Yup.object().shape({
dokumen: Yup.array().min(1).required("Wajib diisi").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 ?
proses ini.
', confirmButtonColor: "#3e3a8e", confirmButtonText: 'Oke' // footer: 'Why do I have this issue?' }) } else { const getToken = await getCsrf(); const _csrf = getToken.token; const { token, query } = this.props; const { id } = query; const formdata = new FormData(); this.state.files.forEach((e) => { formdata.append("dokumen", e); }); const toastid = toast.loading("Please wait..."); const added = await addRekomendasiDelegasi(token, 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 }); const sanksi = await getOneSanksi(token, id); this.setState({ sanksi, files: [] }); resetForm(); // Router.push({ // pathname: "/app/rekomendasi-delegasi", // }); } } }; render() { const { files } = 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}
)); return (Dokumen Rekomendasi Delegasi