detail.js 4.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135
  1. import React, { Component } from "react";
  2. import ContentWrapper from "@/components/Layout/ContentWrapper";
  3. import { getOneSanksi, updatePT } from "@/actions/sanksi";
  4. import Header from "@/components/Main/Header";
  5. import DetailPT from "@/components/Main/DetailPT";
  6. import DetailSanksi from "@/components/Main/DetailSanksi";
  7. import Riwayat from "@/components/PT/Keberatan/Riwayat";
  8. import ModalPermohonan from "@/components/PT/Keberatan/ModalPermohonan";
  9. import Link from "next/link";
  10. import moment from "moment";
  11. import { Row, Col, Card, CardBody, Button } from "reactstrap";
  12. import { connect } from "react-redux";
  13. import Router from "next/router";
  14. import Loader from "@/components/Common/Loader";
  15. import { ToastContainer, toast } from "react-toastify";
  16. class Sanksi extends Component {
  17. state = {
  18. modal: false,
  19. sanksi: {},
  20. pt: null,
  21. };
  22. static getInitialProps = ({ query }) => ({ query });
  23. componentDidMount = async () => {
  24. const { token, query } = this.props;
  25. const sanksi = await getOneSanksi(token, query.id);
  26. updatePT(token, query.id, { is_read: true })
  27. this.setState({ sanksi, pt: sanksi.data.laporan.pt });
  28. };
  29. render() {
  30. const { sanksi, pt } = this.state;
  31. console.log(sanksi)
  32. return (
  33. <ContentWrapper unwrap>
  34. {pt && <Header data={pt} />}
  35. <div className="p-3">
  36. <div className="content-heading">
  37. <span className="font-color-white">
  38. Sanksi
  39. </span>
  40. <div className="ml-auto">
  41. <Link href="/pt/keberatan">
  42. <Button className="color-3e3a8e" color>
  43. <span className="font-color-white">
  44. &lt; Kembali
  45. </span>
  46. </Button>
  47. </Link>
  48. </div>
  49. </div>
  50. <Row>
  51. {sanksi.data ? (
  52. <Col xl="9">
  53. <Card className="card-default">
  54. <CardBody>
  55. <Row>
  56. <Col lg={12}>
  57. <DetailSanksi data={sanksi.data} />
  58. {new Date(sanksi.data.batas_waktu.keberatan).getTime() > Date.now() ? (
  59. <>
  60. <p style={{ fontSize: '1vw' }}>
  61. <strong>
  62. Setelah membaca surat keputusan sanksi tersebut, Apakah Perguruan Tinggi bermaksud mengajukan keberatan?
  63. </strong>
  64. </p>
  65. <p style={{ fontSize: '0.8vw' }}>
  66. Pengajuan dilakukan paling lambat tanggal {moment(sanksi.data.batas_waktu.keberatan).locale("id").format("DD MMMM YYYY")}
  67. </p>
  68. <p className="lead">
  69. <span className="btn-radius">
  70. <Button color="" disabled={sanksi.data.is_pengajuan === true || sanksi.data.is_pengajuan === false} className="btn-labeled" onClick={async () => {
  71. const toastid = toast.loading("Please wait...");
  72. try {
  73. const { token, query } = this.props;
  74. await updatePT(token, query.id, { is_pengajuan: true })
  75. toast.update(toastid, { render: "All is good", type: "success", isLoading: false, autoClose: true, closeButton: true });
  76. Router.push("/pt/keberatan");
  77. } catch (error) {
  78. toast.update(toastid, { render: "All is not good", type: "error", isLoading: false, autoClose: true, closeButton: true });
  79. }
  80. }
  81. }>
  82. <h4 className="mt-2 mb-md-2 text-center font-color-white pl-3 pr-3">Ya</h4>
  83. </Button>
  84. </span>
  85. <span className="btn-radius">
  86. <Button disabled={sanksi.data.is_pengajuan === true || sanksi.data.is_pengajuan === false} color className="btn-labeled-3" onClick={async () => {
  87. const toastid = toast.loading("Please wait...");
  88. try {
  89. const { token, query } = this.props;
  90. await updatePT(token, query.id, { is_pengajuan: false })
  91. toast.update(toastid, { render: "All is good", type: "success", isLoading: false, autoClose: true, closeButton: true });
  92. Router.push("/pt/dokumen-perbaikan");
  93. } catch (error) {
  94. toast.update(toastid, { render: "All is not good", type: "error", isLoading: false, autoClose: true, closeButton: true });
  95. }
  96. }
  97. }>
  98. <h4 className=" mt-1 mb-md-2 text-center">Tidak</h4>
  99. </Button>
  100. </span>
  101. </p>
  102. </>
  103. ) : (
  104. <p>Pengajuan ditutup</p>
  105. )}
  106. </Col>
  107. </Row>
  108. </CardBody>
  109. </Card>
  110. </Col>
  111. ) : (
  112. <Loader />
  113. )}
  114. <Col xl="3">{pt && <DetailPT data={pt} />}</Col>
  115. </Row>
  116. {sanksi.data && (
  117. <Row>
  118. <Col>
  119. <Riwayat data={sanksi.data?.pengajuan?.keberatan ? sanksi.data.pengajuan.keberatan : null} />
  120. </Col>
  121. </Row>
  122. )}
  123. </div>
  124. </ContentWrapper >
  125. );
  126. }
  127. }
  128. const mapStateToProps = (state) => ({ user: state.user, token: state.token });
  129. export default connect(mapStateToProps)(Sanksi);