detail.js 5.7 KB

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