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