Skip to content

Commit 9915a70

Browse files
fix: incompatible pdf issue and signturetype issues
1 parent 851ea24 commit 9915a70

File tree

7 files changed

+75
-76
lines changed

7 files changed

+75
-76
lines changed

apps/OpenSign/src/components/pdf/SignPad.js

Lines changed: 16 additions & 26 deletions
Original file line numberDiff line numberDiff line change
@@ -125,7 +125,6 @@ function SignPad(props) {
125125
props?.onSaveSign(signatureType);
126126
}
127127
}
128-
129128
setPenColor("blue");
130129
} else {
131130
setIsSignImg("");
@@ -136,7 +135,7 @@ function SignPad(props) {
136135
props?.setIsImageSelect(false);
137136
setIsDefaultSign(false);
138137
props?.setImage();
139-
setIsTab("draw");
138+
handleTab();
140139
setSignValue("");
141140
props?.setIsStamp(false);
142141
}}
@@ -310,6 +309,19 @@ function SignPad(props) {
310309
</div>
311310
);
312311
};
312+
313+
// `handleCancelBtn` function trigger when user click on cross button
314+
const handleCancelBtn = () => {
315+
setPenColor("blue");
316+
props?.setIsSignPad(false);
317+
props?.setIsInitial(false);
318+
props?.setIsImageSelect(false);
319+
setIsDefaultSign(false);
320+
props?.setImage();
321+
handleTab();
322+
setSignValue("");
323+
props?.setIsStamp(false);
324+
};
313325
return (
314326
<div>
315327
{props?.isSignPad && (
@@ -443,18 +455,7 @@ function SignPad(props) {
443455
</div>
444456
<div
445457
className="text-[1.5rem] cursor-pointer"
446-
onClick={() => {
447-
setPenColor("blue");
448-
props?.setIsSignPad(false);
449-
props?.setIsInitial(false);
450-
props?.setIsImageSelect(false);
451-
setIsDefaultSign(false);
452-
props?.setImage();
453-
setIsTab("draw");
454-
setSignatureType("draw");
455-
setSignValue("");
456-
props?.setIsStamp(false);
457-
}}
458+
onClick={handleCancelBtn}
458459
>
459460
&times;
460461
</div>
@@ -657,18 +658,7 @@ function SignPad(props) {
657658
</div>
658659
<div
659660
className="text-[1.5rem] cursor-pointer"
660-
onClick={() => {
661-
setPenColor("blue");
662-
props?.setIsSignPad(false);
663-
props?.setIsInitial(false);
664-
props?.setIsImageSelect(false);
665-
setIsDefaultSign(false);
666-
props?.setImage();
667-
setIsTab("draw");
668-
setSignatureType("draw");
669-
setSignValue("");
670-
props?.setIsStamp(false);
671-
}}
661+
onClick={handleCancelBtn}
672662
>
673663
&times;
674664
</div>

apps/OpenSign/src/constant/Utils.js

Lines changed: 23 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -637,10 +637,10 @@ export const signPdfFun = async (
637637
return { status: "error", message: "something went wrong." };
638638
}
639639
}
640-
//change image width and height to 100/40 in png base64
641-
const getNewse64 = await changeImageWH(base64Sign);
642-
//remove suffiix of base64
643-
const suffixbase64 = getNewse64 && getNewse64.split(",").pop();
640+
//change image width and height to 300/120 in png base64
641+
const imagebase64 = await changeImageWH(base64Sign);
642+
//remove suffiix of base64 (without type)
643+
const suffixbase64 = imagebase64 && imagebase64.split(",").pop();
644644

645645
const params = {
646646
mailProvider: activeMailAdapter,
@@ -1169,10 +1169,7 @@ export function onSaveSign(
11691169
Height: posHeight,
11701170
SignUrl: signatureImg,
11711171
signatureType: type && type,
1172-
options: {
1173-
...position.options,
1174-
response: signatureImg
1175-
}
1172+
options: { ...position.options, response: signatureImg }
11761173
};
11771174
}
11781175
return position;
@@ -1382,11 +1379,16 @@ export const multiSignEmbed = async (
13821379
const form = pdfDoc.getForm();
13831380
const page = pages[pageNo - 1];
13841381
const images = await Promise.all(
1385-
widgetsPositionArr.map(async (url) => {
1386-
let signUrl = url.SignUrl && url.SignUrl;
1387-
if (signUrl) {
1388-
const res = await fetch(signUrl);
1389-
return res.arrayBuffer();
1382+
widgetsPositionArr.map(async (widget) => {
1383+
// `SignUrl` this is wrong nomenclature and maintain for older code in this options we save base64 of signature image from sign pad
1384+
let signbase64 = widget.SignUrl && widget.SignUrl;
1385+
if (signbase64) {
1386+
let arr = signbase64.split(","),
1387+
mime = arr[0].match(/:(.*?);/)[1];
1388+
const res = await fetch(signbase64);
1389+
const arrayBuffer = await res.arrayBuffer();
1390+
const obj = { mimetype: mime, arrayBuffer: arrayBuffer };
1391+
return obj;
13901392
}
13911393
})
13921394
);
@@ -1397,17 +1399,17 @@ export const multiSignEmbed = async (
13971399
if (
13981400
["signature", "stamp", "initials", "image"].includes(position.type)
13991401
) {
1400-
if (position.ImageType && position.ImageType === "image/jpeg") {
1401-
img = await pdfDoc.embedJpg(images[id]);
1402+
if (images[id].mimetype === "image/png") {
1403+
img = await pdfDoc.embedPng(images[id].arrayBuffer);
14021404
} else {
1403-
img = await pdfDoc.embedPng(images[id]);
1405+
img = await pdfDoc.embedJpg(images[id].arrayBuffer);
14041406
}
14051407
} else if (!position.type) {
14061408
// to handle old widget when only stamp and signature are exists
1407-
if (position.ImageType && position.ImageType === "image/jpeg") {
1408-
img = await pdfDoc.embedJpg(images[id]);
1409+
if (images[id].mimetype === "image/png") {
1410+
img = await pdfDoc.embedPng(images[id].arrayBuffer);
14091411
} else {
1410-
img = await pdfDoc.embedPng(images[id]);
1412+
img = await pdfDoc.embedJpg(images[id].arrayBuffer);
14111413
}
14121414
}
14131415
let widgetWidth, widgetHeight;
@@ -1992,15 +1994,15 @@ export const getAppLogo = async () => {
19921994
}
19931995
};
19941996

1995-
export const getTenantDetails = async (objectId, jwttoken) => {
1997+
export const getTenantDetails = async (objectId, jwttoken, contactId) => {
19961998
try {
19971999
const url = `${localStorage.getItem("baseUrl")}functions/gettenant`;
19982000
const parseAppId = localStorage.getItem("parseAppId");
19992001
const accesstoken = localStorage.getItem("accesstoken");
20002002
const token = jwttoken
20012003
? { jwttoken: jwttoken }
20022004
: { "X-Parse-Session-Token": accesstoken };
2003-
const data = jwttoken ? {} : { userId: objectId };
2005+
const data = jwttoken ? {} : { userId: objectId, contactId: contactId };
20042006
const res = await axios.post(url, data, {
20052007
headers: {
20062008
"Content-Type": "application/json",

apps/OpenSign/src/json/menuJson.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -156,7 +156,7 @@ const sidebarList = [
156156
objectId: "webhook"
157157
},
158158
{
159-
icon: "fa-light fa-pen-fancy",
159+
icon: "fa-light fa-sliders",
160160
title: "Preferences",
161161
target: "_self",
162162
pageType: "",

apps/OpenSign/src/pages/Managesign.js

Lines changed: 9 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -136,10 +136,10 @@ const ManageSign = () => {
136136
const replaceSpace = sanitizeFileName(sanitizename);
137137
let file;
138138
if (signature) {
139-
file = base64StringtoFile(signature, `${replaceSpace}_sign.png`);
139+
file = base64StringtoFile(signature, `${replaceSpace}_sign`);
140140
} else {
141141
if (image && !isUrl) {
142-
file = base64StringtoFile(image, `${replaceSpace}__sign.png`);
142+
file = base64StringtoFile(image, `${replaceSpace}__sign`);
143143
}
144144
}
145145
let imgUrl;
@@ -153,12 +153,12 @@ const ManageSign = () => {
153153

154154
let initialFile;
155155
if (Initials) {
156-
initialFile = base64StringtoFile(Initials, `${replaceSpace}_sign.png`);
156+
initialFile = base64StringtoFile(Initials, `${replaceSpace}_sign`);
157157
} else {
158158
if (imgInitials && !isInitialsUrl) {
159159
initialFile = base64StringtoFile(
160160
imgInitials,
161-
`${replaceSpace}__sign.png`
161+
`${replaceSpace}__sign`
162162
);
163163
}
164164
}
@@ -179,14 +179,18 @@ const ManageSign = () => {
179179
};
180180
function base64StringtoFile(base64String, filename) {
181181
let arr = base64String.split(","),
182+
// type of uploaded image
182183
mime = arr[0].match(/:(.*?);/)[1],
184+
// decode base64
183185
bstr = atob(arr[1]),
184186
n = bstr.length,
185187
u8arr = new Uint8Array(n);
186188
while (n--) {
187189
u8arr[n] = bstr.charCodeAt(n);
188190
}
189-
return new File([u8arr], filename, { type: mime });
191+
const ext = mime.split("/").pop();
192+
const name = `${filename}.${ext}`;
193+
return new File([u8arr], name, { type: mime });
190194
}
191195

192196
const uploadFile = async (file) => {

apps/OpenSign/src/pages/PdfRequestFiles.js

Lines changed: 21 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -378,29 +378,29 @@ function PdfRequestFiles(props) {
378378
return;
379379
}
380380
};
381-
const fetchTenantDetails = async () => {
381+
const fetchTenantDetails = async (contactId) => {
382382
const user = JSON.parse(
383383
localStorage.getItem(
384384
`Parse/${localStorage.getItem("parseAppId")}/currentUser`
385385
)
386386
);
387-
if (user) {
388-
try {
389-
const tenantDetails = await getTenantDetails(user?.objectId);
390-
if (tenantDetails && tenantDetails === "user does not exist!") {
391-
alert(t("user-not-exist"));
392-
} else if (tenantDetails) {
393-
const signatureType = tenantDetails?.SignatureType || [];
394-
const filterSignTypes = signatureType?.filter(
395-
(x) => x.enabled === true
396-
);
397-
398-
return filterSignTypes;
399-
}
400-
} catch (e) {
387+
try {
388+
const tenantDetails = await getTenantDetails(
389+
user?.objectId, // userId
390+
"", // jwttoken
391+
contactId // contactId
392+
);
393+
if (tenantDetails && tenantDetails === "user does not exist!") {
401394
alert(t("user-not-exist"));
395+
} else if (tenantDetails) {
396+
const signatureType = tenantDetails?.SignatureType || [];
397+
const filterSignTypes = signatureType?.filter(
398+
(x) => x.enabled === true
399+
);
400+
401+
return filterSignTypes;
402402
}
403-
} else {
403+
} catch (e) {
404404
alert(t("user-not-exist"));
405405
}
406406
};
@@ -412,7 +412,10 @@ function PdfRequestFiles(props) {
412412
`Parse/${localStorage.getItem("parseAppId")}/currentUser`
413413
);
414414
const jsonSender = JSON.parse(senderUser);
415-
const tenantSignTypes = await fetchTenantDetails();
415+
const contactId = jsonSender?.objectId
416+
? ""
417+
: contactBookId || signerObjectId || "";
418+
const tenantSignTypes = await fetchTenantDetails(contactId);
416419
// `currUserId` will be contactId or extUserId
417420
let currUserId;
418421
//getting document details
@@ -453,7 +456,7 @@ function PdfRequestFiles(props) {
453456

454457
currUserId = getCurrentSigner?.objectId
455458
? getCurrentSigner.objectId
456-
: contactBookId || signerObjectId || "";
459+
: contactBookId || signerObjectId || ""; //signerObjectId is contactBookId refer from public template flow
457460
if (isEnableSubscription) {
458461
await checkIsSubscribed(
459462
documentData[0]?.ExtUserPtr?.objectId,

apps/OpenSign/src/pages/Preferences.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -73,7 +73,7 @@ const Preferences = () => {
7373
const params = { SignatureType: signatureType };
7474
const updateRes = await Parse.Cloud.run("updatesignaturetype", params);
7575
if (updateRes) {
76-
setIsAlert({ type: "danger", msg: "Saved successfully." });
76+
setIsAlert({ type: "success", msg: "Saved successfully." });
7777
setTimeout(() => setIsAlert({ type: "success", msg: "" }), 1500);
7878
}
7979
} catch (err) {

apps/OpenSign/src/pages/SignyourselfPdf.js

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -755,10 +755,10 @@ function SignYourSelf() {
755755
alert(t("something-went-wrong-mssg"));
756756
}
757757
}
758-
//change image width and height to 100/40 in png base64
759-
const getNewse64 = await changeImageWH(base64Sign);
760-
//remove suffiix of base64
761-
const suffixbase64 = getNewse64 && getNewse64.split(",").pop();
758+
//change image width and height to 300/120 in png base64
759+
const imagebase64 = await changeImageWH(base64Sign);
760+
//remove suffiix of base64 (without type)
761+
const suffixbase64 = imagebase64 && imagebase64.split(",").pop();
762762
const params = {
763763
pdfFile: base64Url,
764764
docId: documentId,

0 commit comments

Comments
 (0)