import React, { Component } from "react"; import { Row, Col, Card, CardBody, FormGroup, Input, Button, Modal, ModalHeader, ModalBody, ModalFooter } from "reactstrap"; import Router from "next/router"; import classnames from "classnames"; import ContentWrapper from "@/components/Layout/ContentWrapper"; import DetailSanksi from "@/components/RekomendasiDelegasi/DetailSanksi"; import TableRiwayat from "@/components/RekomendasiDelegasi/TableRiwayat"; import Header from "@/components/Main/Header"; import Link from "next/link"; import DetailPT from "@/components/Main/DetailPT"; import { getPelaporan } from "@/actions/pelaporan"; import { getOneSanksi } from "@/actions/sanksi"; import Loader from "@/components/Common/Loader"; import { connect } from "react-redux"; import { Formik, Form, Field, ErrorMessage } from "formik"; import * as Yup from "yup"; import { createLog } from "@/actions/log"; const stepNavitemStyle = { backgroundColor: "#fcfcfc", }; 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; 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().notRequired().test("filesize", "Maksimal ukuran dokumen 15mb", checkIfFilesAreTooBig), }); class Detail extends Component { constructor(props) { super(props); this.state = { sanksi: {}, files: [], pt: {}, }; } static getInitialProps = async ({ query }) => { return { query }; }; componentDidMount = async () => { const { query, token } = this.props; const idSanksi = query.id; const sanksi = await getOneSanksi(token, idSanksi, { all: true }); const pt = sanksi.data.laporan.pt; this.setState({ sanksi, pt }); console.log(this.state.sanksi) }; onDrop = (files) => { this.setState({ files: files.map((file) => Object.assign(file, { preview: URL.createObjectURL(file), }) ), stat: "Added " + files.length + " file(s)", }); }; 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: [], }); }; handelSimpan = async () => { const { data } = this.state; const { query, token } = this.props; const { id } = query; const formdata = new FormData(); data.dokumen.forEach((e) => { formdata.append("dokumen", e); }); const toastid = toast.loading("Please wait..."); const added = await addJawabanKeberatan(token, id, formdata); if (!added) { toast.update(toastid, { render: "All is not good", type: "error", isLoading: false, autoClose: true, closeButton: true }); } else { toast.update(toastid, { render: "All is good", type: "success", isLoading: false, autoClose: true, closeButton: true }); Router.push({ pathname: "/app/rekomendasi-delegasi", }); } }; render() { const { files, sanksi, pt } = this.state; const thumbs = files.map((file, index) => (
{/* Item */} {index + 1}.{file.name}
)); return ( {/*
*/}
Rekomendasi Delegasi
{sanksi.data && (

Dokumen Rekomendasi Delegasi

{ this.setState({ data }); await this.handelSimpan(); }} > {() => (
{({ field, form }) => ( { this.onDrop(e); form.setFieldValue(field.name, e); }} > {({ getRootProps, getInputProps, isDragActive }) => { return (
{this.state.files.length > 0 ? {thumbs} :
upload dokumen rekomendasi delegasi
}
); }}
)}

Ukuran setiap dokumen maksimal 15mb

{/*
*/}
{/* */} {/*
*/}
)}
{pt ? : }
)}
); } } const mapStateToProps = (state) => ({ user: state.user, token: state.token }); export default connect(mapStateToProps)(Detail);