index.js 3.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106
  1. import React, { Component } from "react";
  2. import ContentWrapper from "@/components/Layout/ContentWrapper";
  3. import { Row, Col, Button } from "reactstrap";
  4. import { getPelaporan } from "@/actions/pelaporan";
  5. import { getGraph, getExcel } from "@/actions/graph";
  6. import CaseProgress from "@/components/Delegasi/CaseProgress";
  7. import TableLaporan from "@/components/Main/TableLaporan";
  8. import { connect } from "react-redux";
  9. import Loader from "@/components/Common/Loader";
  10. import Router from "next/router";
  11. import { createLog } from "@/actions/log";
  12. import swal from "sweetalert2";
  13. class Pelaporan 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. await createLog(token, { aktivitas: "Mengakses halaman Laporan Delegasi", menu: "Laporan Delegasi" });
  25. const pelaporan = await getPelaporan(this.props.token, { delegasi: true });
  26. const graph = await getGraph(this.props.token, { jumlahLaporan: true });
  27. this.setState({ pelaporan, graph });
  28. };
  29. nextButton = async () => {
  30. const tahun = this.state.tahun + 1;
  31. const graph = await getGraph(this.props.token, { jumlahLaporan: true, tahun });
  32. this.setState({ graph, tahun });
  33. };
  34. prevButton = async () => {
  35. const tahun = this.state.tahun - 1;
  36. const graph = await getGraph(this.props.token, { jumlahLaporan: true, tahun });
  37. this.setState({ graph, tahun });
  38. };
  39. shouldComponentUpdate = (prevProps, prevState) => {
  40. if (prevState.graph !== this.state.graph) return true;
  41. };
  42. excel = () => {
  43. const url = getExcel(this.props.token, "Laporan Delegasi", { tahun: this.state.tahun });
  44. Router.push(url);
  45. };
  46. excelMenu = () => {
  47. const url = getExcel(this.props.token, "Laporan", {
  48. tahun: this.state.tahun,
  49. pelaporan: true,
  50. });
  51. if (this.state.graph.data.jumlah_laporan.dikti && this.state.graph.data.jumlah_laporan.ditutup && this.state.graph.data.jumlah_laporan.lldikti) {
  52. Router.push(url);
  53. } else {
  54. swal.fire({
  55. title: "Data Kosong",
  56. icon: "error",
  57. confirmButtonColor: "#3e3a8e",
  58. });
  59. }
  60. };
  61. excelSemua = () => {
  62. const url = getExcel(this.props.token, "Laporan", {
  63. tahun: this.state.tahun,
  64. pelaporan: true,
  65. penjadwalan: true,
  66. pemeriksaan: true,
  67. sanksi: true,
  68. });
  69. if (this.state.graph.data.jumlah_laporan.dikti && this.state.graph.data.jumlah_laporan.ditutup && this.state.graph.data.jumlah_laporan.lldikti) {
  70. Router.push(url);
  71. } else {
  72. swal.fire({
  73. title: "Data Kosong",
  74. icon: "error",
  75. confirmButtonColor: "#3e3a8e",
  76. });
  77. }
  78. };
  79. render() {
  80. const { pelaporan, graph } = this.state;
  81. return (
  82. <ContentWrapper>
  83. <div className="content-heading">
  84. <div className="font-color-white">Laporan Delegasi</div>
  85. </div>
  86. <Row>
  87. <Col lg="4">{graph?.data ? <CaseProgress data={graph.data} nextButton={this.nextButton} prevButton={this.prevButton} tahun={this.state.tahun} excel={this.excel} excelMenu={this.excelMenu} excelSemua={this.excelSemua} /> : <Loader />}</Col>
  88. <Col lg="8">{pelaporan?.data ? <TableLaporan listData={pelaporan.data} to="/app/laporan-delegasi/detail" linkName="Detail" /> : <Loader />}</Col>
  89. </Row>
  90. </ContentWrapper>
  91. );
  92. }
  93. }
  94. const mapStateToProps = (state) => ({ user: state.user, token: state.token });
  95. export default connect(mapStateToProps)(Pelaporan);