pemantauan.js 5.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175
  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 "sweetalert2";
  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.fire("Data ditemukan", "", "success");
  59. swal.fire({
  60. title: 'Data ditemukan',
  61. icon: 'success',
  62. confirmButtonColor: '#6FB9DE',
  63. })
  64. } else {
  65. this.setState({ laporan: null, log: null });
  66. // swal.fire("Data tidak ditemukan", " ", "error");
  67. swal.fire({
  68. title: 'Data tidak ditemukan',
  69. icon: 'error',
  70. confirmButtonColor: '#6FB9DE',
  71. })
  72. }
  73. };
  74. render() {
  75. const { laporan, log } = this.state;
  76. return (
  77. <div>
  78. <ToastContainer />
  79. <Navbar className="navbar-color" expand="md" dark>
  80. <NavbarBrand href="/">
  81. <img className="img-fluid" src="/static/img/Logo-vputih.png" alt="App Logo" />
  82. <img className="img-text-vputih" src="/static/img/Logo-text-vputih.png" alt="App Logo" />
  83. </NavbarBrand>
  84. <NavbarToggler onClick={this.toggleCollapse} />
  85. <Collapse isOpen={this.state.isOpen} navbar>
  86. <Nav className="ml-auto" navbar>
  87. {menu.map((e) => (
  88. <NavItem active={e.path === this.props.pathname ? true : false}>
  89. <Link href={e.path}>
  90. <NavLink style={{ cursor: "pointer" }}>{e.title}</NavLink>
  91. </Link>
  92. </NavItem>
  93. ))}
  94. </Nav>
  95. </Collapse>
  96. </Navbar>
  97. <ContentWrapper>
  98. <Row>
  99. <Col lg={8} className="block-center d-block ">
  100. <Card className="card-default">
  101. <CardBody>
  102. <Formik
  103. initialValues={{
  104. no_laporan: "",
  105. no_hp: "",
  106. }}
  107. validationSchema={pemantauanSchema}
  108. onSubmit={this.handleLihatPemantaun}
  109. >
  110. <Form className="form-horizontal">
  111. <div class="header-1">
  112. <h2 class="card-title-1">Pemantauan</h2>
  113. </div>
  114. {/* <p className="lead bb">Pemantauan</p> */}
  115. <FormGroup row>
  116. <label className="col-md-2 col-form-label">Nomor Laporan</label>
  117. <div className="col-md-10">
  118. <Field name="no_laporan">{({ field }) => <Input type="text" {...field} />}</Field>
  119. <ErrorMessage name="no_laporan" component="div" className="form-text text-danger" />
  120. </div>
  121. </FormGroup>
  122. <FormGroup row>
  123. <label className="col-md-2 col-form-label">Nomor Aktif</label>
  124. <div className="col-md-10">
  125. <Field name="no_hp">{({ field }) => <Input type="tel" {...field} />}</Field>
  126. <ErrorMessage name="no_hp" component="div" className="form-text text-danger" />
  127. </div>
  128. </FormGroup>
  129. <FormGroup row>
  130. <div className="posisi-btn-1 btn-radius">
  131. <Button className="button-lihatpemantauan" color="info" block type="submit">
  132. <h3 className="text-lihatpemantauan">Lihat Pemantauan</h3>
  133. </Button>
  134. </div>
  135. </FormGroup>
  136. </Form>
  137. </Formik>
  138. </CardBody>
  139. </Card>
  140. <Card className="card-default">
  141. <CardBody>
  142. <div class="header-1">
  143. <h2 class="card-title-1">Rekap Laporan</h2>
  144. </div>
  145. <div className="">
  146. {laporan && log ? (
  147. <>
  148. <DetailLaporan data={laporan} />
  149. <p className="lead bb tengah">Pemantauan</p>
  150. <Timeline data={log} noFile />{" "}
  151. </>
  152. ) : (
  153. <p className="tengah">Tidak Ada Laporan</p>
  154. )}
  155. </div>
  156. </CardBody>
  157. </Card>
  158. </Col>
  159. </Row>
  160. </ContentWrapper>
  161. </div>
  162. );
  163. }
  164. }
  165. App.Layout = BasePage;
  166. export default App;