index.js 5.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144
  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. import swal from "sweetalert2";
  14. class PelaporanTuntas extends Component {
  15. constructor(props) {
  16. super(props);
  17. this.state = {
  18. pelaporan: {},
  19. graph: {},
  20. tahun: new Date().getFullYear(),
  21. laporanSelesai: {}
  22. };
  23. }
  24. componentDidMount = async () => {
  25. const { token } = this.props;
  26. let laporanSelesai = await getlaporanselesai(token);
  27. laporanSelesai = {
  28. ...laporanSelesai, data: {
  29. ...laporanSelesai.data, laporan: [...laporanSelesai.data.laporan, ...laporanSelesai.data.sanksi], sanksi: null
  30. }
  31. }
  32. const pelaporan = await getPelaporan(token, { jadwal: true, aktif: false });
  33. const graph = await getGraph(this.props.token, { evaluasi: true, listJadwal: true, aktif: false });
  34. this.setState({ pelaporan, graph, laporanSelesai });
  35. };
  36. nextButton = async () => {
  37. const tahun = this.state.tahun + 1;
  38. const { token } = this.props;
  39. let laporanSelesai = await getlaporanselesai(token);
  40. laporanSelesai = {
  41. ...laporanSelesai, data: {
  42. ...laporanSelesai.data, laporan: [...laporanSelesai.data.laporan, ...laporanSelesai.data.sanksi], sanksi: null
  43. }
  44. }
  45. this.setState({ laporanSelesai, tahun });
  46. };
  47. prevButton = async () => {
  48. const tahun = this.state.tahun - 1;
  49. const { token } = this.props;
  50. let laporanSelesai = await getlaporanselesai(token);
  51. laporanSelesai = {
  52. ...laporanSelesai, data: {
  53. ...laporanSelesai.data, laporan: [...laporanSelesai.data.laporan, ...laporanSelesai.data.sanksi], sanksi: null
  54. }
  55. }
  56. this.setState({ laporanSelesai, tahun });
  57. };
  58. shouldComponentUpdate = (prevProps, prevState) => {
  59. if (prevState.graph !== this.state.graph) return true;
  60. };
  61. excel = () => {
  62. const url = getExcel(this.props.token, "Laporan", { tahun: this.state.tahun });
  63. Router.push(url);
  64. };
  65. excelMenu = () => {
  66. if (this.props.user.role.id === 2024) {
  67. swal.fire({
  68. icon: 'error',
  69. title: 'Oops...',
  70. html: 'Maaf anda tidak memiliki akses untuk menyelesaikan<p> proses ini.</p>',
  71. confirmButtonColor: "#3e3a8e",
  72. confirmButtonText: 'Oke'
  73. })
  74. } else {
  75. const url = getExcel(this.props.token, "Laporan", {
  76. tahun: this.state.tahun,
  77. pelaporan: true,
  78. });
  79. if (this.state.graph.data.jumlah_ditutup && this.state.graph.data.jumlah_selesai) {
  80. Router.push(url);
  81. } else {
  82. swal.fire({
  83. title: "Data Kosong",
  84. icon: "error",
  85. confirmButtonColor: "#3e3a8e",
  86. });
  87. }}
  88. };
  89. excelSemua = () => {
  90. if (this.props.user.role.id === 2024) {
  91. swal.fire({
  92. icon: 'error',
  93. title: 'Oops...',
  94. html: 'Maaf anda tidak memiliki akses untuk menyelesaikan<p> proses ini.</p>',
  95. confirmButtonColor: "#3e3a8e",
  96. confirmButtonText: 'Oke'
  97. })
  98. } else {
  99. const url = getExcel(this.props.token, "Laporan", {
  100. tahun: this.state.tahun,
  101. pelaporan: true,
  102. penjadwalan: true,
  103. pemeriksaan: true,
  104. sanksi: true,
  105. });
  106. if (this.state.graph.data.jumlah_ditutup && this.state.graph.data.jumlah_selesai) {
  107. Router.push(url);
  108. } else {
  109. swal.fire({
  110. title: "Data Kosong",
  111. icon: "error",
  112. confirmButtonColor: "#3e3a8e",
  113. });
  114. }}
  115. };
  116. render() {
  117. const { pelaporan, graph, laporanSelesai } = this.state;
  118. return (
  119. <ContentWrapper>
  120. <div className="content-heading">
  121. <span className="font-color-white">
  122. Pelaporan Tuntas
  123. </span>
  124. </div>
  125. <Row>
  126. <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>
  127. <Col lg="8">{laporanSelesai?.data?.laporan ? <TableLaporan status noBy listData={laporanSelesai.data.laporan} to="/app/tuntas/detail" linkName="Detail" /> : <Loader />}</Col>
  128. </Row>
  129. </ContentWrapper>
  130. );
  131. }
  132. }
  133. const mapStateToProps = (state) => ({ user: state.user, token: state.token });
  134. export default connect(mapStateToProps)(PelaporanTuntas);