index.js 3.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103
  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">{graph?.data ? <CaseProgress data={graph.data} nextButton={this.nextButton} prevButton={this.prevButton} tahun={this.state.tahun} newLaporan={newLaporan} excel={this.excel} /> : <Loader />}</Col>
  77. <Col lg="8">
  78. <div className="mb-3 d-flex">
  79. {/* <div className="margin-left-auto">
  80. <Link href="/app/pelaporan/search">
  81. <Button className="color-3e3a8e" color="purple">Laporan Baru</Button>
  82. </Link>
  83. </div> */}
  84. {pelaporan?.data ? <TableLaporan listData={pelaporan.data} to="/app/pelaporan/detail" linkName="Detail" /> : <Loader />}
  85. </div>
  86. </Col>
  87. </Row>
  88. </ContentWrapper>
  89. );
  90. }
  91. }
  92. const mapStateToProps = (state) => ({ user: state.user, token: state.token });
  93. export default connect(mapStateToProps)(Pelaporan);