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