index.js 2.0 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162
  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 } from "@/actions/graph";
  7. import CaseProgress from "@/components/Delegasi/CaseProgress";
  8. import TableLaporan from "@/components/Main/TableLaporan";
  9. import { connect } from "react-redux";
  10. import Loader from "@/components/Common/Loader";
  11. class Pelaporan extends Component {
  12. constructor(props) {
  13. super(props);
  14. this.state = {
  15. pelaporan: {},
  16. graph: {},
  17. tahun: new Date().getFullYear(),
  18. };
  19. }
  20. componentDidMount = async () => {
  21. const pelaporan = await getPelaporan(this.props.token, { delegasi: true });
  22. const graph = await getGraph(this.props.token, { jumlahLaporan: true });
  23. this.setState({ pelaporan, graph });
  24. };
  25. nextButton = async () => {
  26. const tahun = this.state.tahun + 1;
  27. const graph = await getGraph(this.props.token, { jumlahLaporan: true, tahun });
  28. this.setState({ graph, tahun });
  29. };
  30. prevButton = async () => {
  31. const tahun = this.state.tahun - 1;
  32. const graph = await getGraph(this.props.token, { jumlahLaporan: true, tahun });
  33. this.setState({ graph, tahun });
  34. };
  35. shouldComponentUpdate = (prevProps, prevState) => {
  36. if (prevState.graph !== this.state.graph) return true;
  37. };
  38. render() {
  39. const { pelaporan, graph } = this.state;
  40. return (
  41. <ContentWrapper>
  42. <div className="content-heading">
  43. <div>Laporan Delegasi</div>
  44. <div className="ml-auto"></div>
  45. </div>
  46. <Row>
  47. <Col lg="4">{graph?.data ? <CaseProgress data={graph.data} nextButton={this.nextButton} prevButton={this.prevButton} tahun={this.state.tahun} /> : <Loader />}</Col>
  48. <Col lg="8">{pelaporan?.data ? <TableLaporan listData={pelaporan.data} to="/app/laporan-delegasi/detail" linkName="Detail" /> : <Loader />}</Col>
  49. </Row>
  50. </ContentWrapper>
  51. );
  52. }
  53. }
  54. const mapStateToProps = (state) => ({ user: state.user, token: state.token });
  55. export default connect(mapStateToProps)(Pelaporan);