pemantauan.js 4.5 KB

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