Skip to content

The Open Source DocuSign Alternative.

🧹🚧 doc-107 doc-19

Timur Ercan3b1bd3587922
diff --git a/apps/web/components/editor/pdf-signer.tsx b/apps/web/components/editor/pdf-signer.tsx
index f0a672c57..dda2b45b1 100644
--- a/apps/web/components/editor/pdf-signer.tsx
+++ b/apps/web/components/editor/pdf-signer.tsx
@@ -3,7 +3,7 @@ import { NEXT_PUBLIC_WEBAPP_URL } from "@documenso/lib/constants";
import { useRouter } from "next/router";
import dynamic from "next/dynamic";
import SignatureDialog from "./signature-dialog";
-import { useState } from "react";
+import { useEffect, useState } from "react";
import { Button } from "@documenso/ui";
import { CheckBadgeIcon } from "@heroicons/react/24/outline";
import toast from "react-hot-toast";
@@ -15,10 +15,15 @@ const PDFViewer = dynamic(() => import("./pdf-viewer"), {
export default function PDFSigner(props: any) {
const router = useRouter();
const [open, setOpen] = useState(false);
+ const [signingDone, setSigningDone] = useState(false);
const [signatures, setSignatures] = useState<any[]>([]);
const [fields, setFields] = useState<any[]>(props.fields);
const [dialogField, setDialogField] = useState<any>();
+ useEffect(() => {
+ setSigningDone(checkIfSigningIsDone());
+ }, [fields]);
+
function onClick(item: any) {
if (item.type === "SIGNATURE") {
setDialogField(item);
@@ -27,6 +32,7 @@ export default function PDFSigner(props: any) {
}
function onDialogClose(dialogResult: any) {
+ // todo handle signature removed from field
const signature = {
fieldId: dialogField.id,
type: dialogResult.type,
@@ -88,7 +94,7 @@ export default function PDFSigner(props: any) {
document.
</p>
<Button
- disabled={signatures.length < props.fields.length}
+ disabled={!signingDone}
color="secondary"
icon={CheckBadgeIcon}
className="float-right"
@@ -111,4 +117,14 @@ export default function PDFSigner(props: any) {
></PDFViewer>
</>
);
+
+ function checkIfSigningIsDone(): boolean {
+ // Check if all fields are signed..
+ if (fields.length > 0) {
+ // If there are no fields to sign at least one signature is enough
+ return fields.every((field) => field.signature);
+ } else {
+ return signatures.length > 0;
+ }
+ }
}
diff --git a/apps/web/pages/documents/[id]/sign.tsx b/apps/web/pages/documents/[id]/sign.tsx
index 4ec0c687d..48b054572 100644
--- a/apps/web/pages/documents/[id]/sign.tsx
+++ b/apps/web/pages/documents/[id]/sign.tsx
@@ -11,7 +11,6 @@ const SignPage: NextPageWithLayout = (props: any) => {
<title>Sign | Documenso</title>
</Head>
<PDFSigner document={props.document} fields={props.fields} />
- {/* todo read/ sign version of editor => flag or own component */}
</>
);
};
@@ -39,19 +38,31 @@ export async function getServerSideProps(context: any) {
},
});
- const fields = await prisma.field.findMany({
+ const unsignedFields = await prisma.field.findMany({
where: {
documentId: recipient.Document.id,
+ recipientId: recipient.id,
+ Signature: { is: null },
},
include: {
Recipient: true,
+ Signature: true,
},
});
+ if (unsignedFields.length === 0) {
+ return {
+ redirect: {
+ permanent: false,
+ destination: `/documents/${recipient.Document.id}/signed`,
+ },
+ };
+ }
+
return {
props: {
document: recipient.Document,
- fields: fields,
+ fields: unsignedFields,
},
};
}
diff --git a/apps/web/pages/documents/[id]/signed.tsx b/apps/web/pages/documents/[id]/signed.tsx
index 413c360ca..3f5fc9b9c 100644
--- a/apps/web/pages/documents/[id]/signed.tsx
+++ b/apps/web/pages/documents/[id]/signed.tsx
@@ -50,7 +50,7 @@ const SignPage: NextPageWithLayout = (props: any) => {
router.push("/api/documents/" + props.document.id);
}}
>
- Download Document
+ Download "{props.document.title}"
</Button>
</div>
</div>