import React, { Component } from "react"; import ContentWrapper from "@/components/Layout/ContentWrapper"; import Link from "next/link"; import { Row, Col, Button } from "reactstrap"; import { getPelaporan } from "@/actions/pelaporan"; import { getGraph, getExcel } from "@/actions/graph"; import CaseProgress from "@/components/Pelaporan/CaseProgress"; import TableLaporan from "@/components/Pelaporan/TableLaporan"; import { connect } from "react-redux"; import Loader from "@/components/Common/Loader"; import Router from "next/router"; import { createLog } from "@/actions/log"; import swal from "sweetalert2"; import { getCsrf } from "../../../actions/security"; import Swal from "sweetalert2"; class Pelaporan extends Component { constructor(props) { super(props); this.state = { pelaporan: {}, graph: {}, tahun: new Date().getFullYear(), newLaporan: [], }; } componentDidMount = async () => { const { token } = this.props; const getTokenCsrf = await getCsrf(); const _csrf = getTokenCsrf.token; await createLog(token, { aktivitas: "Mengakses halaman Pelaporan", menu: "Pelaporan", _csrf: _csrf }); const pelaporan = await getPelaporan(this.props.token); const graph = await getGraph(this.props.token, { laporanTahun: true, newLaporan: true, jumlahLaporan: true, }); const newLaporan = graph.data.newLaporan; this.setState({ pelaporan, graph, newLaporan }); }; nextButton = async () => { const tahun = this.state.tahun + 1; const graph = await getGraph(this.props.token, { laporanTahun: true, jumlahLaporan: true, tahun, }); this.setState({ graph, tahun }); }; prevButton = async () => { const tahun = this.state.tahun - 1; const graph = await getGraph(this.props.token, { laporanTahun: true, jumlahLaporan: true, tahun, }); this.setState({ graph, tahun }); }; shouldComponentUpdate = (prevProps, prevState) => { if (prevState.graph !== this.state.graph) return true; }; excelMenu = () => { 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 url = getExcel(this.props.token, "Laporan", { tahun: this.state.tahun, pelaporan: true, }); if (this.state.graph.data.jumlah_laporan.dikti && this.state.graph.data.jumlah_laporan.ditutup && this.state.graph.data.jumlah_laporan.lldikti) { Router.push(url); } else { swal.fire({ title: "Data Kosong", icon: "error", confirmButtonColor: "#3e3a8e", }); } } }; excelSemua = () => { 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 url = getExcel(this.props.token, "Laporan", { tahun: this.state.tahun, pelaporan: true, penjadwalan: true, pemeriksaan: true, sanksi: true, }); if (this.state.graph.data.jumlah_laporan.dikti && this.state.graph.data.jumlah_laporan.ditutup && this.state.graph.data.jumlah_laporan.lldikti) { Router.push(url); } else { swal.fire({ title: "Data Kosong", icon: "error", confirmButtonColor: "#3e3a8e", }); } } }; render() { const { pelaporan, graph, newLaporan } = this.state; return (
Pelaporan
{graph?.data ? : } {pelaporan?.data ? : }
); } } const mapStateToProps = (state) => ({ user: state.user, token: state.token }); export default connect(mapStateToProps)(Pelaporan);