index.js 3.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112
  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. excelMenu = () => {
  57. const url = getExcel(this.props.token, "Laporan", {
  58. tahun: this.state.tahun,
  59. pelaporan: true,
  60. });
  61. Router.push(url);
  62. };
  63. excelSemua = () => {
  64. const url = getExcel(this.props.token, "Laporan", {
  65. tahun: this.state.tahun,
  66. pelaporan: true,
  67. penjadwalan: true,
  68. pemeriksaan: true,
  69. sanksi: true,
  70. });
  71. Router.push(url);
  72. };
  73. // excel = () => {
  74. // const url = getExcel(this.props.token, "Laporan", {
  75. // tahun: this.state.tahun,
  76. // pelaporan: true,
  77. // });
  78. // Router.push(url);
  79. // };
  80. render() {
  81. const { pelaporan, graph, newLaporan } = this.state;
  82. return (
  83. <ContentWrapper>
  84. <div className="content-heading">
  85. <span className="font-color-white">Pelaporan</span>
  86. <div className="ml-auto"></div>
  87. <Link href="/app/penjadwalan">
  88. <Button className="btn-header" color>
  89. <h4 className="font-color-white">Penjadwalan &gt;</h4>
  90. </Button>
  91. </Link>
  92. </div>
  93. <Row>
  94. <Col lg="4">{graph?.data ? <CaseProgress data={graph.data} nextButton={this.nextButton} prevButton={this.prevButton} tahun={this.state.tahun} newLaporan={newLaporan} excelMenu={this.excelMenu} excelSemua={this.excelSemua} /> : <Loader />}</Col>
  95. <Col lg="8">{pelaporan?.data ? <TableLaporan listData={pelaporan.data} to="/app/pelaporan/detail" linkName="Detail" /> : <Loader />}</Col>
  96. </Row>
  97. </ContentWrapper>
  98. );
  99. }
  100. }
  101. const mapStateToProps = (state) => ({ user: state.user, token: state.token });
  102. export default connect(mapStateToProps)(Pelaporan);