detail.js 5.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158
  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, Modal, ModalBody, ModalFooter } 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. import { getCsrf } from "../../../actions/security";
  17. class Sanksi extends Component {
  18. state = {
  19. modal: false,
  20. sanksi: {},
  21. pt: null,
  22. };
  23. static getInitialProps = ({ query }) => ({ query });
  24. componentDidMount = async () => {
  25. const getToken = await getCsrf();
  26. const _csrf = getToken.token;
  27. const { token, query } = this.props;
  28. const sanksi = await getOneSanksi(token, query.id);
  29. updatePT(token, query.id, { is_read: true }, _csrf)
  30. this.setState({ sanksi, pt: sanksi.data.laporan.pt });
  31. };
  32. setModal = (modal) => {
  33. this.setState({
  34. modal: !this.state.modal
  35. })
  36. }
  37. render() {
  38. const { sanksi, pt } = this.state;
  39. return (
  40. <ContentWrapper unwrap>
  41. <Modal isOpen={this.state.modal} toggle={this.props.toggleModal}>
  42. <ModalBody>Apakah anda akan tidak mengajukan permohonan keberatan atas pengenaan sanksi?</ModalBody>
  43. <ModalFooter>
  44. <Button color className="btn-login" onClick={async () => {
  45. const getToken = await getCsrf();
  46. const _csrf = getToken.token;
  47. const toastid = toast.loading("Please wait...");
  48. try {
  49. const { token, query } = this.props;
  50. await updatePT(token, query.id, { is_pengajuan_keberatan: false }, _csrf)
  51. toast.update(toastid, { render: "All is good", type: "success", isLoading: false, autoClose: true, closeButton: true });
  52. Router.push(`/pt/sanksi/dokumen-perbaikan/detail?id=${sanksi.data._id}`);
  53. } catch (error) {
  54. toast.update(toastid, { render: "All is not good", type: "error", isLoading: false, autoClose: true, closeButton: true });
  55. }
  56. }
  57. }>
  58. <span className="font-color-white">Ya</span>
  59. </Button>
  60. <Button color className="btn-v2" onClick={this.setModal}>
  61. Tidak
  62. </Button>
  63. </ModalFooter>
  64. </Modal>
  65. {pt && <Header data={pt} />}
  66. <div className="p-3">
  67. <div className="content-heading">
  68. <span className="font-color-white">
  69. Sanksi
  70. </span>
  71. <div className="ml-auto">
  72. <Link href="/pt/keberatan">
  73. <Button className="color-3e3a8e" color>
  74. <span className="font-color-white">
  75. &lt; Kembali
  76. </span>
  77. </Button>
  78. </Link>
  79. </div>
  80. </div>
  81. <Row>
  82. {sanksi.data ? (
  83. <Col xl="9">
  84. <Card className="card-default">
  85. <CardBody>
  86. <Row>
  87. <Col lg={12}>
  88. <DetailSanksi data={sanksi.data} />
  89. {new Date(sanksi.data.tanggal_akhir_keberatan).getTime() + 86400000 > Date.now() ? (
  90. <>
  91. <p style={{ fontSize: '1vw' }}>
  92. <strong>
  93. Setelah membaca surat keputusan sanksi tersebut, Apakah Perguruan Tinggi bermaksud mengajukan keberatan?
  94. </strong>
  95. </p>
  96. <p style={{ fontSize: '0.9vw' }}>
  97. Pengajuan dilakukan paling lambat tanggal {moment(sanksi.data.tanggal_akhir_keberatan).locale("id").format("DD MMMM YYYY")}
  98. </p>
  99. <p className="lead">
  100. <Link href={{ pathname: "/pt/sanksi/keberatan/detail", query: { id: sanksi.data._id } }}>
  101. <span className="btn-radius">
  102. <Button color="" className="btn-labeled-notHover" onClick={async () => {
  103. // const toastid = toast.loading("Please wait...");
  104. const getToken = await getCsrf();
  105. const _csrf = getToken.token;
  106. try {
  107. const { token, query } = this.props;
  108. await updatePT(token, query.id, { is_pengajuan_keberatan: true }, _csrf)
  109. // toast.update(toastid, { render: "Berhasil", type: "success", isLoading: false, autoClose: true, closeButton: true });
  110. } catch (error) {
  111. // toast.update(toastid, { render: "Gagal", type: "error", isLoading: false, autoClose: true, closeButton: true });
  112. }
  113. }
  114. }>
  115. <h4 className="mt-2 mb-md-2 text-center font-color-white pl-3 pr-3">Ya</h4>
  116. </Button>
  117. </span>
  118. </Link>
  119. <span className="btn-radius">
  120. <Button disabled={sanksi.data.is_pengajuan_keberatan === true || sanksi.data.is_pengajuan_keberatan === false} color className="btn-labeled-3-notHover" onClick={this.setModal} >
  121. <h4 className=" mt-1 mb-md-2 text-center">Tidak</h4>
  122. </Button>
  123. </span>
  124. </p>
  125. </>
  126. ) : (
  127. <p>Pengajuan Keberatan Sudah Ditutup</p>
  128. )}
  129. </Col>
  130. </Row>
  131. </CardBody>
  132. </Card>
  133. </Col>
  134. ) : (
  135. <Loader />
  136. )}
  137. <Col xl="3">{pt && <DetailPT data={pt} />}</Col>
  138. </Row>
  139. {/* {sanksi.data && (
  140. <Row>
  141. <Col>
  142. <Riwayat data={sanksi.data?.pengajuan?.keberatan ? sanksi.data.pengajuan.keberatan : null} />
  143. </Col>
  144. </Row>
  145. )} */}
  146. </div>
  147. </ContentWrapper >
  148. );
  149. }
  150. }
  151. const mapStateToProps = (state) => ({ user: state.user, token: state.token });
  152. export default connect(mapStateToProps)(Sanksi);