index.js 2.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687
  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. class Pelaporan extends Component {
  13. constructor(props) {
  14. super(props);
  15. this.state = {
  16. pelaporan: {},
  17. graph: {},
  18. tahun: new Date().getFullYear(),
  19. newLaporan: [],
  20. };
  21. }
  22. componentDidMount = async () => {
  23. const pelaporan = await getPelaporan(this.props.token);
  24. const graph = await getGraph(this.props.token, { laporanTahun: true, newLaporan: true, jumlahLaporan: true });
  25. const newLaporan = graph.data.newLaporan;
  26. this.setState({ pelaporan, graph, newLaporan });
  27. };
  28. nextButton = async () => {
  29. const tahun = this.state.tahun + 1;
  30. const graph = await getGraph(this.props.token, { laporanTahun: true, 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, { laporanTahun: true, 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", { tahun: this.state.tahun });
  43. Router.push(url);
  44. };
  45. render() {
  46. const { pelaporan, graph, newLaporan } = this.state;
  47. return (
  48. <ContentWrapper>
  49. <div className="content-heading">
  50. <span className="font-color-white">
  51. Pelaporan
  52. </span>
  53. <div className="ml-auto"></div>
  54. <Link href="/app/penjadwalan">
  55. <Button className="btn-header" color>
  56. <h4 className="font-color-white">Penjadwalan &gt;</h4>
  57. </Button>
  58. </Link>
  59. </div>
  60. <Row>
  61. <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>
  62. <Col lg="8">
  63. <div className="mb-3 d-flex">
  64. {/* <div className="margin-left-auto">
  65. <Link href="/app/pelaporan/search">
  66. <Button className="color-3e3a8e" color="purple">Laporan Baru</Button>
  67. </Link>
  68. </div> */}
  69. </div>
  70. {pelaporan?.data ? <TableLaporan listData={pelaporan.data} to="/app/pelaporan/detail" linkName="Detail" /> : <Loader />}
  71. </Col>
  72. </Row>
  73. </ContentWrapper>
  74. );
  75. }
  76. }
  77. const mapStateToProps = (state) => ({ user: state.user, token: state.token });
  78. export default connect(mapStateToProps)(Pelaporan);