import React, { Component } from "react"; import ContentWrapper from "@/components/Layout/ContentWrapper"; import { Row, Col, Button } from "reactstrap"; import { getPelaporan } from "@/actions/pelaporan"; import { getGraph, getExcel } from "@/actions/graph"; import CaseProgress from "@/components/Delegasi/CaseProgress"; import TableLaporan from "@/components/Main/TableLaporan"; import { connect } from "react-redux"; import Loader from "@/components/Common/Loader"; import Router from "next/router"; class Pelaporan extends Component { constructor(props) { super(props); this.state = { pelaporan: {}, graph: {}, tahun: new Date().getFullYear(), }; } componentDidMount = async () => { const pelaporan = await getPelaporan(this.props.token, { delegasi: true }); const graph = await getGraph(this.props.token, { jumlahLaporan: true }); this.setState({ pelaporan, graph }); }; nextButton = async () => { const tahun = this.state.tahun + 1; const graph = await getGraph(this.props.token, { jumlahLaporan: true, tahun }); this.setState({ graph, tahun }); }; prevButton = async () => { const tahun = this.state.tahun - 1; const graph = await getGraph(this.props.token, { jumlahLaporan: true, tahun }); this.setState({ graph, tahun }); }; shouldComponentUpdate = (prevProps, prevState) => { if (prevState.graph !== this.state.graph) return true; }; excel = () => { const url = getExcel(this.props.token, "Laporan Delegasi", { tahun: this.state.tahun }); Router.push(url); }; render() { const { pelaporan, graph } = this.state; return (
Laporan Delegasi
{graph?.data ? : } {pelaporan?.data ? : }
); } } const mapStateToProps = (state) => ({ user: state.user, token: state.token }); export default connect(mapStateToProps)(Pelaporan);