index.js 2.7 KB

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