pemantauan.js 4.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144
  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 color="info" expand="md" dark>
  59. <NavbarBrand href="/">
  60. <img className="img-fluid" src="/static/img/logo-single.png" alt="App Logo" /> Sidali
  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. <p className="lead bb">Pemantauan</p>
  90. <FormGroup row>
  91. <label className="col-md-2 col-form-label">Nomor Laporan</label>
  92. <div className="col-md-10">
  93. <Field name="no_laporan">{({ field }) => <Input type="text" {...field} />}</Field>
  94. <ErrorMessage name="no_laporan" component="div" className="form-text text-danger" />
  95. </div>
  96. </FormGroup>
  97. <FormGroup row>
  98. <label className="col-md-2 col-form-label">Nomor yang dapat dihubungi</label>
  99. <div className="col-md-10">
  100. <Field name="no_hp">{({ field }) => <Input type="tel" {...field} />}</Field>
  101. <ErrorMessage name="no_hp" component="div" className="form-text text-danger" />
  102. </div>
  103. </FormGroup>
  104. <FormGroup row>
  105. <div className="col-12 col-lg-2">
  106. <Button color="info" block type="submit">
  107. Lihat Pemantauan
  108. </Button>
  109. </div>
  110. </FormGroup>
  111. </Form>
  112. </Formik>
  113. </CardBody>
  114. </Card>
  115. <Card className="card-default">
  116. <CardBody>
  117. {laporan && log ? (
  118. <>
  119. <DetailLaporan data={laporan} />
  120. <p className="lead bb">Pemantauan</p>
  121. <Timeline data={log} noFile />{" "}
  122. </>
  123. ) : (
  124. "Tidak Ada Laporan"
  125. )}
  126. </CardBody>
  127. </Card>
  128. </Col>
  129. </Row>
  130. </ContentWrapper>
  131. </div>
  132. );
  133. }
  134. }
  135. App.Layout = BasePage;
  136. export default App;