pemantauan.js 6.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216
  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. handleOTPagain = async () => {
  55. const { token } = this.props
  56. await createotp({ no_hp: this.state.phone }, token)
  57. this.setState({ modalPhone: false, modalOTP: true })
  58. }
  59. handleSubmitOtp = async () => {
  60. const { token } = this.props
  61. const create = await createkontak({ otp: this.state.otp, no_hp: this.state.phone }, token)
  62. if (create.error) {
  63. swal.fire({
  64. title: create.error.message,
  65. icon: "error",
  66. content: create.error.message,
  67. confirmButtonColor: "#3e3a8e",
  68. });
  69. } else {
  70. swal.fire({
  71. title: "Data berhasil dikirim",
  72. icon: "success",
  73. confirmButtonColor: "#3e3a8e",
  74. });
  75. this.setState({ modalPhone: false, modalOTP: false })
  76. }
  77. }
  78. render() {
  79. const { log, pt } = this.state;
  80. return (
  81. <ContentWrapper unwrap>
  82. {this.state.kontakPT === undefined &&
  83. <Modal isOpen={this.state.kontakPT === undefined && this.state.modalPhone} style={{ width: '400px' }} >
  84. <ModalBody>
  85. <div className="modalLoginPT-a">
  86. <img
  87. className="icon-triangle-onModalPT"
  88. src="/static/img/Frame_10.png"
  89. ></img>
  90. <h3 className=" font-color-black">Konfirmasi Nomor Telepon Perguruan Tinggi</h3>
  91. </div>
  92. <div className="modalLoginPT-b">
  93. <label className=" font-weight-bold h6">
  94. Nomor Telepon :
  95. </label>
  96. <div className="border-2">
  97. <PhoneInput
  98. country={'id'}
  99. value={this.state.phone}
  100. onChange={phone => this.setState({ phone })} />
  101. </div>
  102. </div>
  103. <div>
  104. <Button className="btn-v2 float-left mr-2 ml-4" style={{ width: "40%" }} color onClick={this.otpClose}>
  105. <span className=" font-color-black">
  106. Batal
  107. </span>
  108. </Button>
  109. <Button className="btn-login float-right mr-4" style={{ width: "40%" }} color onClick={this.handleSubmitTelepon}>
  110. {this.state.loadingProses ?
  111. (
  112. <div class="d-flex justify-content-center">
  113. <span
  114. class="spinner-border spinner-border-sm text-white"
  115. role="status"
  116. ></span>
  117. <span className="font-color-white">
  118. &nbsp; Diproses...
  119. </span>
  120. </div>
  121. ) : (
  122. <span className="font-color-white">
  123. Simpan
  124. </span>
  125. )}
  126. </Button>
  127. </div>
  128. </ModalBody>
  129. </Modal>
  130. }
  131. <Modal isOpen={this.state.modalOTP} style={{ width: '400px' }} >
  132. <ModalBody>
  133. <div className="modalLoginPT-a">
  134. <img
  135. className="icon-triangle-onModalPT mt-auto mb-auto"
  136. src="/static/img/Frame_10.png"
  137. ></img>
  138. <h3 className=" font-color-black">Masukan Kode OTP</h3>
  139. </div>
  140. {/* <div className="modalLoginPT-b"> */}
  141. <div className=" mt-5 mb-5">
  142. <OtpInput
  143. invalid={this.state.error}
  144. value={this.state.otp}
  145. onChange={(otp) => { this.setState({ otp }) }}
  146. numInputs={4}
  147. renderSeparator={<span className=" font-color-black font-weight-bold mr-2 ml-2">-</span>}
  148. renderInput={(props) => <input {...props} style={{ width: "50px", height: "50px", textAlign: "center", marginLeft: "auto", marginRight: "auto", borderRadius: "7px", fontSize: "30px" }} />}
  149. />
  150. <p className=" mt-3">
  151. *Kode OTP terkirim ke nomor WA {this.state.phone}
  152. </p>
  153. <p className=" mt-3 ">
  154. Jika Anda belum menerima kode OTP, <span className=" btn-link" onClick={this.handleOTPagain}>kirimkan ulang kode OTP</span>
  155. </p>
  156. <FormFeedback invalid={this.state.error}>
  157. Kode verifikasi harus diisi
  158. </FormFeedback>
  159. </div>
  160. <div>
  161. <Button className="btn-v2 float-left mr-2 ml-4" style={{ width: "40%" }} color onClick={this.otpClose}>
  162. <span className=" font-color-black">
  163. Batal
  164. </span>
  165. </Button>
  166. <Button className="btn-login float-right mr-4" style={{ width: "40%" }} color onClick={this.handleSubmitOtp}
  167. >
  168. <span className=" font-color-white">
  169. Simpan
  170. </span>
  171. </Button>
  172. </div>
  173. </ModalBody>
  174. </Modal>
  175. {pt?.data ? <Header data={pt.data} /> : <Loader />}
  176. <div className="p-3">
  177. <Row>
  178. {log.data ? (
  179. <Col xl="9">
  180. <Timeline data={log.data} />
  181. </Col>
  182. ) : (
  183. <Loader />
  184. )}
  185. <Col xl="3">{pt.data && <DetailPT data={pt.data} />}</Col>
  186. </Row>
  187. </div>
  188. </ContentWrapper>
  189. );
  190. }
  191. }
  192. const mapStateToProps = (state) => ({ user: state.user, token: state.token });
  193. export default connect(mapStateToProps)(Pemantauan);