index.js 2.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899
  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. console.log(pelaporan)
  34. this.setState({ pelaporan, graph, newLaporan });
  35. console.log(this.state.pelaporan)
  36. };
  37. nextButton = async () => {
  38. const tahun = this.state.tahun + 1;
  39. const graph = await getGraph(this.props.token, {
  40. laporanTahun: true,
  41. jumlahLaporan: true,
  42. tahun,
  43. });
  44. this.setState({ graph, tahun });
  45. };
  46. prevButton = async () => {
  47. const tahun = this.state.tahun - 1;
  48. const graph = await getGraph(this.props.token, {
  49. laporanTahun: true,
  50. jumlahLaporan: true,
  51. tahun,
  52. });
  53. this.setState({ graph, tahun });
  54. };
  55. shouldComponentUpdate = (prevProps, prevState) => {
  56. if (prevState.graph !== this.state.graph) return true;
  57. };
  58. excel = () => {
  59. const url = getExcel(this.props.token, "Laporan", {
  60. tahun: this.state.tahun,
  61. });
  62. Router.push(url);
  63. };
  64. render() {
  65. const { pelaporan, graph, newLaporan } = this.state;
  66. return (
  67. <ContentWrapper>
  68. <div className="content-heading">
  69. <span className="font-color-white">Pelaporan</span>
  70. <div className="ml-auto"></div>
  71. <Link href="/app/penjadwalan">
  72. <Button className="btn-header" color>
  73. <h4 className="font-color-white">Penjadwalan &gt;</h4>
  74. </Button>
  75. </Link>
  76. </div>
  77. <Row>
  78. <Col lg="4">
  79. {graph?.data ? <CaseProgress data={graph.data} nextButton={this.nextButton} prevButton={this.prevButton} tahun={this.state.tahun} newLaporan={newLaporan} excel={this.excel} /> : <Loader />}
  80. </Col>
  81. <Col lg="8">
  82. {pelaporan?.data ? <TableLaporan listData={pelaporan.data} to="/app/pelaporan/detail" linkName="Detail" /> : <Loader />}
  83. </Col>
  84. </Row>
  85. </ContentWrapper>
  86. );
  87. }
  88. }
  89. const mapStateToProps = (state) => ({ user: state.user, token: state.token });
  90. export default connect(mapStateToProps)(Pelaporan);