index.js 2.7 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586
  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. class Penjadwalan extends Component {
  14. constructor(props) {
  15. super(props);
  16. this.state = {
  17. pelaporan: {},
  18. graph: {},
  19. tahun: new Date().getFullYear(),
  20. };
  21. }
  22. componentDidMount = async () => {
  23. const { token } = this.props;
  24. const pelaporan = await getPelaporan(token);
  25. const graph = await getGraph(this.props.token, { jadwal: true });
  26. this.setState({ pelaporan, graph });
  27. };
  28. nextButton = async () => {
  29. const tahun = this.state.tahun + 1;
  30. const graph = await getGraph(this.props.token, { jadwal: true, tahun });
  31. this.setState({ graph, tahun });
  32. };
  33. prevButton = async () => {
  34. const tahun = this.state.tahun - 1;
  35. const graph = await getGraph(this.props.token, { jadwal: true, tahun });
  36. this.setState({ graph, tahun });
  37. };
  38. shouldComponentUpdate = (prevProps, prevState) => {
  39. if (prevState.graph !== this.state.graph) return true;
  40. };
  41. excel = () => {
  42. const url = getExcel(this.props.token, "Laporan", { tahun: this.state.tahun });
  43. Router.push(url);
  44. };
  45. render() {
  46. const { pelaporan, graph } = this.state;
  47. return (
  48. <ContentWrapper>
  49. <div className="content-heading">
  50. <span className="font-color-white">
  51. Penjadwalan Evaluasi
  52. </span>
  53. <div className="ml-auto">
  54. <Link href="/app/pelaporan">
  55. <span className="margin-l-5">
  56. <Button className="btn-header" color>
  57. <h4 className="font-color-white">&lt; Pelaporan</h4>
  58. </Button>
  59. </span>
  60. </Link>
  61. <Link href="/app/pemeriksaan">
  62. <Button className="btn-header" color>
  63. <h4 className="font-color-white">Pemeriksaan &gt;</h4>
  64. </Button>
  65. </Link>
  66. </div>
  67. </div>
  68. <Row>
  69. <Col lg="4">{graph?.data ? <CaseProgress data={graph.data} nextButton={this.nextButton} prevButton={this.prevButton} tahun={this.state.tahun} excel={this.excel} /> : <Loader />}</Col>
  70. <Col lg="8">{pelaporan?.data ? <TableLaporan listData={pelaporan.data} to="/app/penjadwalan/todo" linkName="Atur Jadwal" /> : <Loader />}</Col>
  71. </Row>
  72. </ContentWrapper>
  73. );
  74. }
  75. }
  76. const mapStateToProps = (state) => ({ user: state.user, token: state.token });
  77. export default connect(mapStateToProps)(Penjadwalan);