pemantauan.js 5.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183
  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. class Pemantauan extends Component {
  17. constructor(props) {
  18. super(props);
  19. this.state = {
  20. log: [],
  21. pt: {},
  22. modalPhone: false,
  23. otpClose: false,
  24. modalOTP: false,
  25. otp: "",
  26. phone: "",
  27. // closeVerifikasi:false,
  28. };
  29. }
  30. componentDidMount = async () => {
  31. const { token } = this.props;
  32. const log = await getLogPT(token);
  33. const pt = await getPT(token);
  34. const kontakPT = await getkontakpt(token);
  35. this.setState({ log, pt, kontakPT });
  36. const closeverif = localStorage.getItem(("closeverif"))
  37. if (kontakPT=== undefined && closeverif === null) {
  38. this.setState({modalPhone:true})
  39. }
  40. };
  41. otpClose = () => {
  42. // return location.href = '/pt/pemantauan';71
  43. this.setState({ modalOTP: false, modalPhone: false })
  44. localStorage.setItem("closeverif", "true");
  45. }
  46. handleSubmitTelepon = async () => {
  47. const { token } = this.props
  48. const create = createotp({ no_hp: this.state.phone }, token)
  49. await toast.promise(create, {
  50. pending: "Loading...",
  51. // success: "Berhasil ",
  52. error: "Error",
  53. },)
  54. this.setState({ modalPhone: false, modalOTP: true })
  55. }
  56. handleSubmitOtp = async () => {
  57. const { token } = this.props
  58. const create = createkontak({ otp: this.state.otp, no_hp: this.state.phone }, token)
  59. await toast.promise(create, {
  60. pending: "Loading...",
  61. success: "Success",
  62. error: "Error",
  63. },)
  64. this.setState({ modalPhone: false, modalOTP: false })
  65. }
  66. render() {
  67. const { log, pt } = this.state;
  68. return (
  69. <ContentWrapper unwrap>
  70. {this.state.kontakPT === undefined &&
  71. <Modal isOpen={ this.state.kontakPT === undefined && this.state.modalPhone} style={{ width: '400px' }} >
  72. <ModalBody>
  73. <div className="modalLoginPT-a">
  74. <img
  75. className="icon-triangle-onModalPT"
  76. src="/static/img/Frame_10.png"
  77. ></img>
  78. <h3 className=" font-color-black">Konfirmasi Nomor Telepon Perguruan Tinggi</h3>
  79. </div>
  80. <div className="modalLoginPT-b">
  81. <label className=" font-weight-bold h6">
  82. Nomor Telepon :
  83. </label>
  84. <div className="border-2">
  85. <PhoneInput
  86. country={'id'}
  87. value={this.state.phone}
  88. onChange={phone => this.setState({ phone })} />
  89. </div>
  90. </div>
  91. <div>
  92. <Button className="btn-v2 float-left mr-2 ml-4" style={{ width: "40%" }} color onClick={this.otpClose}>
  93. <span className=" font-color-black">
  94. Batal
  95. </span>
  96. </Button>
  97. <Button className="btn-login float-right mr-4" style={{ width: "40%" }} color onClick={this.handleSubmitTelepon}>
  98. <span className=" font-color-white">
  99. Kirim
  100. </span>
  101. </Button>
  102. </div>
  103. </ModalBody>
  104. </Modal>
  105. }
  106. <Modal isOpen={this.state.modalOTP} style={{ width: '400px' }} >
  107. <ModalBody>
  108. <div className="modalLoginPT-a">
  109. <img
  110. className="icon-triangle-onModalPT mt-auto mb-auto"
  111. src="/static/img/Frame_10.png"
  112. ></img>
  113. <h3 className=" font-color-black">Masukan Kode OTP</h3>
  114. </div>
  115. {/* <div className="modalLoginPT-b"> */}
  116. <div className=" mt-5 mb-5">
  117. <OtpInput
  118. invalid={this.state.error}
  119. value={this.state.otp}
  120. onChange={(otp) => { this.setState({ otp }) }}
  121. numInputs={4}
  122. renderSeparator={<span className=" font-color-black font-weight-bold mr-2 ml-2">-</span>}
  123. renderInput={(props) => <input {...props} style={{ width: "50px", height: "50px", textAlign: "center", marginLeft: "auto", marginRight: "auto", borderRadius: "7px", fontSize: "30px" }} />}
  124. /> <p className=" mt-3">
  125. *Kode OTP terkirim ke nomor WA {this.state.phone}
  126. </p>
  127. <FormFeedback invalid={this.state.error}>
  128. Kode verifikasi harus diisi
  129. </FormFeedback>
  130. </div>
  131. <div>
  132. <Button className="btn-v2 float-left mr-2 ml-4" style={{ width: "40%" }} color onClick={this.otpClose}>
  133. <span className=" font-color-black">
  134. Batal
  135. </span>
  136. </Button>
  137. <Button className="btn-login float-right mr-4" style={{ width: "40%" }} color onClick={this.handleSubmitOtp}
  138. >
  139. <span className=" font-color-white">
  140. Kirim
  141. </span>
  142. </Button>
  143. </div>
  144. </ModalBody>
  145. </Modal>
  146. {pt?.data ? <Header data={pt.data} /> : <Loader />}
  147. <div className="p-3">
  148. <Row>
  149. {log.data ? (
  150. <Col xl="9">
  151. <Timeline data={log.data} />
  152. </Col>
  153. ) : (
  154. <Loader />
  155. )}
  156. <Col xl="3">{pt.data && <DetailPT data={pt.data} />}</Col>
  157. </Row>
  158. </div>
  159. </ContentWrapper>
  160. );
  161. }
  162. }
  163. const mapStateToProps = (state) => ({ user: state.user, token: state.token });
  164. export default connect(mapStateToProps)(Pemantauan);