import React, { useRef, Component } from 'react'; import { Row, Col, Button, Popover, PopoverHeader, PopoverBody, Card, CardBody, Modal, ModalBody, ModalFooter, FormGroup } from "reactstrap"; import ReactToPrint, { PrintContextConsumer } from 'react-to-print'; import id from 'date-fns/locale/id'; import CopyToClipboard from "react-copy-to-clipboard"; import { getAutoSave } from "@/actions/autosave"; import ContentEditable from 'react-contenteditable' import { ToastContainer, toast } from "react-toastify"; import Router from "next/router"; import ContentWrapper from "@/components/Layout/ContentWrapper"; import Swal from 'sweetalert2'; import Datetime from "react-datetime"; import { getOneSanksi } from "@/actions/sanksi"; import { addCatatan } from "../../../actions/catatan"; import { getCsrf } from "../../../actions/security"; class Catatan extends Component { constructor(props) { super(props); this.state = { judul: "", tanggal: "", setTanggal: false, isEditTanggal: false, isEditTempat: false, simpulan: "", rekomendasi: "", isi: [ { Aspek_Perbaikan: "", Laporan_Perbaikan: "", Hasil_Verifikasi: "" }, ], }; } static getInitialProps = async ({ query }) => { return { query }; }; componentDidMount = async () => { const { query, token } = this.props; const idSanksi = query.id; const sanksi = await getOneSanksi(token, idSanksi, { all: true }); const pt = sanksi.data?.laporan.pt; this.setState({ sanksi, pt }); }; handelSimpan = async (data) => { if (this.props?.user?.role.id === 2024) { Swal.fire({ icon: 'error', title: 'Oops...', html: 'Maaf anda tidak memiliki akses untuk menyelesaikan
proses ini.
', confirmButtonColor: "#3e3a8e", confirmButtonText: 'Oke' }) } else { const getToken = await getCsrf(); const _csrf = getToken.token; const { token, query } = this.props; const { id } = query; // const isi = ("editorState", draftToHtml(convertToRaw(this.state.editorState.getCurrentContent()))) const toastid = toast.loading("Please wait..."); const added = await addCatatan(token, id, { "judul": this.state.judul, "isi": this.state, "menu": "Perpanjangan Sanksi" }, _csrf); if (!added) { toast.update(toastid, { render: "Error", type: "error", isLoading: false, autoClose: true, closeButton: true }); } else { toast.update(toastid, { render: "Success", type: "success", isLoading: false, autoClose: true, closeButton: true }); Router.push(`/app/perpanjangan-sanksi/detail?id=${id}`); // this.setState({ simpan: true }) } } }; setHandleJudul = (e) => { this.setState({ judul: e.target.value }, this.setDataCatatan); }; isEditTanggal = () => { // this.state.isEditTanggal = !this.state.isEditTanggal this.setState({ isEditTanggal: !this.state.isEditTanggal, }) } isEditTempat = () => { this.setState({ isEditTempat: !this.state.isEditTempat, }) } handleAspek = (evt, id, field) => { const newValue = evt.target.value || evt.target.innerHTML; this.setState(prevState => ({ isi: prevState.isi.map((item, index) => index === id ? { ...item, [field]: newValue } : item ) })); }; addRow = () => { this.setState(prevState => ({ isi: [ ...prevState.isi, { Aspek_Perbaikan: "", Laporan_Perbaikan: "", Hasil_Verifikasi: "" } ] })); }; setDataCatatan = (data) => { this.setState({ dataCatatan: data }); } removeRow = (index) => { this.setState(prevState => ({ isi: prevState.isi.filter((_, i) => i !== index) })); }; render() { const { pt } = this.state const { tanggal, isEditTanggal, simpulan, catatan } = this.state return (
Pada hari ini
{isEditTanggal &&
| NO | ASPEK PERBAIKAN | LAPORAN PERBAIKAN | HASIL VERIFIKASI DAN VALIDASI | |
|---|---|---|---|---|
| {index + 1} |
|
|
|