pemantauan.js 5.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166
  1. import React, { Component } from "react";
  2. import BasePage from "@/components/Layout/BasePage";
  3. import { Row, Col, FormGroup, Input, Card, CardBody, Button, Navbar, NavItem, NavLink, NavbarBrand, NavbarToggler, Nav, Collapse } from "reactstrap";
  4. import Link from "next/link";
  5. import ContentWrapper from "@/components/Layout/ContentWrapper";
  6. import { getPelaporanPublic } from "@/actions/pelaporan";
  7. import DetailLaporan from "@/components/Public/DetailLaporan";
  8. import { getLogPublic } from "@/actions/log";
  9. import Timeline from "@/components/Main/Timeline";
  10. import { Formik, Form, Field, ErrorMessage } from "formik";
  11. import * as Yup from "yup";
  12. import { ToastContainer, toast } from "react-toastify";
  13. import Swal from '@/components/Common/Swal';
  14. import "react-toastify/dist/ReactToastify.css";
  15. const menu = [
  16. {
  17. title: "Home",
  18. path: "/app",
  19. },
  20. {
  21. title: "Buat Laporan",
  22. path: "/laporan/new",
  23. },
  24. {
  25. title: "Pemantauan",
  26. path: "/pemantauan",
  27. },
  28. ];
  29. const pemantauanSchema = Yup.object().shape({
  30. no_laporan: Yup.string().required("Harap Diisi"),
  31. no_hp: Yup.number().required("Harap Diisi"),
  32. });
  33. class App extends Component {
  34. constructor(props) {
  35. super(props);
  36. this.state = {
  37. isOpen: false,
  38. no_laporan: "",
  39. no_hp: "",
  40. msgError: [],
  41. laporan: null,
  42. log: null,
  43. };
  44. }
  45. static getInitialProps = ({ pathname }) => ({ pathname });
  46. toggleCollapse = () => {
  47. this.setState({
  48. isOpen: !this.state.isOpen,
  49. });
  50. };
  51. handleLihatPemantaun = async (data) => {
  52. const { no_hp, no_laporan } = data;
  53. // const toastid = toast.loading("Please wait...");
  54. const log = await getLogPublic({ no_hp, no_laporan });
  55. if (log.data) {
  56. this.setState({ laporan: log.data.laporan, log: log.data.pemantauan });
  57. // swal.update(toastid, { render: "Berhasil mendapatkan data Pemantauan", type: "success", isLoading: false, autoClose: true, closeButton: true });
  58. swal("Data ditemukan", " ", "success");
  59. } else {
  60. this.setState({ laporan: null, log: null });
  61. // swal.update(toastid, { render: "Pemantauan tidak ada", type: "error", isLoading: false, autoClose: true, closeButton: true });
  62. swal("Data tidak ditemukan", " ", "error");
  63. }
  64. };
  65. render() {
  66. const { laporan, log } = this.state;
  67. return (
  68. <div>
  69. <ToastContainer />
  70. <Navbar className="navbar-color" expand="md" dark>
  71. <NavbarBrand href="/">
  72. <img className="img-fluid" src="/static/img/Logo-vputih.png" alt="App Logo" />
  73. <img className="img-text-vputih" src="/static/img/Logo-text-vputih.png" alt="App Logo" />
  74. </NavbarBrand>
  75. <NavbarToggler onClick={this.toggleCollapse} />
  76. <Collapse isOpen={this.state.isOpen} navbar>
  77. <Nav className="ml-auto" navbar>
  78. {menu.map((e) => (
  79. <NavItem active={e.path === this.props.pathname ? true : false}>
  80. <Link href={e.path}>
  81. <NavLink style={{ cursor: "pointer" }}>{e.title}</NavLink>
  82. </Link>
  83. </NavItem>
  84. ))}
  85. </Nav>
  86. </Collapse>
  87. </Navbar>
  88. <ContentWrapper>
  89. <Row>
  90. <Col lg={8} className="block-center d-block ">
  91. <Card className="card-default">
  92. <CardBody>
  93. <Formik
  94. initialValues={{
  95. no_laporan: "",
  96. no_hp: "",
  97. }}
  98. validationSchema={pemantauanSchema}
  99. onSubmit={this.handleLihatPemantaun}
  100. >
  101. <Form className="form-horizontal">
  102. <div class="header-1">
  103. <h2 class="card-title-1">Pemantauan</h2>
  104. </div>
  105. {/* <p className="lead bb">Pemantauan</p> */}
  106. <FormGroup row>
  107. <label className="col-md-2 col-form-label">Nomor Laporan</label>
  108. <div className="col-md-10">
  109. <Field name="no_laporan">{({ field }) => <Input type="text" {...field} />}</Field>
  110. <ErrorMessage name="no_laporan" component="div" className="form-text text-danger" />
  111. </div>
  112. </FormGroup>
  113. <FormGroup row>
  114. <label className="col-md-2 col-form-label">Nomor Aktif</label>
  115. <div className="col-md-10">
  116. <Field name="no_hp">{({ field }) => <Input type="tel" {...field} />}</Field>
  117. <ErrorMessage name="no_hp" component="div" className="form-text text-danger" />
  118. </div>
  119. </FormGroup>
  120. <FormGroup row>
  121. <div className="posisi-btn-1">
  122. <Button className="button-lihatpemantauan" color="info" block type="submit">
  123. <h3 className="text-lihatpemantauan">Lihat Pemantauan</h3>
  124. </Button>
  125. </div>
  126. </FormGroup>
  127. </Form>
  128. </Formik>
  129. </CardBody>
  130. </Card>
  131. <Card className="card-default">
  132. <CardBody>
  133. <div class="header-1">
  134. <h2 class="card-title-1">Rekap Laporan</h2>
  135. </div>
  136. <div className="">
  137. {laporan && log ? (
  138. <>
  139. <DetailLaporan data={laporan} />
  140. <p className="lead bb tengah">Pemantauan</p>
  141. <Timeline data={log} noFile />{" "}
  142. </>
  143. ) : (
  144. <p className="tengah">Tidak Ada Laporan</p>
  145. )}
  146. </div>
  147. </CardBody>
  148. </Card>
  149. </Col>
  150. </Row>
  151. </ContentWrapper>
  152. </div>
  153. );
  154. }
  155. }
  156. App.Layout = BasePage;
  157. export default App;