detail.js 5.8 KB

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