import React, { Component } from "react"; import Router from "next/router"; import Link from "next/link"; import { getSanksi } from "@/actions/sanksi"; import Header from "@/components/Main/Header"; import DetailPT from "@/components/Main/DetailPT"; import DetailSanksi from "@/components/Main/DetailSanksi"; import Riwayat from "@/components/PT/CabutSanksi/Riwayat"; import ContentWrapper from "@/components/Layout/ContentWrapper"; import { Row, Col, Card, CardBody, FormGroup, Button } from "reactstrap"; import { addCabutSanksi } from "@/actions/cabutSanksi"; import { connect } from "react-redux"; import Loader from "@/components/Common/Loader"; 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; } } class DetailPencabutanSanksi extends Component { constructor(props) { super(props); this.state = { files: [], }; } static async getInitialProps({ query }) { return { query }; } componentDidMount = async () => { const { user } = this.props; const { noSanksi } = this.props.query; const sanksi = await getSanksi({ noSanksi, ptId: user.peran[0].organisasi.id }); this.setState({ 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: [], }); }; handleKirim = async (e) => { e.preventDefault(); const { noSanksi } = this.props.query; const { user } = this.props; const org_id = user.peran[0].organisasi.id; const formdata = new FormData(); if (this.state.files.length > 0) { this.state.files.forEach((e) => { formdata.append("files", e); }); const added = await addCabutSanksi({ noSanksi, ptId: org_id }, formdata); if (added) { Router.push({ pathname: "/app/pt/pencabutan-sanksi", }); } } }; render() { const { files, sanksi } = this.state; const thumbs = files.map((file, index) => ( Item )); return (
Permohonan Pencabutan Sanksi
{sanksi?.data ? (

Permohonan Pencabutan Sanksi

{({ getRootProps, getInputProps, isDragActive }) => { return (
{this.state.files.length > 0 ? {thumbs} :
Drop files here to upload
}
); }}
) : ( )} {this.props.pt && }
{sanksi?.data && ( )}
); } } const mapStateToProps = (state) => ({ user: state.user, pt: state.pt }); export default connect(mapStateToProps)(DetailPencabutanSanksi);