index.js 2.8 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697
  1. import React, { Component } from "react";
  2. import ContentWrapper from "@/components/Layout/ContentWrapper";
  3. import Link from "next/link";
  4. import { Row, Col, Button } from "reactstrap";
  5. import { getPelaporan } from "@/actions/pelaporan";
  6. import { getGraph, getExcel } from "@/actions/graph";
  7. import CaseProgress from "@/components/Pelaporan/CaseProgress";
  8. import TableLaporan from "@/components/Pelaporan/TableLaporan";
  9. import { connect } from "react-redux";
  10. import Loader from "@/components/Common/Loader";
  11. import Router from "next/router";
  12. import { createLog } from "@/actions/log";
  13. class Pelaporan extends Component {
  14. constructor(props) {
  15. super(props);
  16. this.state = {
  17. pelaporan: {},
  18. graph: {},
  19. tahun: new Date().getFullYear(),
  20. newLaporan: [],
  21. };
  22. }
  23. componentDidMount = async () => {
  24. const { token } = this.props;
  25. await createLog(token, { aktivitas: "Mengakses halaman Pelaporan", menu: "Pelaporan" });
  26. const pelaporan = await getPelaporan(this.props.token);
  27. const graph = await getGraph(this.props.token, {
  28. laporanTahun: true,
  29. newLaporan: true,
  30. jumlahLaporan: true,
  31. });
  32. const newLaporan = graph.data.newLaporan;
  33. this.setState({ pelaporan, graph, newLaporan });
  34. };
  35. nextButton = async () => {
  36. const tahun = this.state.tahun + 1;
  37. const graph = await getGraph(this.props.token, {
  38. laporanTahun: true,
  39. jumlahLaporan: true,
  40. tahun,
  41. });
  42. this.setState({ graph, tahun });
  43. };
  44. prevButton = async () => {
  45. const tahun = this.state.tahun - 1;
  46. const graph = await getGraph(this.props.token, {
  47. laporanTahun: true,
  48. jumlahLaporan: true,
  49. tahun,
  50. });
  51. this.setState({ graph, tahun });
  52. };
  53. shouldComponentUpdate = (prevProps, prevState) => {
  54. if (prevState.graph !== this.state.graph) return true;
  55. };
  56. excel = () => {
  57. const url = getExcel(this.props.token, "Laporan", {
  58. tahun: this.state.tahun,
  59. });
  60. Router.push(url);
  61. };
  62. render() {
  63. const { pelaporan, graph, newLaporan } = this.state;
  64. return (
  65. <ContentWrapper>
  66. <div className="content-heading">
  67. <span className="font-color-white">Pelaporan</span>
  68. <div className="ml-auto"></div>
  69. <Link href="/app/penjadwalan">
  70. <Button className="btn-header" color>
  71. <h4 className="font-color-white">Penjadwalan &gt;</h4>
  72. </Button>
  73. </Link>
  74. </div>
  75. <Row>
  76. <Col lg="4">
  77. {graph?.data ? <CaseProgress data={graph.data} nextButton={this.nextButton} prevButton={this.prevButton} tahun={this.state.tahun} newLaporan={newLaporan} excel={this.excel} /> : <Loader />}
  78. </Col>
  79. <Col lg="8">
  80. {pelaporan?.data ? <TableLaporan listData={pelaporan.data} to="/app/pelaporan/detail" linkName="Detail" /> : <Loader />}
  81. </Col>
  82. </Row>
  83. </ContentWrapper>
  84. );
  85. }
  86. }
  87. const mapStateToProps = (state) => ({ user: state.user, token: state.token });
  88. export default connect(mapStateToProps)(Pelaporan);