pemantauan.js 5.0 KB

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