index.js 2.3 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576
  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. <div>Sanksi</div>
  51. <div className="ml-auto">
  52. <Link href="/app/pemeriksaan">
  53. <Button className="btn-header" color="info">
  54. <h4>&lt; Pemeriksaan</h4>
  55. </Button>
  56. </Link>
  57. </div>
  58. </div>
  59. <Row>
  60. <Col lg="4">{graph?.data ? <CaseProgress data={graph.data} nextButton={this.nextButton} prevButton={this.prevButton} tahun={this.state.tahun} excel={this.excel} /> : <Loader />}</Col>
  61. <Col lg="8">{pelaporan.data ? <TableLaporan listData={pelaporan.data} /> : <Loader />}</Col>
  62. </Row>
  63. </ContentWrapper>
  64. );
  65. }
  66. }
  67. const mapStateToProps = (state) => ({ user: state.user, token: state.token });
  68. export default connect(mapStateToProps)(Sanksi);