index.js 2.2 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667
  1. import React, { Component } from "react";
  2. import ContentWrapper from "@/components/Layout/ContentWrapper";
  3. import { Row, Col, Button } from "reactstrap";
  4. import { getPelaporan } from "@/actions/pelaporan";
  5. import { getGraph, getExcel } from "@/actions/graph";
  6. import CaseProgress from "@/components/Delegasi/CaseProgress";
  7. import TableLaporan from "@/components/Main/TableLaporan";
  8. import { connect } from "react-redux";
  9. import Loader from "@/components/Common/Loader";
  10. import Router from "next/router";
  11. class Pelaporan extends Component {
  12. constructor(props) {
  13. super(props);
  14. this.state = {
  15. pelaporan: {},
  16. graph: {},
  17. tahun: new Date().getFullYear(),
  18. };
  19. }
  20. componentDidMount = async () => {
  21. const pelaporan = await getPelaporan(this.props.token, { delegasi: true });
  22. const graph = await getGraph(this.props.token, { jumlahLaporan: true });
  23. this.setState({ pelaporan, graph });
  24. };
  25. nextButton = async () => {
  26. const tahun = this.state.tahun + 1;
  27. const graph = await getGraph(this.props.token, { jumlahLaporan: true, tahun });
  28. this.setState({ graph, tahun });
  29. };
  30. prevButton = async () => {
  31. const tahun = this.state.tahun - 1;
  32. const graph = await getGraph(this.props.token, { jumlahLaporan: true, tahun });
  33. this.setState({ graph, tahun });
  34. };
  35. shouldComponentUpdate = (prevProps, prevState) => {
  36. if (prevState.graph !== this.state.graph) return true;
  37. };
  38. excel = () => {
  39. const url = getExcel(this.props.token, "Laporan Delegasi", { tahun: this.state.tahun });
  40. Router.push(url);
  41. };
  42. render() {
  43. const { pelaporan, graph } = this.state;
  44. return (
  45. <ContentWrapper>
  46. <div className="content-heading">
  47. <div>Laporan Delegasi</div>
  48. <div className="ml-auto"></div>
  49. </div>
  50. <Row>
  51. <Col lg="4">{graph?.data ? <CaseProgress data={graph.data} nextButton={this.nextButton} prevButton={this.prevButton} tahun={this.state.tahun} excel={this.excel} /> : <Loader />}</Col>
  52. <Col lg="8">{pelaporan?.data ? <TableLaporan listData={pelaporan.data} to="/app/laporan-delegasi/detail" linkName="Detail" /> : <Loader />}</Col>
  53. </Row>
  54. </ContentWrapper>
  55. );
  56. }
  57. }
  58. const mapStateToProps = (state) => ({ user: state.user, token: state.token });
  59. export default connect(mapStateToProps)(Pelaporan);