pemantauan.js 3.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135
  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: "Membuat Laporan",
  17. path: "/laporan/new",
  18. },
  19. {
  20. title: "Pemantauan",
  21. path: "/pemantauan",
  22. },
  23. {
  24. title: "Login",
  25. path: "/login",
  26. },
  27. ];
  28. class App extends Component {
  29. constructor(props) {
  30. super(props);
  31. this.state = {
  32. isOpen: false,
  33. no_laporan: "",
  34. no_hp: "",
  35. msgError: [],
  36. laporan: {},
  37. log: {},
  38. };
  39. }
  40. static getInitialProps = ({ pathname }) => ({ pathname });
  41. toggleCollapse = () => {
  42. this.setState({
  43. isOpen: !this.state.isOpen,
  44. });
  45. };
  46. handleLihatPemantaun = async (e) => {
  47. e.preventDefault();
  48. const { no_hp, no_laporan } = this.state;
  49. const laporan = await getPelaporanPublic({ number: no_laporan, noHp: no_hp });
  50. const log = await getLogPublic({ ptId: laporan.data[0].pt_id, laporanId: laporan.data[0]._id });
  51. this.setState({ laporan });
  52. this.setState({ log });
  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" /> Aldila Dikti
  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. <form className="form-horizontal" method="post" onSubmit={this.onSubmit}>
  81. <p className="lead bb">Pemantauan</p>
  82. <FormGroup row>
  83. <label className="col-md-2 col-form-label">Nomor Laporan</label>
  84. <div className="col-md-10">
  85. <Input type="text" value={this.state.no_laporan} onChange={(e) => this.setState({ no_laporan: e.target.value })} required />
  86. </div>
  87. </FormGroup>
  88. <FormGroup row>
  89. <label className="col-md-2 col-form-label">Nomor yang dapat dihubungi</label>
  90. <div className="col-md-10">
  91. <Input type="text" value={this.state.no_hp} onChange={(e) => this.setState({ no_hp: e.target.value })} required />
  92. </div>
  93. </FormGroup>
  94. <FormGroup row>
  95. <div className="col-12 col-lg-2">
  96. <Button color="info" block type="submit" onClick={this.handleLihatPemantaun}>
  97. Lihat Pemantauan
  98. </Button>
  99. </div>
  100. </FormGroup>
  101. </form>
  102. </CardBody>
  103. </Card>
  104. <Card className="card-default">
  105. <CardBody>
  106. {laporan.data && log.data ? (
  107. <>
  108. <DetailLaporan data={laporan.data[0]} />
  109. <p className="lead bb">Pemantauan</p>
  110. <Timeline data={log.data} noFile />{" "}
  111. </>
  112. ) : (
  113. ""
  114. )}
  115. </CardBody>
  116. </Card>
  117. {/* <Card className="card-default">
  118. <CardBody></CardBody>
  119. </Card> */}
  120. </Col>
  121. </Row>
  122. </ContentWrapper>
  123. </div>
  124. );
  125. }
  126. }
  127. App.Layout = BasePage;
  128. export default App;