mirror of
https://github.com/documenso/documenso.git
synced 2025-11-13 00:03:33 +10:00
🚧 singing workflow, signing pad
This commit is contained in:
@ -16,6 +16,7 @@ export default function PDFSigner(props: any) {
|
||||
const router = useRouter();
|
||||
const [open, setOpen] = useState(false);
|
||||
const [signatures, setSignatures] = useState<any[]>([]);
|
||||
const [fields, setFields] = useState<any[]>(props.fields);
|
||||
const [dialogField, setDialogField] = useState<any>();
|
||||
|
||||
function onClick(item: any) {
|
||||
@ -26,16 +27,24 @@ export default function PDFSigner(props: any) {
|
||||
}
|
||||
|
||||
function onDialogClose(dialogResult: any) {
|
||||
console.log(dialogResult);
|
||||
console.log(dialogField);
|
||||
setSignatures(
|
||||
signatures.concat({
|
||||
fieldId: dialogField.id,
|
||||
type: dialogResult.type,
|
||||
name: dialogResult.name,
|
||||
signatureImage: null,
|
||||
})
|
||||
const signature = {
|
||||
fieldId: dialogField.id,
|
||||
type: dialogResult.type,
|
||||
name: dialogResult.name,
|
||||
signatureImage: dialogResult.signatureImage,
|
||||
};
|
||||
|
||||
setSignatures(signatures.concat(signature));
|
||||
|
||||
fields.splice(
|
||||
fields.findIndex(function (i) {
|
||||
return i.id === signature.fieldId;
|
||||
}),
|
||||
1
|
||||
);
|
||||
const signedField = { ...dialogField };
|
||||
signedField.signature = signature;
|
||||
setFields(fields.concat(signedField));
|
||||
setOpen(false);
|
||||
setDialogField(null);
|
||||
}
|
||||
@ -98,7 +107,7 @@ export default function PDFSigner(props: any) {
|
||||
<PDFViewer
|
||||
readonly={true}
|
||||
document={props.document}
|
||||
fields={props.fields}
|
||||
fields={fields}
|
||||
pdfUrl={`${NEXT_PUBLIC_WEBAPP_URL}/api/documents/${router.query.id}?token=${router.query.token}`}
|
||||
onClick={onClick}
|
||||
></PDFViewer>
|
||||
|
||||
@ -39,7 +39,7 @@ export default function ReadOnlyField(props: FieldPropsType) {
|
||||
>
|
||||
<div
|
||||
onClick={() => {
|
||||
props.onClick(props.field);
|
||||
if (!field?.signature) props.onClick(props.field);
|
||||
}}
|
||||
ref={nodeRef}
|
||||
className="cursor-pointer opacity-80 p-2 m-auto w-auto flex-row-reverse text-lg font-bold text-center absolute top-0 left-0 select-none hover:brightness-50"
|
||||
@ -47,9 +47,35 @@ export default function ReadOnlyField(props: FieldPropsType) {
|
||||
background: stc(props.field.Recipient.email),
|
||||
}}
|
||||
>
|
||||
<div className="m-auto w-auto flex-row-reverse font-medium text-center px-12 py-2">
|
||||
<div
|
||||
hidden={field?.signature}
|
||||
className="m-auto w-auto flex-row-reverse font-medium text-center px-12 py-2"
|
||||
>
|
||||
{field.type === "SIGNATURE" ? "SIGN HERE" : ""}
|
||||
</div>
|
||||
<div
|
||||
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 === "draw" ? (
|
||||
<img className="w-50 h-20" src={field?.signature?.signatureImage} />
|
||||
) : (
|
||||
""
|
||||
)}
|
||||
<IconButton
|
||||
icon={XCircleIcon}
|
||||
color="secondary"
|
||||
className="absolute top-0 right-0 -m-5"
|
||||
onClick={(event: any) => {
|
||||
event.preventDefault();
|
||||
event.stopPropagation();
|
||||
const newField = { ...field };
|
||||
newField.signature = null;
|
||||
setField(newField);
|
||||
}}
|
||||
/>
|
||||
</div>
|
||||
</div>
|
||||
</Draggable>
|
||||
);
|
||||
|
||||
@ -2,25 +2,24 @@ import { classNames } from "@documenso/lib";
|
||||
import { Button, IconButton } from "@documenso/ui";
|
||||
import { Dialog, Transition } from "@headlessui/react";
|
||||
import {
|
||||
BuildingOfficeIcon,
|
||||
CreditCardIcon,
|
||||
LanguageIcon,
|
||||
PencilIcon,
|
||||
UserIcon,
|
||||
UsersIcon,
|
||||
XMarkIcon,
|
||||
TrashIcon,
|
||||
} from "@heroicons/react/24/outline";
|
||||
import React from "react";
|
||||
import { Fragment, useState } from "react";
|
||||
import SignatureCanvas from "react-signature-canvas";
|
||||
|
||||
const tabs = [
|
||||
{ name: "Type", href: "#", icon: LanguageIcon, current: true },
|
||||
{ name: "Draw", href: "#", icon: PencilIcon, current: false },
|
||||
{ name: "Type", icon: LanguageIcon, current: true },
|
||||
{ name: "Draw", icon: PencilIcon, current: false },
|
||||
];
|
||||
|
||||
export default function SignatureDialog(props: any) {
|
||||
const [currentTab, setCurrentTab] = useState(tabs[0]);
|
||||
const [typedName, setTypedName] = useState("");
|
||||
const [signatureEmpty, setSignatureEmpty] = useState(true);
|
||||
|
||||
let signCanvas: any | undefined;
|
||||
|
||||
return (
|
||||
<>
|
||||
@ -49,37 +48,35 @@ export default function SignatureDialog(props: any) {
|
||||
leaveFrom="opacity-100 translate-y-0 sm:scale-100"
|
||||
leaveTo="opacity-0 translate-y-4 sm:translate-y-0 sm:scale-95"
|
||||
>
|
||||
<Dialog.Panel className="min-h-[300px] relative transform overflow-hidden rounded-lg bg-white px-4 pt-5 pb-4 text-left shadow-xl transition-all sm:my-8 sm:w-full sm:max-w-sm sm:p-6">
|
||||
<Dialog.Panel className="min-h-[350px] relative transform overflow-hidden rounded-lg bg-white px-4 pt-5 pb-4 text-left shadow-xl transition-all sm:my-8 sm:w-full sm:max-w-sm sm:p-6">
|
||||
<div className="">
|
||||
<div className="border-b border-gray-200 mb-3">
|
||||
<nav className="-mb-px flex space-x-8" aria-label="Tabs">
|
||||
{tabs.map((tab) => (
|
||||
<Fragment>
|
||||
<a
|
||||
key={tab.name}
|
||||
onClick={() => {
|
||||
setCurrent(tab);
|
||||
}}
|
||||
<a
|
||||
key={tab.name}
|
||||
onClick={() => {
|
||||
setCurrent(tab);
|
||||
}}
|
||||
className={classNames(
|
||||
tab.current
|
||||
? "border-neon text-neon"
|
||||
: "border-transparent text-gray-500 hover:text-gray-700 hover:border-gray-300",
|
||||
"group inline-flex items-center py-4 px-1 border-b-2 font-medium text-sm cursor-pointer"
|
||||
)}
|
||||
aria-current={tab.current ? "page" : undefined}
|
||||
>
|
||||
<tab.icon
|
||||
className={classNames(
|
||||
tab.current
|
||||
? "border-neon text-neon"
|
||||
: "border-transparent text-gray-500 hover:text-gray-700 hover:border-gray-300",
|
||||
"group inline-flex items-center py-4 px-1 border-b-2 font-medium text-sm cursor-pointer"
|
||||
? "text-neon"
|
||||
: "text-gray-400 group-hover:text-gray-500",
|
||||
"-ml-0.5 mr-2 h-5 w-5"
|
||||
)}
|
||||
aria-current={tab.current ? "page" : undefined}
|
||||
>
|
||||
<tab.icon
|
||||
className={classNames(
|
||||
tab.current
|
||||
? "text-neon"
|
||||
: "text-gray-400 group-hover:text-gray-500",
|
||||
"-ml-0.5 mr-2 h-5 w-5"
|
||||
)}
|
||||
aria-hidden="true"
|
||||
/>
|
||||
<span>{tab.name}</span>
|
||||
</a>
|
||||
</Fragment>
|
||||
aria-hidden="true"
|
||||
/>
|
||||
<span>{tab.name}</span>
|
||||
</a>
|
||||
))}
|
||||
</nav>
|
||||
</div>
|
||||
@ -87,14 +84,11 @@ export default function SignatureDialog(props: any) {
|
||||
<div>
|
||||
<div className="my-8">
|
||||
<input
|
||||
type="email"
|
||||
name="email"
|
||||
id="email"
|
||||
value={typedName}
|
||||
onChange={(e) => {
|
||||
setTypedName(e.target.value);
|
||||
}}
|
||||
className="mt-3 p-1 text-center block border-b w-full border-gray-300 focus:border-neon focus:ring-neon text-2xl"
|
||||
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"
|
||||
placeholder="Kindly type your name"
|
||||
/>
|
||||
</div>
|
||||
@ -111,7 +105,7 @@ export default function SignatureDialog(props: any) {
|
||||
onClick={() => {
|
||||
props.onClose({
|
||||
type: "type",
|
||||
name: "typedName",
|
||||
name: typedName,
|
||||
});
|
||||
}}
|
||||
>
|
||||
@ -123,15 +117,45 @@ export default function SignatureDialog(props: any) {
|
||||
""
|
||||
)}
|
||||
{isCurrentTab("Draw") ? (
|
||||
<div className="my-8">
|
||||
<div className="float-right">
|
||||
<div className="">
|
||||
<SignatureCanvas
|
||||
ref={(ref) => {
|
||||
signCanvas = ref;
|
||||
}}
|
||||
canvasProps={{
|
||||
className:
|
||||
"sigCanvas border-b b-2 border-slate w-full h-full mb-3",
|
||||
}}
|
||||
onEnd={() => {
|
||||
setSignatureEmpty(signCanvas?.isEmpty());
|
||||
}}
|
||||
/>
|
||||
<IconButton
|
||||
className="block float-left"
|
||||
icon={TrashIcon}
|
||||
onClick={() => {
|
||||
signCanvas?.clear();
|
||||
setSignatureEmpty(signCanvas?.isEmpty());
|
||||
}}
|
||||
></IconButton>
|
||||
<div className="mt-10 float-right">
|
||||
<Button
|
||||
color="secondary"
|
||||
onClick={() => props.setOpen(false)}
|
||||
>
|
||||
Cancel
|
||||
</Button>
|
||||
<Button className="ml-3" disabled={!typedName}>
|
||||
<Button
|
||||
className="ml-3"
|
||||
onClick={() => {
|
||||
props.onClose({
|
||||
type: "draw",
|
||||
signatureImage:
|
||||
signCanvas.toDataURL("image/png"),
|
||||
});
|
||||
}}
|
||||
disabled={signatureEmpty}
|
||||
>
|
||||
Sign
|
||||
</Button>
|
||||
</div>
|
||||
|
||||
@ -42,7 +42,6 @@
|
||||
"react-tooltip": "^5.7.2",
|
||||
"sass": "^1.57.1",
|
||||
"short-uuid": "^4.2.2",
|
||||
"signature_pad": "^4.1.4",
|
||||
"string-to-color": "^2.2.2",
|
||||
"typescript": "4.8.4"
|
||||
},
|
||||
|
||||
@ -24,6 +24,8 @@ const SignPage: NextPageWithLayout = (props: any) => {
|
||||
export async function getServerSideProps(context: any) {
|
||||
const recipientToken: string = context.query["token"];
|
||||
|
||||
// todo redirect to sigend of all already signed
|
||||
|
||||
await prisma.recipient.updateMany({
|
||||
where: {
|
||||
token: recipientToken,
|
||||
|
||||
@ -6,7 +6,9 @@
|
||||
min-height: 100%;
|
||||
}
|
||||
|
||||
body {
|
||||
html,
|
||||
body,
|
||||
:host {
|
||||
font-family: montserrat;
|
||||
}
|
||||
|
||||
|
||||
@ -13,7 +13,7 @@ module.exports = {
|
||||
extend: {
|
||||
fontFamily: {
|
||||
monteserrat: ["Monteserrat", "serif"],
|
||||
// qwigley: ["Qwigley", "serif"],
|
||||
qwigley: ["Qwigley", "serif"],
|
||||
},
|
||||
colors: {
|
||||
neon: "#37f095",
|
||||
|
||||
Reference in New Issue
Block a user