detail.js 4.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173
  1. import React, { Component } from "react";
  2. import Router from "next/router";
  3. import Link from "next/link";
  4. import { getSanksi } from "@/actions/sanksi";
  5. import Header from "@/components/Main/Header";
  6. import DetailPT from "@/components/Main/DetailPT";
  7. import DetailSanksi from "@/components/Main/DetailSanksi";
  8. import Riwayat from "@/components/PT/Riwayat";
  9. import ContentWrapper from "@/components/Layout/ContentWrapper";
  10. import { Row, Col, Card, CardBody, FormGroup, Button } from "reactstrap";
  11. import { addCabutSanksi } from "@/actions/cabutSanksi";
  12. let Dropzone = null;
  13. class DropzoneWrapper extends Component {
  14. state = {
  15. isClient: false,
  16. };
  17. componentDidMount = () => {
  18. Dropzone = require("react-dropzone").default;
  19. this.setState({ isClient: true });
  20. };
  21. render() {
  22. return Dropzone ? <Dropzone {...this.props}>{this.props.children}</Dropzone> : null;
  23. }
  24. }
  25. class DetailPencabutanSanksi extends Component {
  26. constructor(props) {
  27. super(props);
  28. this.state = {
  29. files: [],
  30. };
  31. }
  32. static async getInitialProps({ query }) {
  33. const { noSanksi } = query;
  34. const sanksi = await getSanksi({ noSanksi, ptId: "0BCE4DB7-B207-445D-8D03-0C54B7688252" });
  35. return { query, sanksi };
  36. }
  37. onDrop = (files) => {
  38. this.setState({
  39. files: files.map((file) =>
  40. Object.assign(file, {
  41. preview: URL.createObjectURL(file),
  42. })
  43. ),
  44. stat: "Added " + files.length + " file(s)",
  45. });
  46. };
  47. uploadFiles = (e) => {
  48. e.preventDefault();
  49. e.stopPropagation();
  50. this.setState({
  51. stat: this.state.files.length ? "Dropzone ready to upload " + this.state.files.length + " file(s)" : "No files added.",
  52. });
  53. };
  54. clearFiles = (e) => {
  55. e.preventDefault();
  56. e.stopPropagation();
  57. this.setState({
  58. stat: this.state.files.length ? this.state.files.length + " file(s) cleared." : "No files to clear.",
  59. });
  60. this.setState({
  61. files: [],
  62. });
  63. };
  64. handleKirim = async (e) => {
  65. e.preventDefault();
  66. const { noSanksi } = this.props.query;
  67. const formdata = new FormData();
  68. if (this.state.files.length > 0) {
  69. this.state.files.forEach((e) => {
  70. formdata.append("files", e);
  71. });
  72. }
  73. const added = await addCabutSanksi({ noSanksi, ptId: "0BCE4DB7-B207-445D-8D03-0C54B7688252" }, formdata);
  74. if (added) {
  75. Router.push({
  76. pathname: "/app/pt/pencabutan-sanksi",
  77. });
  78. }
  79. };
  80. render() {
  81. const { sanksi } = this.props;
  82. const { files } = this.state;
  83. const thumbs = files.map((file, index) => (
  84. <Col md={3} key={index}>
  85. <img className="img-fluid mb-2" src={file.preview} alt="Item" />
  86. </Col>
  87. ));
  88. return (
  89. <ContentWrapper unwrap>
  90. <Header />
  91. <div className="p-3">
  92. <div className="content-heading">
  93. <div>Permohonan Pencabutan Sanksi</div>
  94. <div className="ml-auto">
  95. <Link href="/app/pt/pencabutan-sanksi">
  96. <button className="btn btn-sm btn-secondary text-sm">&lt; back</button>
  97. </Link>
  98. </div>
  99. </div>
  100. <Row>
  101. <Col xl="9">
  102. <Card className="card-default">
  103. <CardBody>
  104. <Row>
  105. <Col lg="6">
  106. <DetailSanksi data={sanksi.data[0]} />
  107. </Col>
  108. <Col lg={6}>
  109. <p className="lead bb">Permohonan Pencabutan Sanksi</p>
  110. <form className="form-horizontal" method="get" action="/" onSubmit={this.onSubmit}>
  111. <FormGroup>
  112. <label className="row-form-label">Upload Dokumen:</label>
  113. <div className="row-md-10">
  114. <DropzoneWrapper className="" onDrop={this.onDrop}>
  115. {({ getRootProps, getInputProps, isDragActive }) => {
  116. return (
  117. <div {...getRootProps()} className={"dropzone card p-3 " + (isDragActive ? "dropzone-drag-active" : "")}>
  118. <input {...getInputProps()} />
  119. <div className="dropzone-previews flex">
  120. {this.state.files.length > 0 ? <Row>{thumbs}</Row> : <div className="text-center dz-default dz-message">Drop files here to upload</div>}
  121. </div>
  122. <div className="d-flex align-items-center">
  123. <small className="ml-auto">
  124. <button type="button" className="btn btn-link" onClick={this.clearFiles}>
  125. Clear files
  126. </button>
  127. </small>
  128. </div>
  129. </div>
  130. );
  131. }}
  132. </DropzoneWrapper>
  133. </div>
  134. </FormGroup>
  135. <FormGroup>
  136. <div className="row-xl-10">
  137. <Button color="primary" onClick={this.handleKirim} type="submit">
  138. Kirim
  139. </Button>
  140. </div>
  141. </FormGroup>
  142. </form>
  143. </Col>
  144. </Row>
  145. </CardBody>
  146. </Card>
  147. </Col>
  148. <Col xl="3">
  149. <DetailPT />
  150. </Col>
  151. </Row>
  152. <Row>
  153. <Col>
  154. <Riwayat data={sanksi.data[0].sanksi.cabut_sanksi} />
  155. </Col>
  156. </Row>
  157. </div>
  158. </ContentWrapper>
  159. );
  160. }
  161. }
  162. export default DetailPencabutanSanksi;