index.js 2.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778
  1. import React, { Component } from "react";
  2. import ContentWrapper from "@/components/Layout/ContentWrapper";
  3. import { Row, Col } from "reactstrap";
  4. import { getPelaporan } from "@/actions/pelaporan";
  5. import { getGraph, getExcel } from "@/actions/graph";
  6. import CaseProgress from "@/components/Sanksi/CaseProgress";
  7. import TableLaporan from "@/components/Sanksi/TableLaporan";
  8. import { connect } from "react-redux";
  9. import Loader from "@/components/Common/Loader";
  10. import Link from "next/link";
  11. import Button from "reactstrap/lib/Button";
  12. import Router from "next/router";
  13. class Sanksi extends Component {
  14. constructor(props) {
  15. super(props);
  16. this.state = {
  17. pelaporan: {},
  18. graph: {},
  19. tahun: new Date().getFullYear(),
  20. };
  21. }
  22. componentDidMount = async () => {
  23. const { token } = this.props;
  24. const pelaporan = await getPelaporan(token, { evaluasi: true });
  25. const graph = await getGraph(this.props.token, { sanksi: true });
  26. this.setState({ pelaporan, graph });
  27. };
  28. nextButton = async () => {
  29. const tahun = this.state.tahun + 1;
  30. const graph = await getGraph(this.props.token, { sanksi: true, tahun });
  31. this.setState({ graph, tahun });
  32. };
  33. prevButton = async () => {
  34. const tahun = this.state.tahun - 1;
  35. const graph = await getGraph(this.props.token, { sanksi: true, tahun });
  36. this.setState({ graph, tahun });
  37. };
  38. shouldComponentUpdate = (prevProps, prevState) => {
  39. if (prevState.graph !== this.state.graph) return true;
  40. };
  41. excel = () => {
  42. const url = getExcel(this.props.token, "Laporan", { tahun: this.state.tahun });
  43. Router.push(url);
  44. };
  45. render() {
  46. const { pelaporan, graph } = this.state;
  47. return (
  48. <ContentWrapper>
  49. <div className="content-heading">
  50. <span className="font-color-white">
  51. Sanksi
  52. </span>
  53. <div className="ml-auto">
  54. <Link href="/app/pemeriksaan">
  55. <Button className="btn-header" color>
  56. <h4 className="font-color-white">&lt; Pemeriksaan</h4>
  57. </Button>
  58. </Link>
  59. </div>
  60. </div>
  61. <Row>
  62. <Col lg="4">{graph?.data ? <CaseProgress data={graph.data} nextButton={this.nextButton} prevButton={this.prevButton} tahun={this.state.tahun} excel={this.excel} /> : <Loader />}</Col>
  63. <Col lg="8">{pelaporan.data ? <TableLaporan listData={pelaporan.data} /> : <Loader />}</Col>
  64. </Row>
  65. </ContentWrapper>
  66. );
  67. }
  68. }
  69. const mapStateToProps = (state) => ({ user: state.user, token: state.token });
  70. export default connect(mapStateToProps)(Sanksi);