index.js 3.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110
  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. import { getCsrf } from "../../../actions/security";
  14. class Pelaporan extends Component {
  15. constructor(props) {
  16. super(props);
  17. this.state = {
  18. pelaporan: {},
  19. graph: {},
  20. tahun: new Date().getFullYear(),
  21. };
  22. }
  23. componentDidMount = async () => {
  24. const { token } = this.props;
  25. const getTokenCsrf = await getCsrf();
  26. const _csrf = getTokenCsrf.token;
  27. await createLog(token, { aktivitas: "Mengakses halaman Laporan Delegasi", menu: "Laporan Delegasi", _csrf: _csrf });
  28. const pelaporan = await getPelaporan(this.props.token, { delegasi: true });
  29. const graph = await getGraph(this.props.token, { jumlahLaporan: true });
  30. this.setState({ pelaporan, graph });
  31. };
  32. nextButton = async () => {
  33. const tahun = this.state.tahun + 1;
  34. const graph = await getGraph(this.props.token, { jumlahLaporan: true, tahun });
  35. this.setState({ graph, tahun });
  36. };
  37. prevButton = async () => {
  38. const tahun = this.state.tahun - 1;
  39. const graph = await getGraph(this.props.token, { jumlahLaporan: true, tahun });
  40. this.setState({ graph, tahun });
  41. };
  42. shouldComponentUpdate = (prevProps, prevState) => {
  43. if (prevState.graph !== this.state.graph) return true;
  44. };
  45. excel = () => {
  46. const url = getExcel(this.props.token, "Laporan Delegasi", { tahun: this.state.tahun });
  47. Router.push(url);
  48. };
  49. excelMenu = () => {
  50. const url = getExcel(this.props.token, "Laporan", {
  51. tahun: this.state.tahun,
  52. pelaporan: true,
  53. });
  54. if (this.state.graph.data.jumlah_laporan.dikti && this.state.graph.data.jumlah_laporan.ditutup && this.state.graph.data.jumlah_laporan.lldikti) {
  55. Router.push(url);
  56. } else {
  57. swal.fire({
  58. title: "Data Kosong",
  59. icon: "error",
  60. confirmButtonColor: "#3e3a8e",
  61. });
  62. }
  63. };
  64. excelSemua = () => {
  65. const url = getExcel(this.props.token, "Laporan", {
  66. tahun: this.state.tahun,
  67. pelaporan: true,
  68. penjadwalan: true,
  69. pemeriksaan: true,
  70. sanksi: true,
  71. });
  72. if (this.state.graph.data.jumlah_laporan.dikti && this.state.graph.data.jumlah_laporan.ditutup && this.state.graph.data.jumlah_laporan.lldikti) {
  73. Router.push(url);
  74. } else {
  75. swal.fire({
  76. title: "Data Kosong",
  77. icon: "error",
  78. confirmButtonColor: "#3e3a8e",
  79. });
  80. }
  81. };
  82. render() {
  83. const { pelaporan, graph } = this.state;
  84. return (
  85. <ContentWrapper>
  86. <div className="content-heading">
  87. <div className="font-color-white">Laporan Delegasi</div>
  88. </div>
  89. <Row>
  90. <Col lg="4">{graph?.data ? <CaseProgress user={this?.props?.user} data={graph.data} nextButton={this.nextButton} prevButton={this.prevButton} tahun={this.state.tahun} excel={this.excel} excelMenu={this.excelMenu} excelSemua={this.excelSemua} /> : <Loader />}</Col>
  91. <Col lg="8">{pelaporan?.data ? <TableLaporan listData={pelaporan.data} to="/app/laporan-delegasi/detail" linkName="Detail" /> : <Loader />}</Col>
  92. </Row>
  93. </ContentWrapper>
  94. );
  95. }
  96. }
  97. const mapStateToProps = (state) => ({ user: state.user, token: state.token });
  98. export default connect(mapStateToProps)(Pelaporan);