index.js 3.7 KB

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