index.js 2.5 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879
  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/Pelaporan/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. newLaporan: [],
  19. };
  20. }
  21. componentDidMount = async () => {
  22. const pelaporan = await getPelaporan(this.props.token);
  23. const graph = await getGraph(this.props.token, { laporanTahun: true, newLaporan: true, jumlahLaporan: true });
  24. const newLaporan = graph.data.newLaporan;
  25. this.setState({ pelaporan, graph, newLaporan });
  26. };
  27. nextButton = async () => {
  28. const tahun = this.state.tahun + 1;
  29. const graph = await getGraph(this.props.token, { laporanTahun: true, jumlahLaporan: true, tahun });
  30. this.setState({ graph, tahun });
  31. };
  32. prevButton = async () => {
  33. const tahun = this.state.tahun - 1;
  34. const graph = await getGraph(this.props.token, { laporanTahun: true, jumlahLaporan: true, tahun });
  35. this.setState({ graph, tahun });
  36. };
  37. shouldComponentUpdate = (prevProps, prevState) => {
  38. if (prevState.graph !== this.state.graph) return true;
  39. };
  40. render() {
  41. const { pelaporan, graph, newLaporan } = this.state;
  42. return (
  43. <ContentWrapper>
  44. <div className="content-heading">
  45. Pelaporan
  46. <div className="ml-auto"></div>
  47. <Link href="/app/penjadwalan">
  48. <Button className="btn-header" color="info">
  49. <h4>Penjadwalan &gt;</h4>
  50. </Button>
  51. </Link>
  52. </div>
  53. <Row>
  54. <Col lg="4">{graph?.data ? <CaseProgress data={graph.data} nextButton={this.nextButton} prevButton={this.prevButton} tahun={this.state.tahun} newLaporan={newLaporan} /> : <Loader />}</Col>
  55. <Col lg="8">
  56. <div className="mb-3 d-flex">
  57. <div>
  58. <Link href="/app/pelaporan/search">
  59. <Button color="primary">Laporan Baru</Button>
  60. </Link>
  61. </div>
  62. </div>
  63. {pelaporan?.data ? <TableLaporan listData={pelaporan.data} to="/app/pelaporan/detail" linkName="Detail" /> : <Loader />}
  64. </Col>
  65. </Row>
  66. </ContentWrapper>
  67. );
  68. }
  69. }
  70. const mapStateToProps = (state) => ({ user: state.user, token: state.token });
  71. export default connect(mapStateToProps)(Pelaporan);