pemantauan.js 5.2 KB

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