detail.js 4.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170
  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/CabutSanksi/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. const added = await addCabutSanksi({ noSanksi, ptId: "0BCE4DB7-B207-445D-8D03-0C54B7688252" }, formdata);
  73. if (added) {
  74. Router.push({
  75. pathname: "/app/pt/pencabutan-sanksi",
  76. });
  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={12}>
  106. <DetailSanksi data={sanksi.data[0]} />
  107. <p className="lead bb">Permohonan Pencabutan Sanksi</p>
  108. <form className="form-horizontal" method="get" action="/" onSubmit={this.onSubmit}>
  109. <FormGroup>
  110. <label className="row-form-label">Upload Dokumen:</label>
  111. <div className="row-md-10">
  112. <DropzoneWrapper className="" onDrop={this.onDrop}>
  113. {({ getRootProps, getInputProps, isDragActive }) => {
  114. return (
  115. <div {...getRootProps()} className={"dropzone card p-3 " + (isDragActive ? "dropzone-drag-active" : "")}>
  116. <input {...getInputProps()} />
  117. <div className="dropzone-previews flex">
  118. {this.state.files.length > 0 ? <Row>{thumbs}</Row> : <div className="text-center dz-default dz-message">Drop files here to upload</div>}
  119. </div>
  120. <div className="d-flex align-items-center">
  121. <small className="ml-auto">
  122. <button type="button" className="btn btn-link" onClick={this.clearFiles}>
  123. Clear files
  124. </button>
  125. </small>
  126. </div>
  127. </div>
  128. );
  129. }}
  130. </DropzoneWrapper>
  131. </div>
  132. </FormGroup>
  133. <FormGroup>
  134. <div className="row-xl-10">
  135. <Button color="primary" onClick={this.handleKirim} disabled={sanksi.data[0].sanksi.cabut_sanksi || false} type="submit">
  136. Kirim
  137. </Button>
  138. </div>
  139. </FormGroup>
  140. </form>
  141. </Col>
  142. </Row>
  143. </CardBody>
  144. </Card>
  145. </Col>
  146. <Col xl="3">
  147. <DetailPT />
  148. </Col>
  149. </Row>
  150. <Row>
  151. <Col>
  152. <Riwayat data={sanksi.data[0]} />
  153. </Col>
  154. </Row>
  155. </div>
  156. </ContentWrapper>
  157. );
  158. }
  159. }
  160. export default DetailPencabutanSanksi;