pemantauan.js 5.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174
  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: '#3E3A8E',
  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: '#3E3A8E',
  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="width-133" src="/static/img/logo-sidali.png" alt="App Logo" />
  82. </NavbarBrand>
  83. <NavbarToggler onClick={this.toggleCollapse} />
  84. <Collapse isOpen={this.state.isOpen} navbar>
  85. <Nav className="ml-auto" navbar>
  86. {menu.map((e) => (
  87. <NavItem active={e.path === this.props.pathname ? true : false}>
  88. <Link href={e.path}>
  89. <NavLink style={{ cursor: "pointer" }}>{e.title}</NavLink>
  90. </Link>
  91. </NavItem>
  92. ))}
  93. </Nav>
  94. </Collapse>
  95. </Navbar>
  96. <ContentWrapper>
  97. <Row>
  98. <Col lg={8} className="block-center d-block ">
  99. <Card className="card-default">
  100. <CardBody>
  101. <Formik
  102. initialValues={{
  103. no_laporan: "",
  104. no_hp: "",
  105. }}
  106. validationSchema={pemantauanSchema}
  107. onSubmit={this.handleLihatPemantaun}
  108. >
  109. <Form className="form-horizontal">
  110. <div class="header-1">
  111. <h2 class="card-title-1">Pemantauan</h2>
  112. </div>
  113. {/* <p className="lead bb">Pemantauan</p> */}
  114. <FormGroup row>
  115. <label className="col-md-2 col-form-label">Nomor Laporan</label>
  116. <div className="col-md-10">
  117. <Field name="no_laporan">{({ field }) => <Input type="text" {...field} />}</Field>
  118. <ErrorMessage name="no_laporan" component="div" className="form-text text-danger" />
  119. </div>
  120. </FormGroup>
  121. <FormGroup row>
  122. <label className="col-md-2 col-form-label">Nomor Aktif</label>
  123. <div className="col-md-10">
  124. <Field name="no_hp">{({ field }) => <Input type="tel" {...field} />}</Field>
  125. <ErrorMessage name="no_hp" component="div" className="form-text text-danger" />
  126. </div>
  127. </FormGroup>
  128. <FormGroup row>
  129. <div className="posisi-btn-1 btn-radius">
  130. <Button className="button-lihatpemantauan" color block type="submit">
  131. <h3 className="text-lihatpemantauan font-color-white">Lihat Pemantauan</h3>
  132. </Button>
  133. </div>
  134. </FormGroup>
  135. </Form>
  136. </Formik>
  137. </CardBody>
  138. </Card>
  139. <Card className="card-default">
  140. <CardBody>
  141. <div class="header-1">
  142. <h2 class="card-title-1">Rekap Laporan</h2>
  143. </div>
  144. <div className="">
  145. {laporan && log ? (
  146. <>
  147. <DetailLaporan data={laporan} />
  148. <p className="lead bb tengah">Pemantauan</p>
  149. <Timeline data={log} noFile />{" "}
  150. </>
  151. ) : (
  152. <p className="tengah">Tidak Ada Laporan</p>
  153. )}
  154. </div>
  155. </CardBody>
  156. </Card>
  157. </Col>
  158. </Row>
  159. </ContentWrapper>
  160. </div>
  161. );
  162. }
  163. }
  164. App.Layout = BasePage;
  165. export default App;