detail.js 5.2 KB

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