import React from "react"; import ContentWrapper from '@/components/Layout/ContentWrapper'; import { Container, Row, Col, Card, CardBody, CardFooter, CardHeader, Input, Button } from 'reactstrap'; import FormValidator from "@/components/Forms/Validator.js"; import { ptPublic } from "@/actions/PT"; import AsyncSelect from "react-select/async"; import { loginToPt } from "../../../actions/auth"; import { connect } from "react-redux"; import { ToastContainer, toast } from "react-toastify"; import { getCsrf } from "../../../actions/security"; import Swal from "sweetalert2"; const loadOptions = (inputValue, callback) => { setTimeout(async () => { const pt = await ptPublic({ search: inputValue }); const data = pt.data.map((e) => ({ value: e.id, label: e.nama, className: "State-ACT", })); callback(data); }, 1000); }; class Verifikasi extends React.Component { constructor(props) { super(props); this.state = { formLogin: { password: "" }, loading: false, inputValue: "", pt_id: "" }; } validateOnChange = (event) => { const input = event.target; const form = input.form; const value = input.type === "checkbox" ? input.checked : input.value; const result = FormValidator.validate(input); this.setState({ [form.name]: { ...this.state[form.name], [input.name]: value, errors: { ...this.state[form.name].errors, [input.name]: result, }, }, }); }; hasError = (formName, inputName, method) => { return ( this.state[formName] && this.state[formName].errors && this.state[formName].errors[inputName] && this.state[formName].errors[inputName][method] ); }; handleChangeSelectPerguruanTinggi = (selected_PT) => { this.setState({ pt_id: selected_PT.value }); }; onSubmit = async () => { if (this.props.user.role.id === 2024) { Swal.fire({ icon: 'error', title: 'Oops...', html: 'Maaf anda tidak memiliki akses untuk menyelesaikan

proses ini.

', confirmButtonColor: "#3e3a8e", confirmButtonText: 'Oke' }) } else { const getToken = await getCsrf(); const _csrf = getToken.token; this.setState({ loading: true }); const { password } = this.state.formLogin; const { pt_id } = this.state const auth = await toast.promise(loginToPt(pt_id, password, _csrf), { pending: "Loading", success: "Success", error: "Akun tidak ada", }); // const auth = await loginToPt(pt_id, password); this.props.setToken(auth.data.token); this.props.setUser(auth.data.user); if (auth.data.user.role.id === 2022) { location.href = "/pt/pemantauan" return; } else if ([2020, 2021, 2023].includes(auth.data.user.role.id)) { location.href = "/pt/pemantauan" return; } this.setState({ loading: false }); } } render() { return (
Verifikasi
Login sebagai Perguruan Tinggi
Wajib diisi
{ this.handleChangeSelectPerguruanTinggi(e); }} // onInputChange={this.handleInputChange} /> Field is required
) } } const mapStateToProps = (state) => ({ user: state.user }); const mapDispatchToProps = (dispatch) => ({ setUser: (payload) => dispatch({ type: "SET_USER", payload }), setToken: (payload) => dispatch({ type: "SET_TOKEN", payload }), setPT: (payload) => dispatch({ type: "SET_PT", payload }), }); export default connect(mapStateToProps, mapDispatchToProps)(Verifikasi);