index.js 2.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869
  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. import { createLog } from "@/actions/log";
  12. class Pelaporan extends Component {
  13. constructor(props) {
  14. super(props);
  15. this.state = {
  16. pelaporan: {},
  17. graph: {},
  18. tahun: new Date().getFullYear(),
  19. };
  20. }
  21. componentDidMount = async () => {
  22. const { token } = this.props;
  23. await createLog(token, { aktivitas: "Mengakses halaman Laporan Delegasi", menu: "Laporan Delegasi" });
  24. const pelaporan = await getPelaporan(this.props.token, { delegasi: true });
  25. const graph = await getGraph(this.props.token, { jumlahLaporan: 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, { jumlahLaporan: 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, { jumlahLaporan: 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 Delegasi", { 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 className="font-color-white">Laporan Delegasi</div>
  51. </div>
  52. <Row>
  53. <Col lg="4">{graph?.data ? <CaseProgress data={graph.data} nextButton={this.nextButton} prevButton={this.prevButton} tahun={this.state.tahun} excel={this.excel} /> : <Loader />}</Col>
  54. <Col lg="8">{pelaporan?.data ? <TableLaporan listData={pelaporan.data} to="/app/laporan-delegasi/detail" linkName="Detail" /> : <Loader />}</Col>
  55. </Row>
  56. </ContentWrapper>
  57. );
  58. }
  59. }
  60. const mapStateToProps = (state) => ({ user: state.user, token: state.token });
  61. export default connect(mapStateToProps)(Pelaporan);