index.js 3.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596
  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, getlaporanselesai } from "@/actions/graph";
  6. import CaseProgress from "@/components/PelaporanTuntas/CaseProgress";
  7. import TableLaporan from "@/components/PelaporanTuntas/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 PelaporanTuntas extends Component {
  14. constructor(props) {
  15. super(props);
  16. this.state = {
  17. pelaporan: {},
  18. graph: {},
  19. tahun: new Date().getFullYear(),
  20. laporanSelesai: {}
  21. };
  22. }
  23. componentDidMount = async () => {
  24. const { token } = this.props;
  25. let laporanSelesai = await getlaporanselesai(token);
  26. laporanSelesai = {
  27. ...laporanSelesai, data: {
  28. ...laporanSelesai.data, laporan: [...laporanSelesai.data.laporan, ...laporanSelesai.data.sanksi], sanksi: null
  29. }
  30. }
  31. const pelaporan = await getPelaporan(token, { jadwal: true, aktif: false });
  32. const graph = await getGraph(this.props.token, { evaluasi: true, listJadwal: true, aktif: false });
  33. this.setState({ pelaporan, graph, laporanSelesai });
  34. };
  35. nextButton = async () => {
  36. const tahun = this.state.tahun + 1;
  37. const graph = await getGraph(this.props.token, { evaluasi: true, listJadwal: true, tahun });
  38. this.setState({ graph, tahun });
  39. };
  40. prevButton = async () => {
  41. const tahun = this.state.tahun - 1;
  42. const graph = await getGraph(this.props.token, { evaluasi: true, listJadwal: true, tahun });
  43. this.setState({ graph, tahun });
  44. };
  45. shouldComponentUpdate = (prevProps, prevState) => {
  46. if (prevState.graph !== this.state.graph) return true;
  47. };
  48. excel = () => {
  49. const url = getExcel(this.props.token, "Laporan", { tahun: this.state.tahun });
  50. Router.push(url);
  51. };
  52. excelMenu = () => {
  53. const url = getExcel(this.props.token, "Laporan", {
  54. tahun: this.state.tahun,
  55. pelaporan: true,
  56. });
  57. Router.push(url);
  58. };
  59. excelSemua = () => {
  60. const url = getExcel(this.props.token, "Laporan", {
  61. tahun: this.state.tahun,
  62. pelaporan: true,
  63. penjadwalan: true,
  64. pemeriksaan: true,
  65. sanksi: true,
  66. });
  67. Router.push(url);
  68. };
  69. render() {
  70. const { pelaporan, graph, laporanSelesai } = this.state;
  71. return (
  72. <ContentWrapper>
  73. <div className="content-heading">
  74. <span className="font-color-white">
  75. Pelaporan Tuntas
  76. </span>
  77. </div>
  78. <Row>
  79. <Col lg="4">{laporanSelesai?.data ? <CaseProgress data={laporanSelesai.data} nextButton={this.nextButton} prevButton={this.prevButton} tahun={this.state.tahun} excel={this.excel} excelMenu={this.excelMenu} excelSemua={this.excelSemua} /> : <Loader />}</Col>
  80. <Col lg="8">{laporanSelesai?.data?.laporan ? <TableLaporan status noBy listData={laporanSelesai.data.laporan} to="/app/tuntas/detail" linkName="Detail" /> : <Loader />}</Col>
  81. </Row>
  82. </ContentWrapper>
  83. );
  84. }
  85. }
  86. const mapStateToProps = (state) => ({ user: state.user, token: state.token });
  87. export default connect(mapStateToProps)(PelaporanTuntas);