|
@@ -4,6 +4,11 @@ import { Container, Row, Col, Card, CardBody, CardFooter, CardHeader, Input, But
|
|
|
import FormValidator from "@/components/Forms/Validator.js";
|
|
import FormValidator from "@/components/Forms/Validator.js";
|
|
|
import { ptPublic } from "@/actions/PT";
|
|
import { ptPublic } from "@/actions/PT";
|
|
|
import AsyncSelect from "react-select/async";
|
|
import AsyncSelect from "react-select/async";
|
|
|
|
|
+import { loginToPt } from "../../../actions/auth";
|
|
|
|
|
+import { connect } from "react-redux";
|
|
|
|
|
+import { ToastContainer, toast } from "react-toastify";
|
|
|
|
|
+
|
|
|
|
|
+
|
|
|
|
|
|
|
|
|
|
|
|
|
const loadOptions = (inputValue, callback) => {
|
|
const loadOptions = (inputValue, callback) => {
|
|
@@ -22,11 +27,9 @@ class Verifikasi extends React.Component {
|
|
|
super(props);
|
|
super(props);
|
|
|
this.state = {
|
|
this.state = {
|
|
|
formLogin: {
|
|
formLogin: {
|
|
|
-
|
|
|
|
|
- password: "",
|
|
|
|
|
- // pt_id: ""
|
|
|
|
|
|
|
+ password: ""
|
|
|
},
|
|
},
|
|
|
-
|
|
|
|
|
|
|
+ loading: false,
|
|
|
inputValue: "",
|
|
inputValue: "",
|
|
|
pt_id: ""
|
|
pt_id: ""
|
|
|
|
|
|
|
@@ -61,16 +64,32 @@ class Verifikasi extends React.Component {
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
- // handleInputChange = (newValue) => {
|
|
|
|
|
- // const inputValue = newValue.replace();
|
|
|
|
|
- // this.setState({ inputValue });
|
|
|
|
|
- // return inputValue;
|
|
|
|
|
- // };
|
|
|
|
|
|
|
+
|
|
|
handleChangeSelectPerguruanTinggi = (selected_PT) => {
|
|
handleChangeSelectPerguruanTinggi = (selected_PT) => {
|
|
|
this.setState({ pt_id: selected_PT.value });
|
|
this.setState({ pt_id: selected_PT.value });
|
|
|
};
|
|
};
|
|
|
- onSubmit = async (e) => {
|
|
|
|
|
- console.log("di submitt")
|
|
|
|
|
|
|
+ onSubmit = async () => {
|
|
|
|
|
+
|
|
|
|
|
+ this.setState({ loading: true });
|
|
|
|
|
+ const { password } = this.state.formLogin;
|
|
|
|
|
+ const { pt_id } = this.state
|
|
|
|
|
+ const auth = await toast.promise(loginToPt(pt_id, password), {
|
|
|
|
|
+ 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 });
|
|
|
|
|
+
|
|
|
}
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
@@ -126,7 +145,18 @@ class Verifikasi extends React.Component {
|
|
|
style={{ borderRadius: "7px" }}
|
|
style={{ borderRadius: "7px" }}
|
|
|
onClick={this.onSubmit}
|
|
onClick={this.onSubmit}
|
|
|
>
|
|
>
|
|
|
- <span className="font-color-white">Login</span>
|
|
|
|
|
|
|
+ <span className="font-color-white">
|
|
|
|
|
+ {this.state.loading ? (
|
|
|
|
|
+ <div class="d-flex justify-content-center">
|
|
|
|
|
+ <div
|
|
|
|
|
+ class="spinner-border spinner-border-sm"
|
|
|
|
|
+ role="status"
|
|
|
|
|
+ ></div>
|
|
|
|
|
+ </div>
|
|
|
|
|
+ ) : (
|
|
|
|
|
+ "Login"
|
|
|
|
|
+ )}
|
|
|
|
|
+ </span>
|
|
|
</Button>
|
|
</Button>
|
|
|
</form>
|
|
</form>
|
|
|
</CardBody>
|
|
</CardBody>
|
|
@@ -140,5 +170,10 @@ class Verifikasi extends React.Component {
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
-
|
|
|
|
|
-export default Verifikasi
|
|
|
|
|
|
|
+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);
|