|  | @@ -1,14 +1,12 @@
 | 
	
		
			
				|  |  |  import React, { Component } from "react";
 | 
	
		
			
				|  |  |  import { insertPemeriksaan } from "@/actions/pemeriksaan";
 | 
	
		
			
				|  |  | -import Router from "next/router";
 | 
	
		
			
				|  |  | -import Datetime from "react-datetime";
 | 
	
		
			
				|  |  | -import moment from "moment";
 | 
	
		
			
				|  |  | -import { Row, Col, FormGroup, Input, Button } from "reactstrap";
 | 
	
		
			
				|  |  | -import { ToastContainer, toast } from "react-toastify";
 | 
	
		
			
				|  |  | +import { Row, Col, Card, CardBody, FormGroup, Input, Button, Modal, ModalHeader, ModalBody, ModalFooter, CardHeader, CardTitle } from "reactstrap";
 | 
	
		
			
				|  |  | +import { toast } from "react-toastify";
 | 
	
		
			
				|  |  |  import { Formik, Form, Field, ErrorMessage } from "formik";
 | 
	
		
			
				|  |  |  import * as Yup from "yup";
 | 
	
		
			
				|  |  | -import { getOneLaporan, updateLaporan } from "@/actions/pelaporan";
 | 
	
		
			
				|  |  |  import { connect } from "react-redux";
 | 
	
		
			
				|  |  | +import { getOneSanksi, addRekomendasiDelegasi } from "@/actions/sanksi";
 | 
	
		
			
				|  |  | +
 | 
	
		
			
				|  |  |  
 | 
	
		
			
				|  |  |  const selectInstanceId = 1;
 | 
	
		
			
				|  |  |  const checkIfFilesAreTooBig = (files) => {
 | 
	
	
		
			
				|  | @@ -35,7 +33,7 @@ const checkIfFilesAreCorrectType = (files) => {
 | 
	
		
			
				|  |  |  	return valid;
 | 
	
		
			
				|  |  |  };
 | 
	
		
			
				|  |  |  
 | 
	
		
			
				|  |  | -const RekomendasiDelegasiSchema = Yup.object().shape({
 | 
	
		
			
				|  |  | +const rekomendasiSchema = Yup.object().shape({
 | 
	
		
			
				|  |  |  	dokumen: Yup.array().min(1).required("Wajib diisi").test("filesize", "Maksimal ukuran dokumen 15mb", checkIfFilesAreTooBig),
 | 
	
		
			
				|  |  |  });
 | 
	
		
			
				|  |  |  
 | 
	
	
		
			
				|  | @@ -60,22 +58,12 @@ class InputRekomendasi extends Component {
 | 
	
		
			
				|  |  |  		this.state = {
 | 
	
		
			
				|  |  |  			dropdownOpen: false,
 | 
	
		
			
				|  |  |  			splitButtonOpen: false,
 | 
	
		
			
				|  |  | -			judulEvaluasi: "",
 | 
	
		
			
				|  |  | -			tanggal: moment().format("D MMMM YYYY"),
 | 
	
		
			
				|  |  |  			files: [],
 | 
	
		
			
				|  |  | -			delegasichecklist: false,
 | 
	
		
			
				|  |  | -			rolelldikti: false,
 | 
	
		
			
				|  |  | +			sanksi: {},
 | 
	
		
			
				|  |  | +			data: {},
 | 
	
		
			
				|  |  |  		};
 | 
	
		
			
				|  |  |  	}
 | 
	
		
			
				|  |  |  
 | 
	
		
			
				|  |  | -	setjudulEvaluasi = (e) => {
 | 
	
		
			
				|  |  | -		this.setState({ judulEvaluasi: e.target.value });
 | 
	
		
			
				|  |  | -	};
 | 
	
		
			
				|  |  | -
 | 
	
		
			
				|  |  | -	setTanggal = (moment) => {
 | 
	
		
			
				|  |  | -		this.setState({ tanggal: moment.format("D MMMM YYYY") });
 | 
	
		
			
				|  |  | -	};
 | 
	
		
			
				|  |  | -
 | 
	
		
			
				|  |  |  	toggleSplit = () => {
 | 
	
		
			
				|  |  |  		this.setState({
 | 
	
		
			
				|  |  |  			splitButtonOpen: !this.state.splitButtonOpen,
 | 
	
	
		
			
				|  | @@ -118,120 +106,120 @@ class InputRekomendasi extends Component {
 | 
	
		
			
				|  |  |  		});
 | 
	
		
			
				|  |  |  	};
 | 
	
		
			
				|  |  |  
 | 
	
		
			
				|  |  | -	onSubmit = async (data, { resetForm }) => {
 | 
	
		
			
				|  |  | +	static getInitialProps = async ({ query }) => {
 | 
	
		
			
				|  |  | +		return { query };
 | 
	
		
			
				|  |  | +	};
 | 
	
		
			
				|  |  | +
 | 
	
		
			
				|  |  | +
 | 
	
		
			
				|  |  | +	handelSimpan = async () => {
 | 
	
		
			
				|  |  | +
 | 
	
		
			
				|  |  |  		const { token, query } = this.props;
 | 
	
		
			
				|  |  |  		const { id } = query;
 | 
	
		
			
				|  |  |  		const formdata = new FormData();
 | 
	
		
			
				|  |  | -		data.dokumen.forEach((e) => {
 | 
	
		
			
				|  |  | +		this.state.files.forEach((e) => {
 | 
	
		
			
				|  |  |  			formdata.append("dokumen", e);
 | 
	
		
			
				|  |  |  		});
 | 
	
		
			
				|  |  | -		if (this.state.delegasichecklist == true) {
 | 
	
		
			
				|  |  | -			await toast.promise(insertPemeriksaan(token, id, formdata), {
 | 
	
		
			
				|  |  | -				pending: "Loading",
 | 
	
		
			
				|  |  | -				success: "Success",
 | 
	
		
			
				|  |  | -				error: "Error",
 | 
	
		
			
				|  |  | -
 | 
	
		
			
				|  |  | -			});
 | 
	
		
			
				|  |  | -
 | 
	
		
			
				|  |  | -			data.change_role = "true";
 | 
	
		
			
				|  |  | -			data.keterangan = "delegasi ke DIKTI"
 | 
	
		
			
				|  |  | -			Router.push("/app/pemeriksaan");
 | 
	
		
			
				|  |  | -			update = await updateLaporan(token, id, data);
 | 
	
		
			
				|  |  | +		const toastid = toast.loading("Please wait...");
 | 
	
		
			
				|  |  | +		const added = await addRekomendasiDelegasi(token, id, formdata);
 | 
	
		
			
				|  |  | +		if (!added) {
 | 
	
		
			
				|  |  | +			toast.update(toastid, { render: "All is not good", type: "error", isLoading: false, autoClose: true, closeButton: true });
 | 
	
		
			
				|  |  |  		} else {
 | 
	
		
			
				|  |  | -			await toast.promise(insertPemeriksaan(token, id, formdata), {
 | 
	
		
			
				|  |  | -				pending: "Loading",
 | 
	
		
			
				|  |  | -				success: "Success",
 | 
	
		
			
				|  |  | -				error: "Error",
 | 
	
		
			
				|  |  | -			});
 | 
	
		
			
				|  |  | +			toast.update(toastid, { render: "All is good", type: "success", isLoading: false, autoClose: true, closeButton: true });
 | 
	
		
			
				|  |  | +			const sanksi = await getOneSanksi(token, id);
 | 
	
		
			
				|  |  | +			this.setState({ sanksi, files: [] });
 | 
	
		
			
				|  |  | +			resetForm();
 | 
	
		
			
				|  |  | +			// Router.push({
 | 
	
		
			
				|  |  | +			// 	pathname: "/app/rekomendasi-delegasi",
 | 
	
		
			
				|  |  | +			// });
 | 
	
		
			
				|  |  | +
 | 
	
		
			
				|  |  |  		}
 | 
	
		
			
				|  |  | -		this.setState({ files: [] });
 | 
	
		
			
				|  |  | -		resetForm();
 | 
	
		
			
				|  |  | -		const pelaporan = await getOneLaporan(token, query.id);
 | 
	
		
			
				|  |  | -		this.props.changePelaporan(pelaporan);
 | 
	
		
			
				|  |  | +
 | 
	
		
			
				|  |  |  	};
 | 
	
		
			
				|  |  |  	render() {
 | 
	
		
			
				|  |  |  		const { files } = this.state;
 | 
	
		
			
				|  |  |  
 | 
	
		
			
				|  |  |  		const thumbs = files.map((file, index) => (
 | 
	
		
			
				|  |  |  			<div md={3} key={index}>
 | 
	
		
			
				|  |  | -				{/* <img className="img-fluid mb-2" src={file.preview} alt="Item" /> */}
 | 
	
		
			
				|  |  |  				<span className="text-left">{index + 1}.{file.name}</span>
 | 
	
		
			
				|  |  |  			</div>
 | 
	
		
			
				|  |  |  		));
 | 
	
		
			
				|  |  |  		return (
 | 
	
		
			
				|  |  | -			<>
 | 
	
		
			
				|  |  | -				<p className="lead bb">Evaluasi</p>
 | 
	
		
			
				|  |  | -				<Formik
 | 
	
		
			
				|  |  | -					initialValues={{
 | 
	
		
			
				|  |  | -						dokumen: [],
 | 
	
		
			
				|  |  | -					}}
 | 
	
		
			
				|  |  | -					validationSchema={evaluasiSchema}
 | 
	
		
			
				|  |  | -					onSubmit={this.onSubmit}
 | 
	
		
			
				|  |  | -				>
 | 
	
		
			
				|  |  | -					<Form className="form-horizontal">
 | 
	
		
			
				|  |  | -
 | 
	
		
			
				|  |  | -						<FormGroup row>
 | 
	
		
			
				|  |  | -							<label className="col-md-2 col-form-label">Upload File Pendukung<span className="text-danger">*</span></label>
 | 
	
		
			
				|  |  | -							<div className="col-md-10">
 | 
	
		
			
				|  |  | -								<Field name="dokumen">
 | 
	
		
			
				|  |  | -									{({ field, form, meta }) => (
 | 
	
		
			
				|  |  | -										<DropzoneWrapper
 | 
	
		
			
				|  |  | -											className=""
 | 
	
		
			
				|  |  | -											onDrop={(e) => {
 | 
	
		
			
				|  |  | -												this.onDrop(e);
 | 
	
		
			
				|  |  | -												form.setFieldValue(field.name, e);
 | 
	
		
			
				|  |  | -											}}
 | 
	
		
			
				|  |  | -										>
 | 
	
		
			
				|  |  | -											{({ getRootProps, getInputProps, isDragActive }) => {
 | 
	
		
			
				|  |  | -												return (
 | 
	
		
			
				|  |  | -													<div {...getRootProps()} className={"dropzone card" + (isDragActive ? "dropzone-drag-active" : "")}>
 | 
	
		
			
				|  |  | -														<input name="dokumen" {...getInputProps()} />
 | 
	
		
			
				|  |  | -														<div className="dropzone-style-1">
 | 
	
		
			
				|  |  | -															<div className="center-ver-hor dropzone-previews flex">{this.state.files.length > 0 ? <Row><span className="text-left">{thumbs}</span></Row> :
 | 
	
		
			
				|  |  | -																<div className="text-center fa-2x icon-cloud-upload mr-2 ">
 | 
	
		
			
				|  |  | -																	<h5 className="text-center dz-default dz-message">Klik untuk upload dokumen</h5>
 | 
	
		
			
				|  |  | +			<Card className="card-default">
 | 
	
		
			
				|  |  | +				<CardBody>
 | 
	
		
			
				|  |  | +					<p className="lead bb">Dokumen Rekomendasi Delegasi</p>
 | 
	
		
			
				|  |  | +					<Formik
 | 
	
		
			
				|  |  | +						initialValues={{
 | 
	
		
			
				|  |  | +							dokumen: [],
 | 
	
		
			
				|  |  | +						}}
 | 
	
		
			
				|  |  | +						validationSchema={rekomendasiSchema}
 | 
	
		
			
				|  |  | +						onSubmit={async (data) => {
 | 
	
		
			
				|  |  | +							this.setState({ data });
 | 
	
		
			
				|  |  | +							await this.handelSimpan();
 | 
	
		
			
				|  |  | +						}}
 | 
	
		
			
				|  |  | +					>
 | 
	
		
			
				|  |  | +						{() => (
 | 
	
		
			
				|  |  | +							<Form className="form-horizontal">
 | 
	
		
			
				|  |  | +								<FormGroup>
 | 
	
		
			
				|  |  | +									<div className="row-md-10">
 | 
	
		
			
				|  |  | +										<Field name="dokumen">
 | 
	
		
			
				|  |  | +											{({ field, form }) => (
 | 
	
		
			
				|  |  | +												<DropzoneWrapper
 | 
	
		
			
				|  |  | +													className=""
 | 
	
		
			
				|  |  | +													onDrop={(e) => {
 | 
	
		
			
				|  |  | +														this.onDrop(e);
 | 
	
		
			
				|  |  | +														form.setFieldValue(field.name, e);
 | 
	
		
			
				|  |  | +													}}
 | 
	
		
			
				|  |  | +												>
 | 
	
		
			
				|  |  | +													{({ getRootProps, getInputProps, isDragActive }) => {
 | 
	
		
			
				|  |  | +														return (
 | 
	
		
			
				|  |  | +															<div {...getRootProps()} className={"dropzone card" + (isDragActive ? "dropzone-drag-active" : "")}>
 | 
	
		
			
				|  |  | +																<input {...getInputProps()} />
 | 
	
		
			
				|  |  | +																<div className="dropzone-previews flex">
 | 
	
		
			
				|  |  | +																	<div className="dropzone-style-1">
 | 
	
		
			
				|  |  | +																		<div className="center-ver-hor dropzone-previews flex">{this.state.files.length > 0 ? <Row><span className="text-left">{thumbs}</span></Row> :
 | 
	
		
			
				|  |  | +																			<div className="text-center fa-2x icon-cloud-upload mr-2 ">
 | 
	
		
			
				|  |  | +																				<h5 className="text-center dz-default dz-message">upload dokumen rekomendasi delegasi</h5>
 | 
	
		
			
				|  |  | +																			</div>
 | 
	
		
			
				|  |  | +																		}
 | 
	
		
			
				|  |  | +																		</div>
 | 
	
		
			
				|  |  | +																	</div>
 | 
	
		
			
				|  |  | +																</div>
 | 
	
		
			
				|  |  | +																<div className="d-flex align-items-center">
 | 
	
		
			
				|  |  | +																	<small className="ml-auto">
 | 
	
		
			
				|  |  | +																		<button
 | 
	
		
			
				|  |  | +																			type="button"
 | 
	
		
			
				|  |  | +																			className="btn btn-link"
 | 
	
		
			
				|  |  | +																			onClick={(e) => {
 | 
	
		
			
				|  |  | +																				this.clearFiles(e);
 | 
	
		
			
				|  |  | +																				form.setFieldValue(field.name, []);
 | 
	
		
			
				|  |  | +																			}}
 | 
	
		
			
				|  |  | +																		>
 | 
	
		
			
				|  |  | +																			Reset dokumen
 | 
	
		
			
				|  |  | +																		</button>
 | 
	
		
			
				|  |  | +																	</small>
 | 
	
		
			
				|  |  |  																</div>
 | 
	
		
			
				|  |  | -															}
 | 
	
		
			
				|  |  |  															</div>
 | 
	
		
			
				|  |  | -														</div>
 | 
	
		
			
				|  |  | -														<div className="d-flex align-items-center">
 | 
	
		
			
				|  |  | -															<small className="ml-auto">
 | 
	
		
			
				|  |  | -																<button
 | 
	
		
			
				|  |  | -																	type="button"
 | 
	
		
			
				|  |  | -																	className="btn btn-link"
 | 
	
		
			
				|  |  | -																	onClick={(e) => {
 | 
	
		
			
				|  |  | -																		this.clearFiles(e);
 | 
	
		
			
				|  |  | -																		form.setFieldValue(field.name, []);
 | 
	
		
			
				|  |  | -																	}}
 | 
	
		
			
				|  |  | -																>
 | 
	
		
			
				|  |  | -																	Reset dokumen
 | 
	
		
			
				|  |  | -																</button>
 | 
	
		
			
				|  |  | -															</small>
 | 
	
		
			
				|  |  | -														</div>
 | 
	
		
			
				|  |  | -													</div>
 | 
	
		
			
				|  |  | -												);
 | 
	
		
			
				|  |  | -											}}
 | 
	
		
			
				|  |  | -										</DropzoneWrapper>
 | 
	
		
			
				|  |  | -									)}
 | 
	
		
			
				|  |  | -								</Field>
 | 
	
		
			
				|  |  | -								<ErrorMessage name="dokumen" component="div" className="form-text text-danger" />
 | 
	
		
			
				|  |  | -								<p className="mrgn-top-5">
 | 
	
		
			
				|  |  | -									Ukuran setiap dokumen maksimal 15mb
 | 
	
		
			
				|  |  | -								</p>
 | 
	
		
			
				|  |  | -							</div>
 | 
	
		
			
				|  |  | -						</FormGroup>
 | 
	
		
			
				|  |  | -						<FormGroup row>
 | 
	
		
			
				|  |  | -							<div className="col-xl-10">
 | 
	
		
			
				|  |  | -								<Button color className="btn-login" type="submit">
 | 
	
		
			
				|  |  | -									<span className="font-color-white">
 | 
	
		
			
				|  |  | -										Simpan Evaluasi
 | 
	
		
			
				|  |  | -									</span>
 | 
	
		
			
				|  |  | -								</Button>
 | 
	
		
			
				|  |  | -							</div>
 | 
	
		
			
				|  |  | -						</FormGroup>
 | 
	
		
			
				|  |  | -					</Form>
 | 
	
		
			
				|  |  | -				</Formik>
 | 
	
		
			
				|  |  | -			</>
 | 
	
		
			
				|  |  | +														);
 | 
	
		
			
				|  |  | +													}}
 | 
	
		
			
				|  |  | +												</DropzoneWrapper>
 | 
	
		
			
				|  |  | +											)}
 | 
	
		
			
				|  |  | +										</Field>
 | 
	
		
			
				|  |  | +										<ErrorMessage name="dokumen" component="div" className="form-text text-danger" />
 | 
	
		
			
				|  |  | +										<p className="mrgn-top-5">Ukuran setiap dokumen maksimal 15mb</p>
 | 
	
		
			
				|  |  | +									</div>
 | 
	
		
			
				|  |  | +								</FormGroup>
 | 
	
		
			
				|  |  | +								<FormGroup row>
 | 
	
		
			
				|  |  | +									<div className="col-xl-10">
 | 
	
		
			
				|  |  | +										<Button color className="color-3e3a8e btn-login" type="submit">
 | 
	
		
			
				|  |  | +											<span className="font-color-white">Kirim</span>
 | 
	
		
			
				|  |  | +										</Button>
 | 
	
		
			
				|  |  | +									</div>
 | 
	
		
			
				|  |  | +								</FormGroup>
 | 
	
		
			
				|  |  | +							</Form>
 | 
	
		
			
				|  |  | +						)}
 | 
	
		
			
				|  |  | +					</Formik>
 | 
	
		
			
				|  |  | +				</CardBody>
 | 
	
		
			
				|  |  | +			</Card>
 | 
	
		
			
				|  |  |  		);
 | 
	
		
			
				|  |  |  	}
 | 
	
		
			
				|  |  |  }
 |