pemantauan.js 3.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128
  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. const menu = [
  11. {
  12. title: "Home",
  13. path: "/app",
  14. },
  15. {
  16. title: "Buat Laporan",
  17. path: "/laporan/new",
  18. },
  19. {
  20. title: "Pemantauan",
  21. path: "/pemantauan",
  22. },
  23. ];
  24. class App extends Component {
  25. constructor(props) {
  26. super(props);
  27. this.state = {
  28. isOpen: false,
  29. no_laporan: "",
  30. no_hp: "",
  31. msgError: [],
  32. laporan: {},
  33. log: {},
  34. };
  35. }
  36. static getInitialProps = ({ pathname }) => ({ pathname });
  37. toggleCollapse = () => {
  38. this.setState({
  39. isOpen: !this.state.isOpen,
  40. });
  41. };
  42. handleLihatPemantaun = async (e) => {
  43. e.preventDefault();
  44. const { no_hp, no_laporan } = this.state;
  45. const laporan = await getPelaporanPublic({ number: no_laporan, noHp: no_hp });
  46. const log = await getLogPublic({ ptId: laporan.data[0].pt_id, laporanId: laporan.data[0]._id });
  47. this.setState({ laporan });
  48. this.setState({ log });
  49. };
  50. render() {
  51. const { laporan, log } = this.state;
  52. return (
  53. <div>
  54. <Navbar color="info" expand="md" dark>
  55. <NavbarBrand href="/">
  56. <img className="img-fluid" src="/static/img/logo-single.png" alt="App Logo" /> Sidali
  57. </NavbarBrand>
  58. <NavbarToggler onClick={this.toggleCollapse} />
  59. <Collapse isOpen={this.state.isOpen} navbar>
  60. <Nav className="ml-auto" navbar>
  61. {menu.map((e) => (
  62. <NavItem active={e.path === this.props.pathname ? true : false}>
  63. <Link href={e.path}>
  64. <NavLink style={{ cursor: "pointer" }}>{e.title}</NavLink>
  65. </Link>
  66. </NavItem>
  67. ))}
  68. </Nav>
  69. </Collapse>
  70. </Navbar>
  71. <ContentWrapper>
  72. <Row>
  73. <Col lg={8} className="block-center d-block ">
  74. <Card className="card-default">
  75. <CardBody>
  76. <form className="form-horizontal" method="post" onSubmit={this.onSubmit}>
  77. <p className="lead bb">Pemantauan</p>
  78. <FormGroup row>
  79. <label className="col-md-2 col-form-label">Nomor Laporan</label>
  80. <div className="col-md-10">
  81. <Input type="text" value={this.state.no_laporan} onChange={(e) => this.setState({ no_laporan: e.target.value })} required />
  82. </div>
  83. </FormGroup>
  84. <FormGroup row>
  85. <label className="col-md-2 col-form-label">Nomor yang dapat dihubungi</label>
  86. <div className="col-md-10">
  87. <Input type="text" value={this.state.no_hp} onChange={(e) => this.setState({ no_hp: e.target.value })} required />
  88. </div>
  89. </FormGroup>
  90. <FormGroup row>
  91. <div className="col-12 col-lg-2">
  92. <Button color="info" block type="submit" onClick={this.handleLihatPemantaun}>
  93. Lihat Pemantauan
  94. </Button>
  95. </div>
  96. </FormGroup>
  97. </form>
  98. </CardBody>
  99. </Card>
  100. <Card className="card-default">
  101. <CardBody>
  102. {laporan.data && log.data ? (
  103. <>
  104. <DetailLaporan data={laporan.data[0]} />
  105. <p className="lead bb">Pemantauan</p>
  106. <Timeline data={log.data} noFile />{" "}
  107. </>
  108. ) : (
  109. "Tidak Ada Laporan"
  110. )}
  111. </CardBody>
  112. </Card>
  113. </Col>
  114. </Row>
  115. </ContentWrapper>
  116. </div>
  117. );
  118. }
  119. }
  120. App.Layout = BasePage;
  121. export default App;