mirror of
https://github.com/documenso/documenso.git
synced 2025-11-13 08:13:56 +10:00
🧹🚧 doc-107 doc-19
This commit is contained in:
@ -3,7 +3,7 @@ import { NEXT_PUBLIC_WEBAPP_URL } from "@documenso/lib/constants";
|
|||||||
import { useRouter } from "next/router";
|
import { useRouter } from "next/router";
|
||||||
import dynamic from "next/dynamic";
|
import dynamic from "next/dynamic";
|
||||||
import SignatureDialog from "./signature-dialog";
|
import SignatureDialog from "./signature-dialog";
|
||||||
import { useState } from "react";
|
import { useEffect, useState } from "react";
|
||||||
import { Button } from "@documenso/ui";
|
import { Button } from "@documenso/ui";
|
||||||
import { CheckBadgeIcon } from "@heroicons/react/24/outline";
|
import { CheckBadgeIcon } from "@heroicons/react/24/outline";
|
||||||
import toast from "react-hot-toast";
|
import toast from "react-hot-toast";
|
||||||
@ -15,10 +15,15 @@ const PDFViewer = dynamic(() => import("./pdf-viewer"), {
|
|||||||
export default function PDFSigner(props: any) {
|
export default function PDFSigner(props: any) {
|
||||||
const router = useRouter();
|
const router = useRouter();
|
||||||
const [open, setOpen] = useState(false);
|
const [open, setOpen] = useState(false);
|
||||||
|
const [signingDone, setSigningDone] = useState(false);
|
||||||
const [signatures, setSignatures] = useState<any[]>([]);
|
const [signatures, setSignatures] = useState<any[]>([]);
|
||||||
const [fields, setFields] = useState<any[]>(props.fields);
|
const [fields, setFields] = useState<any[]>(props.fields);
|
||||||
const [dialogField, setDialogField] = useState<any>();
|
const [dialogField, setDialogField] = useState<any>();
|
||||||
|
|
||||||
|
useEffect(() => {
|
||||||
|
setSigningDone(checkIfSigningIsDone());
|
||||||
|
}, [fields]);
|
||||||
|
|
||||||
function onClick(item: any) {
|
function onClick(item: any) {
|
||||||
if (item.type === "SIGNATURE") {
|
if (item.type === "SIGNATURE") {
|
||||||
setDialogField(item);
|
setDialogField(item);
|
||||||
@ -27,6 +32,7 @@ export default function PDFSigner(props: any) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
function onDialogClose(dialogResult: any) {
|
function onDialogClose(dialogResult: any) {
|
||||||
|
// todo handle signature removed from field
|
||||||
const signature = {
|
const signature = {
|
||||||
fieldId: dialogField.id,
|
fieldId: dialogField.id,
|
||||||
type: dialogResult.type,
|
type: dialogResult.type,
|
||||||
@ -88,7 +94,7 @@ export default function PDFSigner(props: any) {
|
|||||||
document.
|
document.
|
||||||
</p>
|
</p>
|
||||||
<Button
|
<Button
|
||||||
disabled={signatures.length < props.fields.length}
|
disabled={!signingDone}
|
||||||
color="secondary"
|
color="secondary"
|
||||||
icon={CheckBadgeIcon}
|
icon={CheckBadgeIcon}
|
||||||
className="float-right"
|
className="float-right"
|
||||||
@ -111,4 +117,14 @@ export default function PDFSigner(props: any) {
|
|||||||
></PDFViewer>
|
></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;
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@ -11,7 +11,6 @@ const SignPage: NextPageWithLayout = (props: any) => {
|
|||||||
<title>Sign | Documenso</title>
|
<title>Sign | Documenso</title>
|
||||||
</Head>
|
</Head>
|
||||||
<PDFSigner document={props.document} fields={props.fields} />
|
<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: {
|
where: {
|
||||||
documentId: recipient.Document.id,
|
documentId: recipient.Document.id,
|
||||||
|
recipientId: recipient.id,
|
||||||
|
Signature: { is: null },
|
||||||
},
|
},
|
||||||
include: {
|
include: {
|
||||||
Recipient: true,
|
Recipient: true,
|
||||||
|
Signature: true,
|
||||||
},
|
},
|
||||||
});
|
});
|
||||||
|
|
||||||
|
if (unsignedFields.length === 0) {
|
||||||
|
return {
|
||||||
|
redirect: {
|
||||||
|
permanent: false,
|
||||||
|
destination: `/documents/${recipient.Document.id}/signed`,
|
||||||
|
},
|
||||||
|
};
|
||||||
|
}
|
||||||
|
|
||||||
return {
|
return {
|
||||||
props: {
|
props: {
|
||||||
document: recipient.Document,
|
document: recipient.Document,
|
||||||
fields: fields,
|
fields: unsignedFields,
|
||||||
},
|
},
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
|
|||||||
@ -50,7 +50,7 @@ const SignPage: NextPageWithLayout = (props: any) => {
|
|||||||
router.push("/api/documents/" + props.document.id);
|
router.push("/api/documents/" + props.document.id);
|
||||||
}}
|
}}
|
||||||
>
|
>
|
||||||
Download Document
|
Download "{props.document.title}"
|
||||||
</Button>
|
</Button>
|
||||||
</div>
|
</div>
|
||||||
</div>
|
</div>
|
||||||
|
|||||||
Reference in New Issue
Block a user