DetailPT.js 7.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232
  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 } 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. }
  24. componentDidMount = async () => {
  25. const { token } = this.props;
  26. const kontakPT = await getkontakpt(token);
  27. const oldPhone = kontakPT?.data.map((data) => (data.no_hp)).toString()
  28. if (oldPhone) {
  29. this.setState({ phone: oldPhone })
  30. }
  31. }
  32. OpenEditNoTelp = () => this.setState({
  33. ddselected: !this.state.ddselected
  34. })
  35. handleSubmitTelepon = async () => {
  36. this.setState({ loadingProses: true })
  37. const { token } = this.props
  38. await createotp({ no_hp: this.state.phone }, token)
  39. this.setState({ modalPhone: false, modalOTP: true })
  40. }
  41. otpClose = () => {
  42. this.setState({ modalOTP: false, ddselected: false, loadingProses: false, otp: "" })
  43. // localStorage.setItem("closeverif", "true");
  44. }
  45. handleSubmitOtp = async () => {
  46. const { token } = this.props
  47. const create = await createkontak({ otp: this.state.otp, no_hp: this.state.phone }, token)
  48. if (create.error) {
  49. swal.fire({
  50. title: create.error.message,
  51. icon: "error",
  52. content: create.error.message,
  53. confirmButtonColor: "#3e3a8e",
  54. });
  55. } else {
  56. swal.fire({
  57. title: "Data berhasil dikirim",
  58. icon: "success",
  59. confirmButtonColor: "#3e3a8e",
  60. });
  61. this.setState({ ddselected: false, modalOTP: false, loadingProses: false, otp: "" })
  62. }
  63. }
  64. render() {
  65. const { data } = this.props;
  66. return (
  67. <div className="card card-default">
  68. <Modal isOpen={this.state.ddselected} style={{ width: '400px' }}>
  69. <ModalBody>
  70. <div className="modalLoginPT-a">
  71. <img
  72. className="icon-triangle-onModalPT mt-0"
  73. src="/static/img/Frame_10.png"
  74. ></img>
  75. <h4 className=" font-color-black mt-1">Edit Nomor Telepon Perguruan Tinggi</h4>
  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.kontakPT?.data.map((data) => (data.no_hp)) || this.state.phone}
  85. onChange={phone => this.setState({ phone })} />
  86. </div>
  87. </div>
  88. <div className="">
  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. {this.state.loadingProses ?
  96. (
  97. <div class="d-flex justify-content-center">
  98. <span
  99. class="spinner-border spinner-border-sm text-white"
  100. role="status"
  101. ></span>
  102. <span className="font-color-white">
  103. &nbsp; Diproses...
  104. </span>
  105. </div>
  106. ) : (
  107. <span className="font-color-white">
  108. Simpan
  109. </span>
  110. )}
  111. </Button>
  112. </div>
  113. </ModalBody>
  114. </Modal>
  115. <Modal isOpen={this.state.modalOTP} style={{ width: '400px' }} >
  116. <ModalBody>
  117. <div className="modalLoginPT-a">
  118. <img
  119. className="icon-triangle-onModalPT mt-auto mb-auto"
  120. src="/static/img/Frame_10.png"
  121. ></img>
  122. <h3 className=" font-color-black">Masukan Kode OTP</h3>
  123. </div>
  124. {/* <div className="modalLoginPT-b"> */}
  125. <div className=" mt-5 mb-5">
  126. <OtpInput
  127. invalid={this.state.error}
  128. value={this.state.otp}
  129. onChange={(otp) => { this.setState({ otp }) }}
  130. numInputs={4}
  131. renderSeparator={<span className=" font-color-black font-weight-bold mr-2 ml-2">-</span>}
  132. renderInput={(props) => <input {...props} style={{ width: "50px", height: "50px", textAlign: "center", marginLeft: "auto", marginRight: "auto", borderRadius: "7px", fontSize: "30px" }} />}
  133. /> <p className=" mt-3">
  134. *Kode OTP terkirim ke nomor WA {this.state.phone}
  135. </p>
  136. <FormFeedback invalid={this.state.error}>
  137. Kode verifikasi harus diisi
  138. </FormFeedback>
  139. </div>
  140. <div>
  141. <Button className="btn-v2 float-left mr-2 ml-4" style={{ width: "40%" }} color onClick={this.otpClose}>
  142. <span className=" font-color-black">
  143. Batal
  144. </span>
  145. </Button>
  146. <Button className="btn-login float-right mr-4" style={{ width: "40%" }} color onClick={this.handleSubmitOtp}
  147. >
  148. <span className=" font-color-white">
  149. Kirim
  150. </span>
  151. </Button>
  152. </div>
  153. </ModalBody>
  154. </Modal>
  155. <div className="card-body">
  156. <div className="text-center">
  157. <h3 className="mt-0">{data.nama}</h3>
  158. <p>{data.sk_pendirian}</p>
  159. <p>Pembina: {data.pembina.nama}</p>
  160. <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>
  161. </div>
  162. <hr />
  163. <ul className="list-unstyled px-4">
  164. <li>
  165. <em className="fa fa-globe fa-fw mr-3"></em>
  166. <a href={`https://${data.website}`}>{data.website}</a>
  167. </li>
  168. <li>
  169. <em className="fa fa-phone fa-fw mr-3"></em>
  170. {data.telepon}
  171. </li>
  172. <li>
  173. <em className="fa fa-at fa-fw mr-3"></em>
  174. <a href={`mailto:${data.email}`}>{data.email}</a>
  175. </li>
  176. </ul>
  177. {this.props.user.role.id === 2022 ?
  178. <div>
  179. <hr />
  180. <label >
  181. Nomor Telepon :
  182. </label>
  183. <button onClick={this.OpenEditNoTelp} className=" float-right bg-transparent border-0 color-3e3a8e">
  184. Edit
  185. </button>
  186. <div >
  187. <div className=" no-hpPT mt-2">
  188. <div className=" inline">
  189. <span style={{ fontSize: "16px" }} className=" font-color-black font-weight-bold">
  190. +62
  191. </span>
  192. <span style={{ width: "10px", position: "" }} >
  193. <img style={{ width: "15px" }} src="/static/img/Down.png"></img>
  194. </span>
  195. <div style={{ fontSize: "14px" }} className=" inline ml-2 font-weight-normal font-color-black font-weight-bold">
  196. {this.state.phone.substring(2, 20)}
  197. </div>
  198. </div>
  199. </div>
  200. </div>
  201. </div>
  202. : ""
  203. }
  204. </div>
  205. </div>
  206. );
  207. }
  208. }
  209. const mapStateToProps = (state) => ({ user: state.user, token: state.token });
  210. export default connect(mapStateToProps)(DetailPT);