SidebarUserBlock.js 8.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260
  1. import React, { Component } from "react";
  2. import PropTypes from "prop-types";
  3. import { Collapse, Dropdown, DropdownMenu, DropdownToggle, DropdownItem, UncontrolledDropdown, ModalHeader, ModalBody, ModalFooter, Modal, FormFeedback, Button } from "reactstrap";
  4. import classNames from 'classnames';
  5. import PhoneInput from 'react-phone-input-2'
  6. import 'react-phone-input-2/lib/style.css'
  7. import OtpInput from 'react-otp-input';
  8. import { connect } from "react-redux";
  9. import { createotp, getkontakpt, createkontak } from "../../actions/auth";
  10. import swal from "sweetalert2";
  11. class SidebarUserBlock extends Component {
  12. state = {
  13. showUserBlock: true,
  14. user: {},
  15. role: {},
  16. ddOpen: false,
  17. ddselected: false,
  18. phone: "",
  19. otp: "",
  20. modalOTP: false,
  21. modalPhone: false
  22. };
  23. componentDidMount = async () => {
  24. const { token } = this.props;
  25. const user = this.props.user;
  26. const kontakPT = await getkontakpt(token);
  27. const oldPhone = kontakPT?.data.map((data) => (data.no_hp)).toString()
  28. this.setState({ user, role: user.role });
  29. if (oldPhone) {
  30. this.setState({ phone: oldPhone })
  31. }
  32. }
  33. componentDidUpdate(oldProps) {
  34. if (oldProps.showUserBlock !== this.props.showUserBlock) {
  35. this.setState({ showUserBlock: this.props.showUserBlock });
  36. }
  37. }
  38. toggleDropDown = () => this.setState({
  39. ddOpen: !this.state.ddOpen
  40. })
  41. toggleDropItem = () =>
  42. this.setState({
  43. ddselected: !this.state.ddselected
  44. })
  45. handleSubmitTelepon = async () => {
  46. this.setState({ loadingProses: true })
  47. const { token } = this.props
  48. await createotp({ no_hp: this.state.phone }, token)
  49. this.setState({ modalPhone: false, modalOTP: true })
  50. }
  51. otpClose = () => {
  52. this.setState({ modalOTP: false, ddselected: false })
  53. // localStorage.setItem("closeverif", "true");
  54. }
  55. handleSubmitOtp = async () => {
  56. const { token } = this.props
  57. const create = await createkontak({ otp: this.state.otp, no_hp: this.state.phone }, token)
  58. if (create.error) {
  59. swal.fire({
  60. title: create.error.message,
  61. icon: "error",
  62. content: create.error.message,
  63. confirmButtonColor: "#3e3a8e",
  64. });
  65. } else {
  66. swal.fire({
  67. title: "Data berhasil dikirim",
  68. icon: "success",
  69. confirmButtonColor: "#3e3a8e",
  70. });
  71. this.setState({ ddselected: false, modalOTP: false })
  72. }
  73. }
  74. render() {
  75. const { user, role } = this.state;
  76. return (
  77. <Collapse id="user-block" isOpen={this.state.showUserBlock}>
  78. <Modal isOpen={this.state.ddselected} style={{ width: '400px' }}>
  79. <ModalBody>
  80. <div className="modalLoginPT-a">
  81. <img
  82. className="icon-triangle-onModalPT mt-0"
  83. src="/static/img/Frame_10.png"
  84. ></img>
  85. <h4 className=" font-color-black mt-1">Edit Nomor Telepon Perguruan Tinggi</h4>
  86. </div>
  87. <div className="modalLoginPT-b">
  88. <label className=" font-weight-bold h6">
  89. Nomor Telepon :
  90. </label>
  91. <div className="border-2">
  92. <PhoneInput
  93. country={'id'}
  94. value={this.state.kontakPT?.data.map((data) => (data.no_hp)) || this.state.phone}
  95. onChange={phone => this.setState({ phone })} />
  96. </div>
  97. </div>
  98. <div className="">
  99. <Button className="btn-v2 float-left mr-2 ml-4" style={{ width: "40%" }} color onClick={this.otpClose}>
  100. <span className=" font-color-black">
  101. Batal
  102. </span>
  103. </Button>
  104. <Button className="btn-login float-right mr-4" style={{ width: "40%" }} color onClick={this.handleSubmitTelepon}>
  105. {this.state.loadingProses ?
  106. (
  107. <div class="d-flex justify-content-center">
  108. <span
  109. class="spinner-border spinner-border-sm text-white"
  110. role="status"
  111. ></span>
  112. <span className="font-color-white">
  113. &nbsp; Diproses...
  114. </span>
  115. </div>
  116. ) : (
  117. <span className="font-color-white">
  118. Simpan
  119. </span>
  120. )}
  121. </Button>
  122. </div>
  123. </ModalBody>
  124. </Modal>
  125. <Modal isOpen={this.state.modalOTP} style={{ width: '400px' }} >
  126. <ModalBody>
  127. <div className="modalLoginPT-a">
  128. <img
  129. className="icon-triangle-onModalPT mt-auto mb-auto"
  130. src="/static/img/Frame_10.png"
  131. ></img>
  132. <h3 className=" font-color-black">Masukan Kode OTP</h3>
  133. </div>
  134. {/* <div className="modalLoginPT-b"> */}
  135. <div className=" mt-5 mb-5">
  136. <OtpInput
  137. invalid={this.state.error}
  138. value={this.state.otp}
  139. onChange={(otp) => { this.setState({ otp }) }}
  140. numInputs={4}
  141. renderSeparator={<span className=" font-color-black font-weight-bold mr-2 ml-2">-</span>}
  142. renderInput={(props) => <input {...props} style={{ width: "50px", height: "50px", textAlign: "center", marginLeft: "auto", marginRight: "auto", borderRadius: "7px", fontSize: "30px" }} />}
  143. /> <p className=" mt-3">
  144. *Kode OTP terkirim ke nomor WA {this.state.phone}
  145. </p>
  146. <FormFeedback invalid={this.state.error}>
  147. Kode verifikasi harus diisi
  148. </FormFeedback>
  149. </div>
  150. <div>
  151. <Button className="btn-v2 float-left mr-2 ml-4" style={{ width: "40%" }} color onClick={this.otpClose}>
  152. <span className=" font-color-black">
  153. Batal
  154. </span>
  155. </Button>
  156. <Button className="btn-login float-right mr-4" style={{ width: "40%" }} color onClick={this.handleSubmitOtp}
  157. >
  158. <span className=" font-color-white">
  159. Kirim
  160. </span>
  161. </Button>
  162. </div>
  163. </ModalBody>
  164. </Modal>
  165. <div>
  166. {role.id === 2022 ? (
  167. <div className="item user-block">
  168. {/* User picture */}
  169. <div className="user-block-picture">
  170. <div className="user-block-status">
  171. <img className="rounded-circle" src={role.id === 2022 ? "/static/img/univ-avatar.png" : "/static/img/logo-single.png"} alt="Avatar" width="60" height="60" />
  172. <div className="circle bg-success circle-lg"></div>
  173. </div>
  174. </div>
  175. {/* Name and Job */}
  176. <div className="user-block-info">
  177. <span className="user-block-name">
  178. <div className="col ">
  179. <div className=" d-inline-flex justify-content-center">
  180. <span className="font-color-black font-weight-bold text-center">{user.nama}</span>
  181. </div>
  182. {/* <div className=" d-inline-flex ml-1">
  183. <Dropdown isOpen={this.state.ddOpen} toggle={this.toggleDropDown}>
  184. <DropdownToggle data-toggle="dropdown" tag="span">
  185. <span style={{ width: "20px" }} >
  186. <img className="" src="/static/img/Down.png"></img>
  187. </span>
  188. </DropdownToggle>
  189. <DropdownMenu positionFixed={true} >
  190. <DropdownItem onClick={this.toggleDropItem}>
  191. <span className=" font-color-black font-weight-bold">
  192. Edit Nomor Telepon
  193. </span>
  194. </DropdownItem>
  195. </DropdownMenu>
  196. </Dropdown>
  197. </div> */}
  198. </div>
  199. </span>
  200. <span className="user-block-role">{role.nama}</span>
  201. </div>
  202. </div>
  203. ) :
  204. (
  205. <div className="item user-block">
  206. {/* User picture */}
  207. <div className="user-block-picture">
  208. <div className="user-block-status">
  209. <img className="rounded-circle" src={role.id === 2022 ? "/static/img/univ-avatar.png" : "/static/img/logo-single.png"} alt="Avatar" width="60" height="60" />
  210. <div className="circle bg-success circle-lg"></div>
  211. </div>
  212. </div>
  213. {/* Name and Job */}
  214. <div className="user-block-info">
  215. <span className="user-block-name">
  216. <div className="col ">
  217. <div className=" d-inline-flex justify-content-center">
  218. <h6 className="font-color-black font-weight-bold text-center">{user.nama}</h6>
  219. </div>
  220. </div>
  221. </span>
  222. <span className="user-block-role">{role.nama}</span>
  223. </div>
  224. </div>
  225. )}
  226. </div>
  227. </Collapse >
  228. );
  229. }
  230. }
  231. SidebarUserBlock.propTypes = {
  232. showUserBlock: PropTypes.bool,
  233. };
  234. const mapStateToProps = (state) => ({ showUserBlock: state.settings.showUserBlock, user: state.user });
  235. export default connect(mapStateToProps)(SidebarUserBlock);