Kaynağa Gözat

fix notelp pt

andi 1 yıl önce
ebeveyn
işleme
b554766702

+ 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;
 	}
 };

+ 1 - 0
components/Layout/Header.js

@@ -63,6 +63,7 @@ class Header extends Component {
 		await logout(_csrf);
 		this.props.tokenNull();
 		this.props.userNull();
+		localStorage.removeItem("closeverif");
 
 		location.href='/app'
 		// Router.push({ pathname: "/app" });

+ 11 - 11
components/Main/DetailLaporan.js

@@ -17,20 +17,20 @@ function DetailLaporan({ data, noTitle = false, noStatus = false, role }) {
 	};
 	return (
 		<>
-			{(!data.user.isPrivate || user?.role.id === 2020) && (
+			{(!data.user?.isPrivate || user?.role?.id === 2020) && (
 				<>
 					{noTitle ? (
 						""
 					) : (
 						<div className="header-1">
-							<h2 className="card-title-1">Identitas Pelapor - {data.user.isPublic ? "Umum" : "Internal"}</h2>
+							<h2 className="card-title-1">Identitas Pelapor - {data.user?.isPublic ? "Umum" : "Internal"}</h2>
 						</div>
 					)}
-					{data.user.nama && (
+					{data.user?.nama && (
 						<FormGroup row>
 							<Col md="4">Nama Pelapor:</Col>
 							<Col md="8">
-								<strong>{data.user.nama}</strong>
+								<strong>{data.user?.nama}</strong>
 							</Col>
 						</FormGroup>
 					)}
@@ -38,22 +38,22 @@ function DetailLaporan({ data, noTitle = false, noStatus = false, role }) {
 						<Col md="4">Nomor yang dapat dihubungi:</Col>
 						<Col md="8">
 							<strong>
-								{data.user.no_hp} {data.user.verified && "(Terverifikasi)"}
+								{data.user?.no_hp} {data.user?.verified && "(Terverifikasi)"}
 							</strong>
 						</Col>
 					</FormGroup>
-					{data.user.email && (
+					{data.user?.email && (
 						<FormGroup row>
 							<Col md="4">Email:</Col>
 							<Col md="8">
-								<strong>{data.user.email}</strong>
+								<strong>{data.user?.email}</strong>
 							</Col>
 						</FormGroup>
 					)}
 
-					{data.user.isPublic && (
+					{data.user?.isPublic && (
 						<>
-							{data.user.alamat && (
+							{data.user?.alamat && (
 								<FormGroup row>
 									<Col md="4">Alamat:</Col>
 									<Col md="8">
@@ -65,13 +65,13 @@ function DetailLaporan({ data, noTitle = false, noStatus = false, role }) {
 								<FormGroup row>
 									<Col md="4">Foto Kartu Identitas:</Col>
 									<Col md="8">
-										<img src={data.user.foto.path} height={200} alt="Foto Identitas" />
+										<img src={data.user?.foto.path} height={200} alt="Foto Identitas" />
 									</Col>
 								</FormGroup>
 							)}
 						</>
 					)}
-					{data.user.isPrivate && (
+					{data.user?.isPrivate && (
 						<FormGroup row>
 							<Col md="4">Dirahasiakan</Col>
 							<Col md="8">

+ 4 - 5
components/Riwayat/TableRiwayat.js

@@ -27,10 +27,10 @@ class TableRiwayat extends Component {
         this.setState({ dataRiwayat });
     }
     onFilter = async () => {
-        // const date1 = moment(this.state.fromDate).format("YYYY-MM-DD")
-        // const date2 = moment(this.state.toDate).format("YYYY-MM-DD")
-        // const dataRiwayat = await getLog2(this.props.token, { fromDate: date1, toDate: date2 })
-        // this.setState({ dataRiwayat });
+        const date1 = moment(this.state.fromDate).format("YYYY-MM-DD")
+        const date2 = moment(this.state.toDate).format("YYYY-MM-DD")
+        const dataRiwayat = await getLog2(this.props.token, { fromDate: date1, toDate: date2 })
+        this.setState({ dataRiwayat });
         this.setState({ updateTable: true });
         setTimeout(() => {
             this.setState({ updateTable: false });
@@ -50,7 +50,6 @@ class TableRiwayat extends Component {
 
 
     render() {
-        console.log(this.state.dataRiwayat)
         return (
             <div className="card b ">
 

+ 6 - 3
pages/app/pemantauan/timeline.js

@@ -66,7 +66,7 @@ class Pemantauan extends Component {
 								<div className="card-body">
 									{pelaporan.data?.length ? (
 										<Datatable options={{ responsive: false }}>
-											<table className="table w-100">
+											<table className="table w-100" data-order='[[0, "desc"]]'>
 												<thead>
 													<tr>
 														<th>Tanggal</th>
@@ -80,7 +80,10 @@ class Pemantauan extends Component {
 													{pelaporan.data.map((data) => {
 														return (
 															<tr key={data._id}>
-																<td>{moment(data.createdAt).format("DD/MM/YYYY")}</td>
+
+																<td>
+																	<p style={{ display: "none" }}>{data.createdAt}</p>
+																	{moment(data.createdAt).format("DD/MM/YYYY")}</td>
 																<td>{data.no_laporan}</td>
 
 																<td className="text-nowrap">
@@ -94,7 +97,7 @@ class Pemantauan extends Component {
 																</td>
 
 																<td>
-																	{data.user.isPrivate ? "" : data.user.nama} - {data.role_asal}
+																	{data.user?.isPrivate ? "" : data.user?.nama} - {data.role_asal}
 																</td>
 
 																<td>

+ 48 - 21
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 {
@@ -25,7 +27,9 @@ class Pemantauan extends Component {
 			otpClose: false,
 			modalOTP: false,
 			otp: "",
-			phone: ""
+			phone: "",
+			loadingProses: false,
+			// closeVerifikasi:false,
 		};
 	}
 
@@ -35,42 +39,52 @@ class Pemantauan extends Component {
 		const pt = await getPT(token);
 		const kontakPT = await getkontakpt(token);
 		this.setState({ log, pt, kontakPT });
-		if (kontakPT=== undefined) {
-			this.setState({modalPhone:true})
+		const closeverif = localStorage.getItem(("closeverif"))
+		if (kontakPT === undefined && closeverif === null) {
+			this.setState({ modalPhone: true })
 		}
 
 	};
 	otpClose = () => {
-		// return location.href = '/pt/pemantauan';
+		// return location.href = '/pt/pemantauan';71
 		this.setState({ modalOTP: false, modalPhone: false })
+		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
@@ -100,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>