index.js 2.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778
  1. import React, { Component } from "react";
  2. import ContentWrapper from "@/components/Layout/ContentWrapper";
  3. import { Row, Col } from "reactstrap";
  4. import { getPelaporan } from "@/actions/pelaporan";
  5. import { getGraph } from "@/actions/graph";
  6. import CaseProgress from "@/components/Pemeriksaan/CaseProgress";
  7. import TableLaporan from "@/components/Pemeriksaan/TableLaporan";
  8. import { connect } from "react-redux";
  9. import Loader from "@/components/Common/Loader";
  10. import Link from "next/link";
  11. import Button from "reactstrap/lib/Button";
  12. class Pemeriksaan extends Component {
  13. constructor(props) {
  14. super(props);
  15. this.state = {
  16. pelaporan: {},
  17. graph: {},
  18. tahun: new Date().getFullYear(),
  19. };
  20. }
  21. componentDidMount = async () => {
  22. const { token } = this.props;
  23. const pelaporan = await getPelaporan(token, { jadwal: true });
  24. const graph = await getGraph(this.props.token, { evaluasi: true, listJadwal: true });
  25. this.setState({ pelaporan, graph });
  26. };
  27. nextButton = async () => {
  28. const tahun = this.state.tahun + 1;
  29. const graph = await getGraph(this.props.token, { evaluasi: true, listJadwal: 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, { evaluasi: true, listJadwal: 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 } = this.state;
  42. return (
  43. <ContentWrapper>
  44. <div className="content-heading">
  45. <div>Evaluasi</div>
  46. <div className="ml-auto">
  47. <Link href="/app/penjadwalan">
  48. <span className="margin-l-5">
  49. <Button className="btn-header" color="info">
  50. <h4>&lt; Penjadwalan</h4>
  51. </Button>
  52. </span>
  53. </Link>
  54. <Link href="/app/sanksi">
  55. <Button className="btn-header" color="info">
  56. <h4>Sanksi &gt;</h4>
  57. </Button>
  58. </Link>
  59. </div>
  60. </div>
  61. <Row>
  62. <Col lg="4">{graph?.data ? <CaseProgress data={graph.data} nextButton={this.nextButton} prevButton={this.prevButton} tahun={this.state.tahun} /> : <Loader />}</Col>
  63. <Col lg="8">{pelaporan?.data ? <TableLaporan status noBy listData={pelaporan.data} to="/app/pemeriksaan/new" linkName="Evaluasi" /> : <Loader />}</Col>
  64. </Row>
  65. </ContentWrapper>
  66. );
  67. }
  68. }
  69. const mapStateToProps = (state) => ({ user: state.user, token: state.token });
  70. export default connect(mapStateToProps)(Pemeriksaan);