pemantauan.js 6.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215
  1. import React, { Component } from "react";
  2. import BasePage from "@/components/Layout/BasePage";
  3. import {
  4. Row,
  5. Col,
  6. FormGroup,
  7. Input,
  8. Card,
  9. CardBody,
  10. Button,
  11. Navbar,
  12. NavItem,
  13. NavLink,
  14. NavbarBrand,
  15. NavbarToggler,
  16. Nav,
  17. Collapse,
  18. } from "reactstrap";
  19. import Link from "next/link";
  20. import ContentWrapper from "@/components/Layout/ContentWrapper";
  21. import { getPelaporanPublic } from "@/actions/pelaporan";
  22. import DetailLaporan from "@/components/Public/DetailLaporan";
  23. import { getLogPublic } from "@/actions/log";
  24. import Timeline from "@/components/Main/Timeline";
  25. import { Formik, Form, Field, ErrorMessage } from "formik";
  26. import * as Yup from "yup";
  27. import { ToastContainer, toast } from "react-toastify";
  28. // import Swal from '@/components/Common/Swal';
  29. import "react-toastify/dist/ReactToastify.css";
  30. import swal from "sweetalert2";
  31. const menu = [
  32. {
  33. title: "Home",
  34. path: "/app",
  35. },
  36. {
  37. title: "Buat Laporan",
  38. path: "/laporan/new",
  39. },
  40. {
  41. title: "Pemantauan",
  42. path: "/pemantauan",
  43. },
  44. ];
  45. const pemantauanSchema = Yup.object().shape({
  46. no_laporan: Yup.string().required("Harap Diisi"),
  47. no_hp: Yup.number().notRequired("Harap Diisi"),
  48. });
  49. class App extends Component {
  50. constructor(props) {
  51. super(props);
  52. this.state = {
  53. isOpen: false,
  54. no_laporan: "",
  55. no_hp: "",
  56. msgError: [],
  57. laporan: null,
  58. log: null,
  59. };
  60. }
  61. static getInitialProps = ({ pathname }) => ({ pathname });
  62. toggleCollapse = () => {
  63. this.setState({
  64. isOpen: !this.state.isOpen,
  65. });
  66. };
  67. handleLihatPemantaun = async (data) => {
  68. const { no_hp, no_laporan } = data;
  69. // const toastid = toast.loading("Please wait...");
  70. const log = await getLogPublic({ no_hp, no_laporan });
  71. if (log.data) {
  72. this.setState({ laporan: log.data.laporan, log: log.data.pemantauan });
  73. // swal.fire("Data ditemukan", "", "success");
  74. swal.fire({
  75. title: "Data ditemukan",
  76. icon: "success",
  77. confirmButtonColor: "#3E3A8E",
  78. });
  79. } else {
  80. this.setState({ laporan: null, log: null });
  81. // swal.fire("Data tidak ditemukan", " ", "error");
  82. swal.fire({
  83. title: "Data tidak ditemukan",
  84. icon: "error",
  85. confirmButtonColor: "#3E3A8E",
  86. });
  87. }
  88. };
  89. render() {
  90. const { laporan, log } = this.state;
  91. return (
  92. <div>
  93. <ToastContainer />
  94. <Navbar className="navbar-color" expand="md" dark>
  95. <NavbarBrand href="/">
  96. <img
  97. className="width-133"
  98. src="/static/img/Logo-Sidali.png"
  99. alt="App Logo"
  100. />
  101. </NavbarBrand>
  102. <NavbarToggler onClick={this.toggleCollapse} />
  103. <Collapse isOpen={this.state.isOpen} navbar>
  104. <Nav className="ml-auto" navbar>
  105. {menu.map((e) => (
  106. <NavItem active={e.path === this.props.pathname ? true : false}>
  107. <Link href={e.path}>
  108. <NavLink style={{ cursor: "pointer" }}>{e.title}</NavLink>
  109. </Link>
  110. </NavItem>
  111. ))}
  112. </Nav>
  113. </Collapse>
  114. </Navbar>
  115. <ContentWrapper>
  116. <Row>
  117. <Col lg={8} className="block-center d-block ">
  118. <Card className="card-default">
  119. <CardBody>
  120. <Formik
  121. initialValues={{
  122. no_laporan: "",
  123. no_hp: "",
  124. }}
  125. validationSchema={pemantauanSchema}
  126. onSubmit={this.handleLihatPemantaun}
  127. >
  128. <Form className="form-horizontal">
  129. <div class="header-1">
  130. <h2 class="card-title-1">Pemantauan</h2>
  131. </div>
  132. {/* <p className="lead bb">Pemantauan</p> */}
  133. <FormGroup row>
  134. <label className="col-md-2 col-form-label">
  135. Nomor Laporan
  136. </label>
  137. <div className="col-md-10">
  138. <Field name="no_laporan">
  139. {({ field }) => <Input type="text" {...field} />}
  140. </Field>
  141. <ErrorMessage
  142. name="no_laporan"
  143. component="div"
  144. className="form-text text-danger"
  145. />
  146. </div>
  147. </FormGroup>
  148. <FormGroup row>
  149. <label className="col-md-2 col-form-label">
  150. Nomor Aktif
  151. </label>
  152. <div className="col-md-10">
  153. <Field name="no_hp">
  154. {({ field }) => <Input type="tel" {...field} />}
  155. </Field>
  156. <ErrorMessage
  157. name="no_hp"
  158. component="div"
  159. className="form-text text-danger"
  160. />
  161. </div>
  162. </FormGroup>
  163. <FormGroup row>
  164. <div className="posisi-btn-1 btn-radius">
  165. <Button
  166. className="button-lihatpemantauan btn-login"
  167. color
  168. block
  169. type="submit"
  170. >
  171. <h3 className="text-lihatpemantauan font-color-white">
  172. Lihat Pemantauan
  173. </h3>
  174. </Button>
  175. </div>
  176. </FormGroup>
  177. </Form>
  178. </Formik>
  179. </CardBody>
  180. </Card>
  181. <Card className="card-default">
  182. <CardBody>
  183. <div class="header-1">
  184. <h2 class="card-title-1">Rekap Laporan</h2>
  185. </div>
  186. <div className="">
  187. {laporan && log ? (
  188. <>
  189. <DetailLaporan data={laporan} />
  190. <p className="lead bb tengah">Pemantauan</p>
  191. <Timeline data={log} noFile />{" "}
  192. </>
  193. ) : (
  194. <p className="tengah">Tidak Ada Laporan</p>
  195. )}
  196. </div>
  197. </CardBody>
  198. </Card>
  199. </Col>
  200. </Row>
  201. </ContentWrapper>
  202. </div>
  203. );
  204. }
  205. }
  206. App.Layout = BasePage;
  207. export default App;