DetailPT.js 7.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265
  1. import React, { Component } from "react";
  2. import ContentWrapper from "@/components/Layout/ContentWrapper";
  3. import Header from "@/components/Main/Header";
  4. import { getLogPT } from "@/actions/log";
  5. import { getPT } from "@/actions/PT";
  6. import { Row, Col, ModalHeader, ModalBody, ModalFooter, Modal, FormFeedback, Button, Alert } from "reactstrap";
  7. import Timeline from "@/components/Main/Timeline";
  8. import { connect } from "react-redux";
  9. import Loader from "@/components/Common/Loader";
  10. import { createotp, getkontakpt, createkontak } from "../../actions/auth";
  11. import PhoneInput from 'react-phone-input-2'
  12. import 'react-phone-input-2/lib/style.css'
  13. import OtpInput from 'react-otp-input';
  14. import { ToastContainer, toast } from "react-toastify";
  15. import swal from "sweetalert2";
  16. class DetailPT extends Component {
  17. state = {
  18. phone: "",
  19. ddselected: false,
  20. modalOTP: false,
  21. loadingProses: false,
  22. otp: "",
  23. sendingOTP: false,
  24. newphone: "",
  25. }
  26. componentDidMount = async () => {
  27. const { token } = this.props;
  28. const kontakPT = await getkontakpt(token);
  29. const oldPhone = kontakPT?.data.map((data) => (data.no_hp)).toString()
  30. if (oldPhone) {
  31. this.setState({ phone: oldPhone })
  32. }
  33. }
  34. OpenEditNoTelp = () => this.setState({
  35. ddselected: !this.state.ddselected
  36. })
  37. handleSubmitTelepon = async () => {
  38. this.setState({ loadingProses: true })
  39. const { token } = this.props
  40. if (this.state.newphone.length) {
  41. await createotp({ no_hp: this.state.newphone }, token)
  42. } else {
  43. await createotp({ no_hp: this.state.phone }, token)
  44. }
  45. this.setState({ modalPhone: false, modalOTP: true })
  46. }
  47. handleOTPagain = async () => {
  48. this.setState({ sendingOTP: true })
  49. const { token } = this.props
  50. await createotp({ no_hp: this.state.newphone }, token)
  51. this.setState({ modalPhone: false, modalOTP: true })
  52. setTimeout(() => {
  53. this.setState({
  54. sendingOTP: !this.state.sendingOTP
  55. });
  56. }, 5000);
  57. }
  58. otpClose = () => {
  59. this.setState({ modalOTP: false, ddselected: false, loadingProses: false, otp: "" })
  60. }
  61. handleSubmitOtp = async () => {
  62. const { token } = this.props
  63. const create = await createkontak({ otp: this.state.otp, no_hp: this.state.newphone }, token)
  64. if (create.error) {
  65. swal.fire({
  66. title: create.error.message,
  67. icon: "error",
  68. content: create.error.message,
  69. confirmButtonColor: "#3e3a8e",
  70. });
  71. } else {
  72. swal.fire({
  73. title: "Data berhasil dikirim",
  74. icon: "success",
  75. confirmButtonColor: "#3e3a8e",
  76. });
  77. this.setState({ ddselected: false, modalOTP: false, loadingProses: false, otp: "" })
  78. window.location.reload(false);
  79. }
  80. }
  81. render() {
  82. const { data } = this.props;
  83. return (
  84. <div className="card card-default">
  85. <Modal isOpen={this.state.ddselected} style={{ width: '400px' }}>
  86. <ModalBody>
  87. <div className="modalLoginPT-a">
  88. <img
  89. className="icon-triangle-onModalPT mt-0"
  90. src="/static/img/Frame_10.png"
  91. ></img>
  92. <h4 className=" font-color-black mt-1">Edit Nomor Telepon Perguruan Tinggi</h4>
  93. </div>
  94. <div className="modalLoginPT-b">
  95. <label className=" font-weight-bold h6">
  96. Nomor Telepon :
  97. </label>
  98. <div className="border-2">
  99. <PhoneInput
  100. country={'id'}
  101. value={this.state.phone || this.state.newphone}
  102. onChange={newphone => this.setState({ newphone })} />
  103. </div>
  104. </div>
  105. <div className="">
  106. <Button className="btn-v2 float-left mr-2 ml-4" style={{ width: "40%" }} color onClick={this.otpClose}>
  107. <span className=" font-color-black">
  108. Batal
  109. </span>
  110. </Button>
  111. <Button className="btn-login float-right mr-4" style={{ width: "40%" }} color onClick={this.handleSubmitTelepon}>
  112. {this.state.loadingProses ?
  113. (
  114. <div class="d-flex justify-content-center">
  115. <span
  116. class="spinner-border spinner-border-sm text-white"
  117. role="status"
  118. ></span>
  119. <span className="font-color-white">
  120. &nbsp; Diproses...
  121. </span>
  122. </div>
  123. ) : (
  124. <span className="font-color-white">
  125. Simpan
  126. </span>
  127. )}
  128. </Button>
  129. </div>
  130. </ModalBody>
  131. </Modal>
  132. <Modal isOpen={this.state.modalOTP} style={{ width: '400px' }} >
  133. <ModalBody>
  134. <div className="modalLoginPT-a">
  135. <img
  136. className="icon-triangle-onModalPT mt-auto mb-auto"
  137. src="/static/img/Frame_10.png"
  138. ></img>
  139. <h3 className=" font-color-black">Masukan Kode OTP</h3>
  140. </div>
  141. {this.state.sendingOTP === true &&
  142. <div>
  143. <Alert color="warning">
  144. Berhasil Kirim Kode OTP
  145. </Alert>
  146. </div>
  147. }
  148. {/* <div className="modalLoginPT-b"> */}
  149. <div className=" mt-5 mb-5">
  150. <OtpInput
  151. invalid={this.state.error}
  152. value={this.state.otp}
  153. onChange={(otp) => { this.setState({ otp }) }}
  154. numInputs={4}
  155. renderSeparator={<span className=" font-color-black font-weight-bold mr-2 ml-2">-</span>}
  156. renderInput={(props) => <input {...props} style={{ width: "50px", height: "50px", textAlign: "center", marginLeft: "auto", marginRight: "auto", borderRadius: "7px", fontSize: "30px" }} />}
  157. />
  158. <p className=" mt-3">
  159. *Kode OTP terkirim ke nomor WA {this.state.newphone || this.state.phone}
  160. </p>
  161. <p className=" mt-3 ">
  162. Jika Anda belum menerima kode OTP, <span className=" btn-link" onClick={this.handleOTPagain}>kirimkan ulang kode OTP</span>
  163. </p>
  164. <FormFeedback invalid={this.state.error}>
  165. Kode verifikasi harus diisi
  166. </FormFeedback>
  167. </div>
  168. <div>
  169. <Button className="btn-v2 float-left mr-2 ml-4" style={{ width: "40%" }} color onClick={this.otpClose}>
  170. <span className=" font-color-black">
  171. Batal
  172. </span>
  173. </Button>
  174. <Button className="btn-login float-right mr-4" style={{ width: "40%" }} color onClick={this.handleSubmitOtp}
  175. >
  176. <span className=" font-color-white">
  177. Simpan
  178. </span>
  179. </Button>
  180. </div>
  181. </ModalBody>
  182. </Modal>
  183. <div className="card-body">
  184. <div className="text-center">
  185. <h3 className="mt-0">{data.nama}</h3>
  186. <p>{data.sk_pendirian}</p>
  187. <p>Pembina: {data.pembina.nama}</p>
  188. <p>{`${data.alamat.jalan} ${data.alamat.rt ? `rt ${data.alamat.rt}` : ""} ${data.alamat.rw ? `rt ${data.alamat.rw}` : ""}, ${data.alamat.kab_kota.nama}, ${data.propinsi.nama}`}</p>
  189. </div>
  190. <hr />
  191. <ul className="list-unstyled px-4">
  192. <li>
  193. <em className="fa fa-globe fa-fw mr-3"></em>
  194. <a href={`https://${data.website}`}>{data.website}</a>
  195. </li>
  196. <li>
  197. <em className="fa fa-phone fa-fw mr-3"></em>
  198. {data.telepon}
  199. </li>
  200. <li>
  201. <em className="fa fa-at fa-fw mr-3"></em>
  202. <a href={`mailto:${data.email}`}>{data.email}</a>
  203. </li>
  204. </ul>
  205. {this.props.user.role.id === 2022 ?
  206. <div>
  207. <hr />
  208. <label >
  209. Nomor Telepon :
  210. </label>
  211. <button onClick={this.OpenEditNoTelp} className=" float-right bg-transparent border-0 color-3e3a8e">
  212. Edit
  213. </button>
  214. <div >
  215. <div className=" no-hpPT mt-2">
  216. <div className=" inline">
  217. <span style={{ fontSize: "16px" }} className=" font-color-black font-weight-bold">
  218. +62
  219. </span>
  220. <span style={{ width: "10px", position: "" }} >
  221. <img style={{ width: "15px" }} src="/static/img/Down.png"></img>
  222. </span>
  223. <div style={{ fontSize: "14px" }} className=" inline ml-2 font-weight-normal font-color-black font-weight-bold">
  224. {this.state.phone.substring(2, 20)}
  225. </div>
  226. </div>
  227. </div>
  228. </div>
  229. </div>
  230. : ""
  231. }
  232. </div>
  233. </div>
  234. );
  235. }
  236. }
  237. const mapStateToProps = (state) => ({ user: state.user, token: state.token });
  238. export default connect(mapStateToProps)(DetailPT);