index.js 3.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123
  1. import React, { Component } from "react";
  2. import ContentWrapper from "@/components/Layout/ContentWrapper";
  3. import Link from "next/link";
  4. import { Row, Col, Button } from "reactstrap";
  5. import { getPelaporan } from "@/actions/pelaporan";
  6. import { getGraph, getExcel } from "@/actions/graph";
  7. import CaseProgress from "@/components/Pelaporan/CaseProgress";
  8. import TableLaporan from "@/components/Pelaporan/TableLaporan";
  9. import { connect } from "react-redux";
  10. import Loader from "@/components/Common/Loader";
  11. import Router from "next/router";
  12. import { createLog } from "@/actions/log";
  13. import swal from "sweetalert2";
  14. import { getCsrf } from "../../../actions/security";
  15. class Pelaporan extends Component {
  16. constructor(props) {
  17. super(props);
  18. this.state = {
  19. pelaporan: {},
  20. graph: {},
  21. tahun: new Date().getFullYear(),
  22. newLaporan: [],
  23. };
  24. }
  25. componentDidMount = async () => {
  26. const { token } = this.props;
  27. const getTokenCsrf = await getCsrf();
  28. const _csrf = getTokenCsrf.token;
  29. await createLog(token, { aktivitas: "Mengakses halaman Pelaporan", menu: "Pelaporan", _csrf: _csrf });
  30. const pelaporan = await getPelaporan(this.props.token);
  31. const graph = await getGraph(this.props.token, {
  32. laporanTahun: true,
  33. newLaporan: true,
  34. jumlahLaporan: true,
  35. });
  36. const newLaporan = graph.data.newLaporan;
  37. this.setState({ pelaporan, graph, newLaporan });
  38. };
  39. nextButton = async () => {
  40. const tahun = this.state.tahun + 1;
  41. const graph = await getGraph(this.props.token, {
  42. laporanTahun: true,
  43. jumlahLaporan: true,
  44. tahun,
  45. });
  46. this.setState({ graph, tahun });
  47. };
  48. prevButton = async () => {
  49. const tahun = this.state.tahun - 1;
  50. const graph = await getGraph(this.props.token, {
  51. laporanTahun: true,
  52. jumlahLaporan: true,
  53. tahun,
  54. });
  55. this.setState({ graph, tahun });
  56. };
  57. shouldComponentUpdate = (prevProps, prevState) => {
  58. if (prevState.graph !== this.state.graph) return true;
  59. };
  60. excelMenu = () => {
  61. const url = getExcel(this.props.token, "Laporan", {
  62. tahun: this.state.tahun,
  63. pelaporan: true,
  64. });
  65. if (this.state.graph.data.jumlah_laporan.dikti && this.state.graph.data.jumlah_laporan.ditutup && this.state.graph.data.jumlah_laporan.lldikti) {
  66. Router.push(url);
  67. } else {
  68. swal.fire({
  69. title: "Data Kosong",
  70. icon: "error",
  71. confirmButtonColor: "#3e3a8e",
  72. });
  73. }
  74. };
  75. excelSemua = () => {
  76. const url = getExcel(this.props.token, "Laporan", {
  77. tahun: this.state.tahun,
  78. pelaporan: true,
  79. penjadwalan: true,
  80. pemeriksaan: true,
  81. sanksi: true,
  82. });
  83. if (this.state.graph.data.jumlah_laporan.dikti && this.state.graph.data.jumlah_laporan.ditutup && this.state.graph.data.jumlah_laporan.lldikti) {
  84. Router.push(url);
  85. } else {
  86. swal.fire({
  87. title: "Data Kosong",
  88. icon: "error",
  89. confirmButtonColor: "#3e3a8e",
  90. });
  91. }
  92. };
  93. render() {
  94. const { pelaporan, graph, newLaporan } = this.state;
  95. return (
  96. <ContentWrapper>
  97. <div className="content-heading">
  98. <span className="font-color-white">Pelaporan</span>
  99. <div className="ml-auto"></div>
  100. <Link href="/app/penjadwalan">
  101. <Button className="btn-header" color>
  102. <h4 className="font-color-white">Penjadwalan &gt;</h4>
  103. </Button>
  104. </Link>
  105. </div>
  106. <Row>
  107. <Col lg="4">{graph?.data ? <CaseProgress data={graph.data} nextButton={this.nextButton} prevButton={this.prevButton} tahun={this.state.tahun} newLaporan={newLaporan} excelMenu={this.excelMenu} excelSemua={this.excelSemua} /> : <Loader />}</Col>
  108. <Col lg="8">{pelaporan?.data ? <TableLaporan listData={pelaporan.data} to="/app/pelaporan/detail" linkName="Detail" /> : <Loader />}</Col>
  109. </Row>
  110. </ContentWrapper>
  111. );
  112. }
  113. }
  114. const mapStateToProps = (state) => ({ user: state.user, token: state.token });
  115. export default connect(mapStateToProps)(Pelaporan);