index.js 4.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147
  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. import Swal from "sweetalert2";
  16. class Pelaporan extends Component {
  17. constructor(props) {
  18. super(props);
  19. this.state = {
  20. pelaporan: {},
  21. graph: {},
  22. tahun: new Date().getFullYear(),
  23. newLaporan: [],
  24. };
  25. }
  26. componentDidMount = async () => {
  27. const { token } = this.props;
  28. const getTokenCsrf = await getCsrf();
  29. const _csrf = getTokenCsrf.token;
  30. await createLog(token, { aktivitas: "Mengakses halaman Pelaporan", menu: "Pelaporan", _csrf: _csrf });
  31. const pelaporan = await getPelaporan(this.props.token);
  32. const graph = await getGraph(this.props.token, {
  33. laporanTahun: true,
  34. newLaporan: true,
  35. jumlahLaporan: true,
  36. });
  37. const newLaporan = graph.data?.newLaporan;
  38. this.setState({ pelaporan, graph, newLaporan });
  39. };
  40. nextButton = async () => {
  41. const tahun = this.state.tahun + 1;
  42. const graph = await getGraph(this.props.token, {
  43. laporanTahun: true,
  44. jumlahLaporan: true,
  45. tahun,
  46. });
  47. this.setState({ graph, tahun });
  48. };
  49. prevButton = async () => {
  50. const tahun = this.state.tahun - 1;
  51. const graph = await getGraph(this.props.token, {
  52. laporanTahun: true,
  53. jumlahLaporan: true,
  54. tahun,
  55. });
  56. this.setState({ graph, tahun });
  57. };
  58. shouldComponentUpdate = (prevProps, prevState) => {
  59. if (prevState.graph !== this.state.graph) return true;
  60. };
  61. excelMenu = () => {
  62. if (this.props?.user?.role.id === 2071) {
  63. Swal.fire({
  64. icon: 'error',
  65. title: 'Oops...',
  66. html: 'Maaf anda tidak memiliki akses untuk menyelesaikan<p> proses ini.</p>',
  67. confirmButtonColor: "#3e3a8e",
  68. confirmButtonText: 'Oke'
  69. // footer: '<a href="">Why do I have this issue?</a>'
  70. })
  71. } else {
  72. const url = getExcel(this.props.token, "Laporan", {
  73. tahun: this.state.tahun,
  74. pelaporan: true,
  75. });
  76. if (this.state.graph.data.jumlah_laporan.dikti && this.state.graph.data.jumlah_laporan.ditutup && this.state.graph.data.jumlah_laporan.lldikti) {
  77. Router.push(url);
  78. } else {
  79. swal.fire({
  80. title: "Data Kosong",
  81. icon: "error",
  82. confirmButtonColor: "#3e3a8e",
  83. });
  84. }
  85. }
  86. };
  87. excelSemua = () => {
  88. if (this.props?.user?.role.id === 2071) {
  89. Swal.fire({
  90. icon: 'error',
  91. title: 'Oops...',
  92. html: 'Maaf anda tidak memiliki akses untuk menyelesaikan<p> proses ini.</p>',
  93. confirmButtonColor: "#3e3a8e",
  94. confirmButtonText: 'Oke'
  95. // footer: '<a href="">Why do I have this issue?</a>'
  96. })
  97. } else {
  98. const url = getExcel(this.props.token, "Laporan", {
  99. tahun: this.state.tahun,
  100. pelaporan: true,
  101. penjadwalan: true,
  102. pemeriksaan: true,
  103. sanksi: true,
  104. });
  105. if (this.state.graph.data.jumlah_laporan.dikti && this.state.graph.data.jumlah_laporan.ditutup && this.state.graph.data.jumlah_laporan.lldikti) {
  106. Router.push(url);
  107. } else {
  108. swal.fire({
  109. title: "Data Kosong",
  110. icon: "error",
  111. confirmButtonColor: "#3e3a8e",
  112. });
  113. }
  114. }
  115. };
  116. render() {
  117. const { pelaporan, graph, newLaporan } = this.state;
  118. return (
  119. <ContentWrapper>
  120. <div className="content-heading">
  121. <span className="font-color-white">Pelaporan</span>
  122. <div className="ml-auto"></div>
  123. <Link href="/app/penjadwalan">
  124. <Button className="btn-header" color>
  125. <h4 className="font-color-white">Penjadwalan &gt;</h4>
  126. </Button>
  127. </Link>
  128. </div>
  129. <Row>
  130. <Col lg="4">{graph?.data ? <CaseProgress user={this?.props?.user} data={graph.data} nextButton={this.nextButton} prevButton={this.prevButton} tahun={this.state.tahun} newLaporan={newLaporan} excelMenu={this.excelMenu} excelSemua={this.excelSemua} /> : <Loader />}</Col>
  131. <Col lg="8">{pelaporan?.data ? <TableLaporan listData={pelaporan.data} to="/app/pelaporan/detail" linkName="Detail" /> : <Loader />}</Col>
  132. </Row>
  133. </ContentWrapper>
  134. );
  135. }
  136. }
  137. const mapStateToProps = (state) => ({ user: state.user, token: state.token });
  138. export default connect(mapStateToProps)(Pelaporan);