import { NEXT_PUBLIC_WEBAPP_URL } from "@documenso/lib/constants"; import { useRouter } from "next/router"; import dynamic from "next/dynamic"; import React, { useState } from "react"; import { Button } from "@documenso/ui"; import short from "short-uuid"; import toast from "react-hot-toast"; import { FieldType } from "@prisma/client"; const stc = require("string-to-color"); const PDFViewer = dynamic(() => import("./pdf-viewer"), { ssr: false, }); export default function PDFEditor(props: any) { const [selectedValue, setSelectedValue] = useState(""); const [fields, setFields] = useState(props.document.Field); const router = useRouter(); function onPositionChangedHandler(position: any, id: any) { if (!position) return; const movedField = fields.find((e) => e.id == id); movedField.positionX = position.x; movedField.positionY = position.y; upsertField(props.document, movedField); // no instant redraw neccessary, postion information for saving or later rerender is enough // setFields(newFields); } return ( <> ); } async function upsertField(document: any, field: any): Promise { try { const created = await toast.promise( fetch("/api/documents/" + document.id + "/fields", { method: "POST", headers: { "Content-Type": "application/json", }, body: JSON.stringify(field), }).then((res) => { if (!res.ok) { throw new Error(res.status.toString()); } return res.json(); }), { loading: "Saving...", success: "Saved.", error: "Could not save :/", }, { id: "saving field", style: { minWidth: "200px", }, } ); return created; } catch (error) {} }