From 44884ae648a2c6f630470a0fe913de264617d53e Mon Sep 17 00:00:00 2001 From: Timur Ercan Date: Mon, 20 Feb 2023 14:49:17 +0100 Subject: [PATCH] =?UTF-8?q?=F0=9F=9A=A7=20place=20signatures=20and=20text?= =?UTF-8?q?=20signatures?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- apps/web/components/editor/pdf-signer.tsx | 4 +- apps/web/components/editor/readonly-field.tsx | 4 +- .../components/editor/signature-dialog.tsx | 39 +- apps/web/package.json | 1 + apps/web/pages/api/documents/[id]/sign.ts | 65 +- package-lock.json | 777 ++++++++++++++++++ packages/lib/index.ts | 1 + packages/lib/webstorage.ts | 24 + packages/pdf/insertImageInPDF.ts | 11 +- packages/pdf/insertTextInPDF.ts | 12 +- 10 files changed, 891 insertions(+), 47 deletions(-) create mode 100644 packages/lib/webstorage.ts diff --git a/apps/web/components/editor/pdf-signer.tsx b/apps/web/components/editor/pdf-signer.tsx index b8b32c9bd..f0a672c57 100644 --- a/apps/web/components/editor/pdf-signer.tsx +++ b/apps/web/components/editor/pdf-signer.tsx @@ -30,7 +30,7 @@ export default function PDFSigner(props: any) { const signature = { fieldId: dialogField.id, type: dialogResult.type, - name: dialogResult.name, + typedSignature: dialogResult.typedSignature, signatureImage: dialogResult.signatureImage, }; @@ -72,8 +72,6 @@ export default function PDFSigner(props: any) { error: "Could not sign :/", } ); - - // goto signing done page } return ( diff --git a/apps/web/components/editor/readonly-field.tsx b/apps/web/components/editor/readonly-field.tsx index 95e241a55..34c2b75a5 100644 --- a/apps/web/components/editor/readonly-field.tsx +++ b/apps/web/components/editor/readonly-field.tsx @@ -57,7 +57,9 @@ export default function ReadOnlyField(props: FieldPropsType) { hidden={!field?.signature} className="font-qwigley text-5xl m-auto w-auto flex-row-reverse font-medium text-center" > - {field?.signature?.type === "type" ? field?.signature.name : ""} + {field?.signature?.type === "type" + ? field?.signature.typedSignature + : ""} {field?.signature?.type === "draw" ? ( ) : ( diff --git a/apps/web/components/editor/signature-dialog.tsx b/apps/web/components/editor/signature-dialog.tsx index af935870f..5cd1ed3eb 100644 --- a/apps/web/components/editor/signature-dialog.tsx +++ b/apps/web/components/editor/signature-dialog.tsx @@ -6,8 +6,9 @@ import { PencilIcon, TrashIcon, } from "@heroicons/react/24/outline"; -import { Fragment, useState } from "react"; +import { Fragment, useEffect, useState } from "react"; import SignatureCanvas from "react-signature-canvas"; +import { localStorage } from "@documenso/lib"; const tabs = [ { name: "Type", icon: LanguageIcon, current: true }, @@ -16,10 +17,13 @@ const tabs = [ export default function SignatureDialog(props: any) { const [currentTab, setCurrentTab] = useState(tabs[0]); - const [typedName, setTypedName] = useState(""); + const [typedSignature, setTypedSignature] = useState(""); const [signatureEmpty, setSignatureEmpty] = useState(true); + let signCanvasRef: any | undefined; - let signCanvas: any | undefined; + useEffect(() => { + setTypedSignature(localStorage.getItem("typedSignature") || ""); + }); return ( <> @@ -82,13 +86,16 @@ export default function SignatureDialog(props: any) { {isCurrentTab("Type") ? (
-
+
{ - setTypedName(e.target.value); + setTypedSignature(e.target.value); }} - className="font-qw leading-none h-10 align-bottom font-qwigley mt-14 text-center block border-b w-full border-gray-300 focus:border-neon focus:ring-neon text-2xl" + className={classNames( + typedSignature ? "font-qwigley text-4xl" : "", + "leading-none h-10 align-bottom mt-14 text-center block w-full focus:border-neon focus:ring-neon text-2xl" + )} placeholder="Kindly type your name" />
@@ -101,11 +108,15 @@ export default function SignatureDialog(props: any) {