andi 3 years ago
parent
commit
8101f349e8
3 changed files with 89 additions and 94 deletions
  1. 23 0
      actions/log.js
  2. 61 94
      pages/app/pelaporan/index.js
  3. 5 0
      utils/osValue.js

+ 23 - 0
actions/log.js

@@ -1,5 +1,7 @@
 import { get } from "../config/request";
 import axios from "@/config/axios";
+import axios2 from "axios";
+import osValue from "../utils/osValue";
 
 export const getLog = async (token, laporan_id) => {
 	try {
@@ -40,3 +42,24 @@ export const getLogPublic = async ({ no_hp, no_laporan }) => {
 		return false;
 	}
 };
+
+export const createLog = async (token, data) => {
+	try {
+		const jsonip = await axios2.get("https://jsonip.com", { mode: "cors" });
+		const res = await axios.post("/log", { os: window.navigator.platform, ipv4: jsonip.data.ip, ...data }, { headers: { Authorization: token } });
+		return res.data;
+	} catch (error) {
+		console.log("error", error);
+		return false;
+	}
+};
+
+export const getLogAdmin = async (token) => {
+	try {
+		const res = await axios.get(`/log`, { headers: { Authorization: token } });
+		return res.data;
+	} catch (error) {
+		console.log("error", error);
+		return false;
+	}
+};

+ 61 - 94
pages/app/pelaporan/index.js

@@ -5,115 +5,82 @@ import { Row, Col, Button } from "reactstrap";
 import { getPelaporan } from "@/actions/pelaporan";
 import { getGraph, getExcel } from "@/actions/graph";
 import CaseProgress from "@/components/Pelaporan/CaseProgress";
-import TableLaporan from "@/components/Pelaporan/TableLaporan";
+import TableLaporan from "@/components/pelaporan/TableLaporan";
 import { connect } from "react-redux";
 import Loader from "@/components/Common/Loader";
-import Router from "next/router";
+import Router from 'next/router'
 
 class Pelaporan extends Component {
-  constructor(props) {
-    super(props);
-    this.state = {
-      pelaporan: {},
-      graph: {},
-      tahun: new Date().getFullYear(),
-      newLaporan: [],
-    };
-  }
+	constructor(props) {
+		super(props);
+		this.state = {
+			pelaporan: {},
+			graph: {},
+			tahun: new Date().getFullYear(),
+			newLaporan: [],
+		};
+	}
 
-  componentDidMount = async () => {
-    const pelaporan = await getPelaporan(this.props.token);
-    const graph = await getGraph(this.props.token, {
-      laporanTahun: true,
-      newLaporan: true,
-      jumlahLaporan: true,
-    });
-    const newLaporan = graph.data.newLaporan;
-    this.setState({ pelaporan, graph, newLaporan });
-  };
+	componentDidMount = async () => {
+		const pelaporan = await getPelaporan(this.props.token);
+		const graph = await getGraph(this.props.token, { laporanTahun: true, newLaporan: true, jumlahLaporan: true });
+		const newLaporan = graph.data.newLaporan;
+		this.setState({ pelaporan, graph, newLaporan });
+	};
 
-  nextButton = async () => {
-    const tahun = this.state.tahun + 1;
-    const graph = await getGraph(this.props.token, {
-      laporanTahun: true,
-      jumlahLaporan: true,
-      tahun,
-    });
-    this.setState({ graph, tahun });
-  };
+	nextButton = async () => {
+		const tahun = this.state.tahun + 1;
+		const graph = await getGraph(this.props.token, { laporanTahun: true, jumlahLaporan: true, tahun });
+		this.setState({ graph, tahun });
+	};
 
-  prevButton = async () => {
-    const tahun = this.state.tahun - 1;
-    const graph = await getGraph(this.props.token, {
-      laporanTahun: true,
-      jumlahLaporan: true,
-      tahun,
-    });
-    this.setState({ graph, tahun });
-  };
+	prevButton = async () => {
+		const tahun = this.state.tahun - 1;
+		const graph = await getGraph(this.props.token, { laporanTahun: true, jumlahLaporan: true, tahun });
+		this.setState({ graph, tahun });
+	};
 
-  shouldComponentUpdate = (prevProps, prevState) => {
-    if (prevState.graph !== this.state.graph) return true;
-  };
+	shouldComponentUpdate = (prevProps, prevState) => {
+		if (prevState.graph !== this.state.graph) return true;
+	};
 
-  excel = () => {
-    const url = getExcel(this.props.token, "Laporan", {
-      tahun: this.state.tahun,
-    });
-    Router.push(url);
-  };
+	excel = () => {
+		const url = getExcel(this.props.token, "Laporan", { tahun: this.state.tahun });
+		Router.push(url);
+	};
 
-  render() {
-    const { pelaporan, graph, newLaporan } = this.state;
+	render() {
+		const { pelaporan, graph, newLaporan } = this.state;
 
-    return (
-      <ContentWrapper>
-        <div className="content-heading">
-          <span className="font-color-white">Pelaporan</span>
-          <div className="ml-auto"></div>
-          <Link href="/app/penjadwalan">
-            <Button className="btn-header" color>
-              <h4 className="font-color-white">Penjadwalan &gt;</h4>
-            </Button>
-          </Link>
-        </div>
-        <Row>
-          <Col lg="4">
-            {graph?.data ? (
-              <CaseProgress
-                data={graph.data}
-                nextButton={this.nextButton}
-                prevButton={this.prevButton}
-                tahun={this.state.tahun}
-                newLaporan={newLaporan}
-                excel={this.excel}
-              />
-            ) : (
-              <Loader />
-            )}
-          </Col>
-          <Col lg="8">
-            <div className="mb-3 d-flex">
-              {/* <div className="margin-left-auto">
+		return (
+			<ContentWrapper>
+				<div className="content-heading">
+					<span className="font-color-white">
+						Pelaporan
+					</span>
+					<div className="ml-auto"></div>
+					<Link href="/app/penjadwalan">
+						<Button className="btn-header" color>
+							<h4 className="font-color-white">Penjadwalan &gt;</h4>
+						</Button>
+					</Link>
+				</div>
+				<Row>
+					<Col lg="4">{graph?.data ? <CaseProgress data={graph.data} nextButton={this.nextButton} prevButton={this.prevButton} tahun={this.state.tahun} newLaporan={newLaporan} excel={this.excel} /> : <Loader />}</Col>
+					<Col lg="8">
+						<div className="mb-3 d-flex">
+							{/* <div className="margin-left-auto">
 								<Link href="/app/pelaporan/search">
 									<Button className="color-3e3a8e" color="purple">Laporan Baru</Button>
 								</Link>
 							</div> */}
-            </div>
-            {pelaporan?.data ? (
-              <TableLaporan
-                listData={pelaporan.data}
-                to="/app/pelaporan/detail"
-                linkName="Detail"
-              />
-            ) : (
-              <Loader />
-            )}
-          </Col>
-        </Row>
-      </ContentWrapper>
-    );
-  }
+						</div>
+						{pelaporan?.data ? <TableLaporan listData={pelaporan.data} to="/app/pelaporan/detail" linkName="Detail" /> : <Loader />}
+					</Col>
+				</Row>
+			</ContentWrapper>
+		);
+	}
 }
 
 const mapStateToProps = (state) => ({ user: state.user, token: state.token });

+ 5 - 0
utils/osValue.js

@@ -0,0 +1,5 @@
+const os = process.platform;
+
+export default function osValue() {
+	return os == "darwin" ? "Mac OS" : os == "win32" ? "Windows OS" : os == "android" ? "Android OS" : os == "linux" ? "Linux OS" : "Other OS";
+}