pemantauan.js 6.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206
  1. import React, { Component } from "react";
  2. import ContentWrapper from "@/components/Layout/ContentWrapper";
  3. import Header from "@/components/Main/Header";
  4. import DetailPT from "@/components/Main/DetailPT";
  5. import { getLogPT } from "@/actions/log";
  6. import { getPT } from "@/actions/PT";
  7. import { Row, Col, ModalHeader, ModalBody, ModalFooter, Modal, FormFeedback, Button } from "reactstrap";
  8. import Timeline from "@/components/Main/Timeline";
  9. import { connect } from "react-redux";
  10. import Loader from "@/components/Common/Loader";
  11. import { createotp, getkontakpt, createkontak } from "../../actions/auth";
  12. import PhoneInput from 'react-phone-input-2'
  13. import 'react-phone-input-2/lib/style.css'
  14. import OtpInput from 'react-otp-input';
  15. import { ToastContainer, toast } from "react-toastify";
  16. import swal from "sweetalert2";
  17. class Pemantauan extends Component {
  18. constructor(props) {
  19. super(props);
  20. this.state = {
  21. log: [],
  22. pt: {},
  23. modalPhone: false,
  24. otpClose: false,
  25. modalOTP: false,
  26. otp: "",
  27. phone: "",
  28. loadingProses: false,
  29. // closeVerifikasi:false,
  30. };
  31. }
  32. componentDidMount = async () => {
  33. const { token } = this.props;
  34. const log = await getLogPT(token);
  35. const pt = await getPT(token);
  36. const kontakPT = await getkontakpt(token);
  37. this.setState({ log, pt, kontakPT });
  38. const closeverif = localStorage.getItem(("closeverif"))
  39. if (kontakPT === undefined && closeverif === null) {
  40. this.setState({ modalPhone: true })
  41. }
  42. };
  43. otpClose = () => {
  44. // return location.href = '/pt/pemantauan';71
  45. this.setState({ modalOTP: false, modalPhone: false })
  46. localStorage.setItem("closeverif", "true");
  47. }
  48. handleSubmitTelepon = async () => {
  49. this.setState({ loadingProses: true })
  50. const { token } = this.props
  51. await createotp({ no_hp: this.state.phone }, token)
  52. this.setState({ modalPhone: false, modalOTP: true })
  53. }
  54. handleSubmitOtp = async () => {
  55. const { token } = this.props
  56. const create = await createkontak({ otp: this.state.otp, no_hp: this.state.phone }, token)
  57. if (create.error) {
  58. swal.fire({
  59. title: create.error.message,
  60. icon: "error",
  61. content: create.error.message,
  62. confirmButtonColor: "#3e3a8e",
  63. });
  64. } else {
  65. swal.fire({
  66. title: "Data berhasil dikirim",
  67. icon: "success",
  68. confirmButtonColor: "#3e3a8e",
  69. });
  70. this.setState({ modalPhone: false, modalOTP: false })
  71. }
  72. }
  73. render() {
  74. const { log, pt } = this.state;
  75. return (
  76. <ContentWrapper unwrap>
  77. {this.state.kontakPT === undefined &&
  78. <Modal isOpen={this.state.kontakPT === undefined && this.state.modalPhone} style={{ width: '400px' }} >
  79. <ModalBody>
  80. <div className="modalLoginPT-a">
  81. <img
  82. className="icon-triangle-onModalPT"
  83. src="/static/img/Frame_10.png"
  84. ></img>
  85. <h3 className=" font-color-black">Konfirmasi Nomor Telepon Perguruan Tinggi</h3>
  86. </div>
  87. <div className="modalLoginPT-b">
  88. <label className=" font-weight-bold h6">
  89. Nomor Telepon :
  90. </label>
  91. <div className="border-2">
  92. <PhoneInput
  93. country={'id'}
  94. value={this.state.phone}
  95. onChange={phone => this.setState({ phone })} />
  96. </div>
  97. </div>
  98. <div>
  99. <Button className="btn-v2 float-left mr-2 ml-4" style={{ width: "40%" }} color onClick={this.otpClose}>
  100. <span className=" font-color-black">
  101. Batal
  102. </span>
  103. </Button>
  104. <Button className="btn-login float-right mr-4" style={{ width: "40%" }} color onClick={this.handleSubmitTelepon}>
  105. {this.state.loadingProses ?
  106. (
  107. <div class="d-flex justify-content-center">
  108. <span
  109. class="spinner-border spinner-border-sm text-white"
  110. role="status"
  111. ></span>
  112. <span className="font-color-white">
  113. &nbsp; Diproses...
  114. </span>
  115. </div>
  116. ) : (
  117. <span className="font-color-white">
  118. Kirim
  119. </span>
  120. )}
  121. </Button>
  122. </div>
  123. </ModalBody>
  124. </Modal>
  125. }
  126. <Modal isOpen={this.state.modalOTP} style={{ width: '400px' }} >
  127. <ModalBody>
  128. <div className="modalLoginPT-a">
  129. <img
  130. className="icon-triangle-onModalPT mt-auto mb-auto"
  131. src="/static/img/Frame_10.png"
  132. ></img>
  133. <h3 className=" font-color-black">Masukan Kode OTP</h3>
  134. </div>
  135. {/* <div className="modalLoginPT-b"> */}
  136. <div className=" mt-5 mb-5">
  137. <OtpInput
  138. invalid={this.state.error}
  139. value={this.state.otp}
  140. onChange={(otp) => { this.setState({ otp }) }}
  141. numInputs={4}
  142. renderSeparator={<span className=" font-color-black font-weight-bold mr-2 ml-2">-</span>}
  143. renderInput={(props) => <input {...props} style={{ width: "50px", height: "50px", textAlign: "center", marginLeft: "auto", marginRight: "auto", borderRadius: "7px", fontSize: "30px" }} />}
  144. /> <p className=" mt-3">
  145. *Kode OTP terkirim ke nomor WA {this.state.phone}
  146. </p>
  147. <FormFeedback invalid={this.state.error}>
  148. Kode verifikasi harus diisi
  149. </FormFeedback>
  150. </div>
  151. <div>
  152. <Button className="btn-v2 float-left mr-2 ml-4" style={{ width: "40%" }} color onClick={this.otpClose}>
  153. <span className=" font-color-black">
  154. Batal
  155. </span>
  156. </Button>
  157. <Button className="btn-login float-right mr-4" style={{ width: "40%" }} color onClick={this.handleSubmitOtp}
  158. >
  159. <span className=" font-color-white">
  160. Kirim
  161. </span>
  162. </Button>
  163. </div>
  164. </ModalBody>
  165. </Modal>
  166. {pt?.data ? <Header data={pt.data} /> : <Loader />}
  167. <div className="p-3">
  168. <Row>
  169. {log.data ? (
  170. <Col xl="9">
  171. <Timeline data={log.data} />
  172. </Col>
  173. ) : (
  174. <Loader />
  175. )}
  176. <Col xl="3">{pt.data && <DetailPT data={pt.data} />}</Col>
  177. </Row>
  178. </div>
  179. </ContentWrapper>
  180. );
  181. }
  182. }
  183. const mapStateToProps = (state) => ({ user: state.user, token: state.token });
  184. export default connect(mapStateToProps)(Pemantauan);