index.js 3.6 KB

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