From 851ea24be445d356dbf8e20ea771e7bc242e81c4 Mon Sep 17 00:00:00 2001 From: prafull-opensignlabs Date: Wed, 6 Nov 2024 18:27:24 +0530 Subject: [PATCH 1/3] feat: validation for signature type --- .../public/locales/en/translation.json | 6 +- .../public/locales/es/translation.json | 6 +- .../public/locales/fr/translation.json | 7 +- apps/OpenSign/src/App.js | 5 + apps/OpenSign/src/components/BulkSendUi.js | 6 +- .../src/components/pdf/DefaultSignature.js | 22 +- .../src/components/pdf/Placeholder.js | 10 +- apps/OpenSign/src/components/pdf/SignPad.js | 782 ++++++++++-------- .../src/components/pdf/WidgetNameModal.js | 145 +++- apps/OpenSign/src/constant/Utils.js | 27 +- apps/OpenSign/src/json/menuJson.js | 8 + apps/OpenSign/src/pages/DraftTemplate.js | 106 ++- apps/OpenSign/src/pages/PdfRequestFiles.js | 77 +- apps/OpenSign/src/pages/PlaceHolderSign.js | 105 +-- apps/OpenSign/src/pages/Preferences.js | 171 ++++ apps/OpenSign/src/pages/SignyourselfPdf.js | 4 +- .../OpenSign/src/pages/TemplatePlaceholder.js | 195 ++--- .../src/primitives/GetReportDisplay.js | 58 +- .../src/script/locales/en/translation.json | 8 +- .../src/script/locales/es/translation.json | 9 +- .../src/script/locales/fr/translation.json | 11 +- apps/OpenSignServer/cloud/main.js | 2 + .../cloud/parsefunction/GetTemplate.js | 1 + .../cloud/parsefunction/createBatchDocs.js | 1 + .../parsefunction/updatesignaturetype.js | 44 + ...20241106180102-add_signaturetype_field.cjs | 43 + 26 files changed, 1231 insertions(+), 628 deletions(-) create mode 100644 apps/OpenSign/src/pages/Preferences.js create mode 100644 apps/OpenSignServer/cloud/parsefunction/updatesignaturetype.js create mode 100644 apps/OpenSignServer/databases/migrations/20241106180102-add_signaturetype_field.cjs diff --git a/apps/OpenSign/public/locales/en/translation.json b/apps/OpenSign/public/locales/en/translation.json index e536fea69..16e7cc046 100644 --- a/apps/OpenSign/public/locales/en/translation.json +++ b/apps/OpenSign/public/locales/en/translation.json @@ -94,6 +94,7 @@ "My Signature": "My Signature", "API Token": "API Token", "Webhook": "Webhook", + "Preferences": "Preferences", "Teams": "Teams", "Team-update-successfully": "Team Updated successfully.", "Users": "Users" @@ -684,6 +685,7 @@ "add-user-template": "You need to add a role before you can add fields for it.", "pdf-uncompatible": "This pdf is not compatible with opensign, please contact ", "text-field-tour":"Fields of type 'Text' must be filled in advance before the document is sent. If you need the signers to provide input, use the 'Text Input' field instead.", - "attach-signer-tour":"You need to attach a Signer to every role. You can do that by clicking this icon. Once you select a Signer it will be attached to all the fields associated with that role which appear in the same colour." - + "attach-signer-tour":"You need to attach a Signer to every role. You can do that by clicking this icon. Once you select a Signer it will be attached to all the fields associated with that role which appear in the same colour.", + "allowed-signature-types": "Allowed signature types", + "at-least-one-signature-type": "At least one signature type should be enabled." } diff --git a/apps/OpenSign/public/locales/es/translation.json b/apps/OpenSign/public/locales/es/translation.json index d5615244c..743baaddd 100644 --- a/apps/OpenSign/public/locales/es/translation.json +++ b/apps/OpenSign/public/locales/es/translation.json @@ -94,6 +94,7 @@ "My Signature": "Mi firma", "API Token": "Token API", "Webhook": "Webhook", + "Preferences": "Preferencias", "Teams": "Equipos", "Team-update-successfully": "Equipo actualizado correctamente.", "Users": "Usuarios" @@ -684,6 +685,7 @@ "form-title-1": "Configuración del flujo de documentos", "form-title-2": "Configuración de seguridad", "text-field-tour":"Los campos de tipo 'Texto' deben completarse con anticipación antes de enviar el documento. Si necesita que los firmantes proporcionen información, utilice el campo 'Entrada de texto'", - "attach-signer-tour" :"Debe adjuntar un firmante a cada función. Puede hacerlo haciendo clic en este icono. Una vez que seleccione un Firmante, se adjuntará a todos los campos asociados con ese rol que aparecen en el mismo color." - + "attach-signer-tour" :"Debe adjuntar un firmante a cada función. Puede hacerlo haciendo clic en este icono. Una vez que seleccione un Firmante, se adjuntará a todos los campos asociados con ese rol que aparecen en el mismo color.", + "allowed-signature-types": "Tipos de firma permitidos", + "at-least-one-signature-type": "Se debe habilitar al menos un tipo de firma." } diff --git a/apps/OpenSign/public/locales/fr/translation.json b/apps/OpenSign/public/locales/fr/translation.json index 63b0da911..5595b02d1 100644 --- a/apps/OpenSign/public/locales/fr/translation.json +++ b/apps/OpenSign/public/locales/fr/translation.json @@ -94,6 +94,7 @@ "My Signature": "Ma signature", "API Token": "Jeton API", "Webhook": "Webhook", + "Preferences": "Préférences", "Teams": "Équipe", "Team-update-successfully": "Équipe mise à jour avec succès.", "Users": "Utilisateurs" @@ -683,7 +684,7 @@ "add-user-template":"Vous devez ajouter un rôle avant de pouvoir lui ajouter des champs. ", "pdf-uncompatible":"Ce pdf n'est pas compatible avec opensign, veuillez contacter ", "text-field-tour" :"Les champs de type 'Texte' doivent être remplis à l'avance avant l'envoi du document. Si vous avez besoin que les signataires fournissent des informations, utilisez plutôt le champ 'Saisie de texte'.", - "attach-signer-tour" :"Vous devez associer un signataire à chaque rôle. Vous pouvez le faire en cliquant sur cette icône. Une fois que vous avez sélectionné un signataire, il sera attaché à tous les champs associés à ce rôle qui apparaissent dans la même couleur." - - + "attach-signer-tour" :"Vous devez associer un signataire à chaque rôle. Vous pouvez le faire en cliquant sur cette icône. Une fois que vous avez sélectionné un signataire, il sera attaché à tous les champs associés à ce rôle qui apparaissent dans la même couleur.", + "allowed-signature-types": "Types de signature autorisés", + "at-least-one-signature-type": "Au moins un type de signature doit être activé." } diff --git a/apps/OpenSign/src/App.js b/apps/OpenSign/src/App.js index 91fb8eb5f..d47209390 100644 --- a/apps/OpenSign/src/App.js +++ b/apps/OpenSign/src/App.js @@ -36,6 +36,7 @@ const Webhook = lazy(() => import("./pages/Webhook")); const AddAdmin = lazy(() => import("./pages/AddAdmin")); const UpdateExistUserAdmin = lazy(() => import("./pages/UpdateExistUserAdmin")); const DraftTemplate = lazy(() => import("./pages/DraftTemplate")); +const Preferences = lazy(() => import("./pages/Preferences")); pdfjs.GlobalWorkerOptions.workerSrc = `//unpkg.com/pdfjs-dist@${pdfjs.version}/legacy/build/pdf.worker.min.mjs`; const AppLoader = () => { @@ -199,6 +200,10 @@ function App() { )} } /> + } + /> } /> { : [...existSigner] }); } else { - Documents.push({ ...props.item, Placeholders: updatedPlaceholders }); + Documents.push({ + ...props.item, + Placeholders: updatedPlaceholders, + SignatureType: props.signatureType + }); } }); await batchQuery(Documents); diff --git a/apps/OpenSign/src/components/pdf/DefaultSignature.js b/apps/OpenSign/src/components/pdf/DefaultSignature.js index 3847b895b..4184945d5 100644 --- a/apps/OpenSign/src/components/pdf/DefaultSignature.js +++ b/apps/OpenSign/src/components/pdf/DefaultSignature.js @@ -1,16 +1,16 @@ import React from "react"; import { useTranslation } from "react-i18next"; -function DefaultSignature({ defaultSignImg, xyPostion, setDefaultSignAlert }) { +function DefaultSignature(props) { const { t } = useTranslation(); const confirmToaddDefaultSign = () => { - if (xyPostion.length > 0) { - setDefaultSignAlert({ + if (props?.xyPostion.length > 0) { + props?.setDefaultSignAlert({ isShow: true, alertMessage: t("default-sign-alert") }); } else { - setDefaultSignAlert({ + props?.setDefaultSignAlert({ isShow: true, alertMessage: t("please-select-position!") }); @@ -22,22 +22,32 @@ function DefaultSignature({ defaultSignImg, xyPostion, setDefaultSignAlert }) {
{t("signature")}
-
+

{t("Your-Signature")}

signature
+ {!props.isDefault && ( +
+ Document creator has disabled this option +
+ )}
); diff --git a/apps/OpenSign/src/components/pdf/Placeholder.js b/apps/OpenSign/src/components/pdf/Placeholder.js index 953eb8e14..2e14ea693 100644 --- a/apps/OpenSign/src/components/pdf/Placeholder.js +++ b/apps/OpenSign/src/components/pdf/Placeholder.js @@ -445,17 +445,13 @@ function Placeholder(props) { handleOnClickSettingIcon(); }} className="fa-light fa-gear icon" - style={{ - color: "#188ae2", - right: "29px", - top: "-19px" - }} + style={{ color: "#188ae2", right: "29px", top: "-19px" }} > ) : ( /* condition to add setting icon for placeholder & template flow for all widgets except signature and date */ ((!props?.pos?.type && props.pos.isStamp) || (props?.pos?.type && - !["date", "signature"].includes(props.pos.type) && + !["date"].includes(props.pos.type) && !props.isSignYourself)) && ( { @@ -469,7 +465,7 @@ function Placeholder(props) { className="fa-light fa-gear icon" style={{ color: "#188ae2", - right: props?.pos?.type === textWidget ? "32px" : "47px", + right: props?.pos?.type === textWidget ? "32px" : "51px", top: "-19px" }} > diff --git a/apps/OpenSign/src/components/pdf/SignPad.js b/apps/OpenSign/src/components/pdf/SignPad.js index d38048efa..534f4ddae 100644 --- a/apps/OpenSign/src/components/pdf/SignPad.js +++ b/apps/OpenSign/src/components/pdf/SignPad.js @@ -1,39 +1,20 @@ import React, { useRef, useState, useEffect } from "react"; import { useTranslation } from "react-i18next"; import SignatureCanvas from "react-signature-canvas"; -function SignPad({ - isSignPad, - isStamp, - setIsImageSelect, - onSaveSign, - setIsSignPad, - setImage, - isImageSelect, - imageRef, - onImageChange, - onSaveImage, - image, - defaultSign, - setSignature, - myInitial, - isInitial, - setIsInitial, - setIsStamp, - widgetType, - currWidgetsDetails, - setCurrWidgetsDetails -}) { + +function SignPad(props) { const { t } = useTranslation(); const [penColor, setPenColor] = useState("blue"); const allColor = ["blue", "red", "black"]; const canvasRef = useRef(null); const [isDefaultSign, setIsDefaultSign] = useState(false); - const [isTab, setIsTab] = useState("draw"); + const [isTab, setIsTab] = useState(""); const [isSignImg, setIsSignImg] = useState(""); const [signValue, setSignValue] = useState(""); const [textWidth, setTextWidth] = useState(0); const [textHeight, setTextHeight] = useState(0); - const [signatureType, setSignatureType] = useState("draw"); + const [signatureType, setSignatureType] = useState(""); + const [isSignTypes, setIsSignTypes] = useState(true); const fontOptions = [ { value: "Fasthand" }, { value: "Dancing Script" }, @@ -53,24 +34,56 @@ function SignPad({ const jsonSender = JSON.parse(senderUser); const currentUserName = jsonSender && jsonSender?.name; + useEffect(() => { + handleTab(); + // eslint-disable-next-line react-hooks/exhaustive-deps + }, []); + function handleTab() { + const signtypes = props?.signatureTypes || []; + const index = signtypes?.findIndex((x) => x.enabled === true); + if (index !== -1) { + const tab = props?.signatureTypes[index].name; + if (tab === "draw") { + setIsTab("draw"); + setSignatureType("draw"); + } else if (tab === "upload") { + props?.setIsImageSelect(true); + setIsTab("uploadImage"); + } else if (tab === "typed") { + setIsTab("type"); + } else if (tab === "default") { + setIsTab("mysignature"); + } else { + setIsTab(true); + } + } else { + setIsSignTypes(false); + } + } + function isTabEnabled(tabName) { + const isEnabled = props?.signatureTypes.find( + (x) => x.name === tabName + )?.enabled; + return isEnabled; + } + //function for clear signature image const handleClear = () => { - setCurrWidgetsDetails({}); + props?.setCurrWidgetsDetails({}); if (isTab === "draw") { if (canvasRef.current) { canvasRef.current.clear(); - } else if (isStamp) { - setImage(""); + } else if (props?.isStamp) { + props?.setImage(""); } setIsSignImg(""); } else if (isTab === "uploadImage") { - setImage(""); + props?.setImage(""); } - // setIsInitial(false); }; //function for set signature url const handleSignatureChange = (data) => { - setSignature(data); + props?.setSignature(data); setIsSignImg(data); }; //save button component @@ -88,58 +101,58 @@ function SignPad({ )}