import React, { Component } from "react"; import Router from "next/router"; import { connect } from "react-redux"; import ContentWrapper from "@/components/Layout/ContentWrapper"; import { Row, Col, Card, CardHeader, CardBody, Button, FormGroup, Popover, PopoverHeader } from "reactstrap"; // import { Editor } from 'react-draft-wysiwyg'; import 'react-draft-wysiwyg/dist/react-draft-wysiwyg.css'; import { EditorState, ContentState, convertFromHTML, convertToRaw, convertFromRaw } from 'draft-js'; // import 'draft-js/dist/Draft.css'; import dynamic from 'next/dynamic'; const Editor = dynamic( () => import('react-draft-wysiwyg').then(mod => mod.Editor), { ssr: false }) import draftToHtml from 'draftjs-to-html'; import pdfMake from "pdfmake/build/pdfmake"; import StateToPdfMake from "draft-js-export-pdfmake"; import pdfFonts from "pdfmake/build/vfs_fonts"; import { toast } from "react-toastify"; import { addCatatan, getOneCatatan, updateCatatan } from "../../../actions/catatan"; import { getCsrf } from "../../../actions/security"; pdfMake.vfs = pdfFonts.pdfMake.vfs; import { ENV } from '../../../env.js'; import CopyToClipboard from "react-copy-to-clipboard"; import ReactToPrint from "react-to-print"; import ComponentToPrint from "../../../components/PerpanjanganSanksi/presensi_print.js"; import htmlToPdfmake from "html-to-pdfmake" // import htmlToDraft from 'html-to-draftjs'; import SummerNote from "../../../components/Extras/summernote"; class EditFile extends Component { constructor(props) { super(props); this.state = { editorState: null, copiedd: false, judul: "", }; } static getInitialProps = async ({ query }) => { return { query }; }; componentDidMount = async () => { const { token, query } = this.props; const { id } = query; const getCatatan = await getOneCatatan(token, id) const catatan = getCatatan.data const judul = catatan.judul this.setState({ catatan, judul }); // let blocksFromHTML; // let editorState; // if (typeof window !== 'undefined') { // const htmlToDraft = require('html-to-draftjs').default; // const isi = catatan.isi // blocksFromHTML = htmlToDraft((isi)); // console.log(blocksFromHTML) // editorState = ContentState.createFromBlockArray( // blocksFromHTML.contentBlocks, // blocksFromHTML.entityMap // ); // } this.setState({ // editorState: EditorState.createWithContent(editorState) editorState:catatan?.isi }); } onEditorStateChange = (editorState) => { this.setState({ editorState, }); // localStorage.setItem("editorState", draftToHtml(convertToRaw(editorState.getCurrentContent()))) }; 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 updateCatatan(token, this.state.catatan.sanksi_id, { "judul": this.state.judul, "isi": this.state.editorState, "catatan_id": id, "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=${this.state.catatan.sanksi_id}`); } } }; handleGeneratePDF = () => { // const htmlContent = draftToHtml(convertToRaw(this.state.editorState.getCurrentContent())) const htmlToPrint = htmlToPdfmake(this.state.editorState) const siapPrint = {content : htmlToPrint} pdfMake.createPdf(siapPrint).download(); }; setHandleJudul = (e) => { this.setState({ judul: e.target.value }); }; CloseCopiedd = () => { setTimeout(() => { this.setState({ copiedd: !this.state.copiedd }); }, 1000); } Copiedd = () => this.setState({ copiedd: !this.state.copiedd }) render() { const { editorState, catatan } = this.state; console.log(editorState) return (
{ return }} content={() => this.componentRef} />
(this.componentRef = el)} query={this.props.query} />
{/* { return new Promise((resolve, reject) => { const reader = new FileReader(); reader.onloadend = () => { resolve({ data: { url: reader.result, }, }); }; reader.onerror = (reason) => reject(reason); reader.readAsDataURL(file); }); }, alt: { present: false, mandatory: false }, inputAccept: 'image/gif,image/jpeg,image/jpg,image/png,image/svg', }, }} /> */} { this.setState({ editorState, }); }} // onImageUpload={this.onImageUpload} // ref={this.editor} />
PESERTA RAPAT
{catatan ? catatan.daftar_kehadiran_peserta?.map((value) => (
{value.nama}
)) : ""}
{ENV === "local" &&
Link Berhasil Disalin
} {ENV === "production" &&
Link Berhasil Disalin
} {ENV === "development" &&
Link Berhasil Disalin
}
); } } const mapStateToProps = (state) => ({ user: state.user, token: state.token }); export default connect(mapStateToProps)(EditFile);