Browse Source

fix no hp pt

andi 1 year ago
parent
commit
c0ef7ee370
2 changed files with 45 additions and 21 deletions
  1. 2 1
      actions/auth.js
  2. 43 20
      pages/pt/pemantauan.js

+ 2 - 1
actions/auth.js

@@ -82,6 +82,7 @@ export const createkontak = async (data, token) => {
 		const response = await axiosAPI.post(`/kontak`, data, { headers: { Authorization: token } });
 		return response.data;
 	} catch (error) {
-		if (error.response) return error.response.data;
+		return { error: error.response.data };
+		// if (error.response) return error.response.data;
 	}
 };

+ 43 - 20
pages/pt/pemantauan.js

@@ -13,6 +13,8 @@ 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";
+import swal from "sweetalert2";
+
 
 
 class Pemantauan extends Component {
@@ -26,6 +28,7 @@ class Pemantauan extends Component {
 			modalOTP: false,
 			otp: "",
 			phone: "",
+			loadingProses: false,
 			// closeVerifikasi:false,
 		};
 	}
@@ -37,8 +40,8 @@ class Pemantauan extends Component {
 		const kontakPT = await getkontakpt(token);
 		this.setState({ log, pt, kontakPT });
 		const closeverif = localStorage.getItem(("closeverif"))
-		if (kontakPT=== undefined && closeverif === null) {
-			this.setState({modalPhone:true})
+		if (kontakPT === undefined && closeverif === null) {
+			this.setState({ modalPhone: true })
 		}
 
 	};
@@ -48,33 +51,40 @@ class Pemantauan extends Component {
 		localStorage.setItem("closeverif", "true");
 	}
 	handleSubmitTelepon = async () => {
+		this.setState({ loadingProses: true })
 		const { token } = this.props
-		const create = createotp({ no_hp: this.state.phone }, token)
-		await toast.promise(create, {
-			pending: "Loading...",
-			// success: "Berhasil ",
-			error: "Error",
-		},)
+		await createotp({ no_hp: this.state.phone }, token)
+
 
 		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 })
+		const create = await createkontak({ otp: this.state.otp, no_hp: this.state.phone }, token)
+		if (create.error) {
+			swal.fire({
+			  title: create.error.message,
+			  icon: "error",
+			  content: create.error.message,
+			  confirmButtonColor: "#3e3a8e",
+			});
+		  } else {
+			swal.fire({
+			  title: "Data berhasil dikirim",
+			  icon: "success",
+			  confirmButtonColor: "#3e3a8e",
+			});
+				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' }} >
+					<Modal isOpen={this.state.kontakPT === undefined && this.state.modalPhone} style={{ width: '400px' }} >
 						<ModalBody>
 							<div className="modalLoginPT-a">
 								<img
@@ -104,9 +114,22 @@ class Pemantauan extends Component {
 									</span>
 								</Button>
 								<Button className="btn-login float-right mr-4" style={{ width: "40%" }} color onClick={this.handleSubmitTelepon}>
-									<span className=" font-color-white">
-										Kirim
-									</span>
+									{this.state.loadingProses ?
+										(
+											<div class="d-flex justify-content-center">
+												<span
+													class="spinner-border spinner-border-sm text-white"
+													role="status"
+												></span>
+												<span className="font-color-white">
+													&nbsp; Diproses...
+												</span>
+											</div>
+										) : (
+											<span className="font-color-white">
+												Kirim
+											</span>
+										)}
 								</Button>
 							</div>
 						</ModalBody>