pemantauan.js 5.3 KB

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