| 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179 |
- import React, { Component } from "react";
- import ContentWrapper from "@/components/Layout/ContentWrapper";
- import Header from "@/components/Main/Header";
- import DetailPT from "@/components/Main/DetailPT";
- import { getLogPT } from "@/actions/log";
- import { getPT } from "@/actions/PT";
- import { Row, Col, ModalHeader, ModalBody, ModalFooter, Modal, FormFeedback, Button } from "reactstrap";
- import Timeline from "@/components/Main/Timeline";
- import { connect } from "react-redux";
- import Loader from "@/components/Common/Loader";
- import { createotp, getkontakpt, createkontak } from "../../actions/auth";
- import PhoneInput from 'react-phone-input-2'
- import 'react-phone-input-2/lib/style.css'
- import OtpInput from 'react-otp-input';
- import { ToastContainer, toast } from "react-toastify";
- class Pemantauan extends Component {
- constructor(props) {
- super(props);
- this.state = {
- log: [],
- pt: {},
- modalPhone: false,
- otpClose: false,
- modalOTP: false,
- otp: "",
- phone: ""
- };
- }
- componentDidMount = async () => {
- const { token } = this.props;
- const log = await getLogPT(token);
- const pt = await getPT(token);
- const kontakPT = await getkontakpt(token);
- this.setState({ log, pt, kontakPT });
- if (kontakPT=== undefined) {
- this.setState({modalPhone:true})
- }
- };
- otpClose = () => {
- // return location.href = '/pt/pemantauan';
- this.setState({ modalOTP: false, modalPhone: false })
- }
- handleSubmitTelepon = async () => {
- const { token } = this.props
- const create = createotp({ no_hp: this.state.phone }, token)
- await toast.promise(create, {
- pending: "Loading...",
- // success: "Berhasil ",
- error: "Error",
- },)
- this.setState({ modalPhone: false, modalOTP: true })
- }
- handleSubmitOtp = async () => {
- const { token } = this.props
- const create = createkontak({ otp: this.state.otp, no_hp: this.state.phone }, token)
- await toast.promise(create, {
- pending: "Loading...",
- success: "Success",
- error: "Error",
- },)
- this.setState({ modalPhone: false, modalOTP: false })
- }
- render() {
- const { log, pt } = this.state;
- return (
- <ContentWrapper unwrap>
- {this.state.kontakPT === undefined &&
- <Modal isOpen={ this.state.kontakPT === undefined && this.state.modalPhone} style={{ width: '400px' }} >
- <ModalBody>
- <div className="modalLoginPT-a">
- <img
- className="icon-triangle-onModalPT"
- src="/static/img/Frame_10.png"
- ></img>
- <h3 className=" font-color-black">Konfirmasi Nomor Telepon Perguruan Tinggi</h3>
- </div>
- <div className="modalLoginPT-b">
- <label className=" font-weight-bold h6">
- Nomor Telepon :
- </label>
- <div className="border-2">
- <PhoneInput
- country={'id'}
- value={this.state.phone}
- onChange={phone => this.setState({ phone })} />
- </div>
- </div>
- <div>
- <Button className="btn-v2 float-left mr-2 ml-4" style={{ width: "40%" }} color onClick={this.otpClose}>
- <span className=" font-color-black">
- Batal
- </span>
- </Button>
- <Button className="btn-login float-right mr-4" style={{ width: "40%" }} color onClick={this.handleSubmitTelepon}>
- <span className=" font-color-white">
- Kirim
- </span>
- </Button>
- </div>
- </ModalBody>
- </Modal>
- }
- <Modal isOpen={this.state.modalOTP} style={{ width: '400px' }} >
- <ModalBody>
- <div className="modalLoginPT-a">
- <img
- className="icon-triangle-onModalPT mt-auto mb-auto"
- src="/static/img/Frame_10.png"
- ></img>
- <h3 className=" font-color-black">Masukan Kode OTP</h3>
- </div>
- {/* <div className="modalLoginPT-b"> */}
- <div className=" mt-5 mb-5">
- <OtpInput
- invalid={this.state.error}
- value={this.state.otp}
- onChange={(otp) => { this.setState({ otp }) }}
- numInputs={4}
- renderSeparator={<span className=" font-color-black font-weight-bold mr-2 ml-2">-</span>}
- renderInput={(props) => <input {...props} style={{ width: "50px", height: "50px", textAlign: "center", marginLeft: "auto", marginRight: "auto", borderRadius: "7px", fontSize: "30px" }} />}
- /> <p className=" mt-3">
- *Kode OTP terkirim ke nomor WA {this.state.phone}
- </p>
- <FormFeedback invalid={this.state.error}>
- Kode verifikasi harus diisi
- </FormFeedback>
- </div>
- <div>
- <Button className="btn-v2 float-left mr-2 ml-4" style={{ width: "40%" }} color onClick={this.otpClose}>
- <span className=" font-color-black">
- Batal
- </span>
- </Button>
- <Button className="btn-login float-right mr-4" style={{ width: "40%" }} color onClick={this.handleSubmitOtp}
- >
- <span className=" font-color-white">
- Kirim
- </span>
- </Button>
- </div>
- </ModalBody>
- </Modal>
- {pt?.data ? <Header data={pt.data} /> : <Loader />}
- <div className="p-3">
- <Row>
- {log.data ? (
- <Col xl="9">
- <Timeline data={log.data} />
- </Col>
- ) : (
- <Loader />
- )}
- <Col xl="3">{pt.data && <DetailPT data={pt.data} />}</Col>
- </Row>
- </div>
- </ContentWrapper>
- );
- }
- }
- const mapStateToProps = (state) => ({ user: state.user, token: state.token });
- export default connect(mapStateToProps)(Pemantauan);
|