Skip to content

Commit 5fa8a76

Browse files
authored
Merge pull request #1087 from OpenSignLabs/validation
2 parents db96dbb + 476dcf0 commit 5fa8a76

File tree

4 files changed

+85
-100
lines changed

4 files changed

+85
-100
lines changed

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

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -54,7 +54,7 @@ function DraftDocument() {
5454
navigate(`/recipientSignPdf/${data.objectId}`);
5555
}
5656
//checking if document has completed and signyour-self flow
57-
else if (!signerExist && !isPlaceholder) {
57+
else if ((!signerExist && !isPlaceholder) || data?.IsSignyourself) {
5858
navigate(`/signaturePdf/${data.objectId}`);
5959
}
6060
//checking if document has declined by someone

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

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -554,7 +554,7 @@ function RenderPdf({
554554
</React.Fragment>
555555
);
556556
})
557-
: xyPostion.map((data, ind) => {
557+
: xyPostion?.map((data, ind) => {
558558
// signyourself flow
559559
return (
560560
<React.Fragment key={ind}>

apps/OpenSign/src/pages/SignyourselfPdf.js

Lines changed: 62 additions & 98 deletions
Original file line numberDiff line numberDiff line change
@@ -165,7 +165,7 @@ function SignYourSelf() {
165165
})
166166
});
167167

168-
const index = xyPostion.findIndex((object) => {
168+
const index = xyPostion?.findIndex((object) => {
169169
return object.pageNumber === pageNumber;
170170
});
171171
// rowlevel={JSON.parse(localStorage.getItem("rowlevel"))}
@@ -211,7 +211,6 @@ function SignYourSelf() {
211211

212212
// Use setTimeout to wait for the transition to complete
213213
const timer = setTimeout(updateSize, 100); // match the transition duration
214-
215214
return () => clearTimeout(timer);
216215
// eslint-disable-next-line react-hooks/exhaustive-deps
217216
}, [divRef.current, isHeader]);
@@ -226,6 +225,11 @@ function SignYourSelf() {
226225
if (documentData && documentData.length > 0) {
227226
setPdfDetails(documentData);
228227
setExtUserId(documentData[0]?.ExtUserPtr?.objectId);
228+
const placeholders =
229+
documentData[0]?.Placeholders?.length > 0
230+
? documentData[0]?.Placeholders
231+
: [];
232+
setXyPostion(placeholders);
229233
const url = documentData[0] && documentData[0]?.URL;
230234
if (url) {
231235
//convert document url in array buffer format to use embed widgets in pdf using pdf-lib
@@ -238,21 +242,17 @@ function SignYourSelf() {
238242
} else {
239243
setHandleError(t("something-went-wrong-mssg"));
240244
}
241-
isCompleted =
242-
documentData[0].IsCompleted && documentData[0].IsCompleted;
245+
isCompleted = documentData?.[0]?.IsCompleted;
243246
if (isCompleted) {
244247
setIsCelebration(true);
245-
setTimeout(() => {
246-
setIsCelebration(false);
247-
}, 5000);
248+
setTimeout(() => setIsCelebration(false), 5000);
248249
setIsCompleted(true);
249250
setPdfUrl(documentData[0].SignedUrl);
250-
const alreadySign = {
251-
status: true,
252-
mssg: t("document-signed-alert")
253-
};
254251
if (showComplete) {
255-
setShowAlreadySignDoc(alreadySign);
252+
setShowAlreadySignDoc({
253+
status: true,
254+
mssg: t("document-signed-alert")
255+
});
256256
} else {
257257
setIsUiLoading(false);
258258
setIsSignPad(false);
@@ -265,17 +265,11 @@ function SignYourSelf() {
265265
documentData === "Error: Something went wrong!" ||
266266
(documentData.result && documentData.result.error)
267267
) {
268-
const loadObj = {
269-
isLoad: false
270-
};
271268
setHandleError(t("something-went-wrong-mssg"));
272-
setIsLoading(loadObj);
269+
setIsLoading({ isLoad: false });
273270
} else {
274271
setHandleError(t("no-data-avaliable"));
275-
const loadObj = {
276-
isLoad: false
277-
};
278-
setIsLoading(loadObj);
272+
setIsLoading({ isLoad: false });
279273
}
280274
//function to get default signatur eof current user from `contracts_Signature` class
281275
const defaultSignRes = await getDefaultSignature(jsonSender.objectId);
@@ -284,17 +278,12 @@ function SignYourSelf() {
284278
setMyInitial(defaultSignRes?.res?.defaultInitial);
285279
} else if (defaultSignRes?.status === "error") {
286280
setHandleError("Error: Something went wrong!");
287-
setIsLoading({
288-
isLoad: false
289-
});
281+
setIsLoading({ isLoad: false });
290282
}
291283
const contractUsersRes = await contractUsers();
292284
if (contractUsersRes === "Error: Something went wrong!") {
293-
const loadObj = {
294-
isLoad: false
295-
};
296285
setHandleError(t("something-went-wrong-mssg"));
297-
setIsLoading(loadObj);
286+
setIsLoading({ isLoad: false });
298287
} else if (contractUsersRes[0] && contractUsersRes.length > 0) {
299288
setActiveMailAdapter(contractUsersRes[0]?.active_mail_adapter);
300289
setContractName("_Users");
@@ -374,51 +363,32 @@ function SignYourSelf() {
374363
const addWidgetOptions = (type) => {
375364
switch (type) {
376365
case "signature":
377-
return {
378-
name: "signature"
379-
};
366+
return { name: "signature" };
380367
case "stamp":
381-
return {
382-
name: "stamp"
383-
};
368+
return { name: "stamp" };
384369
case "checkbox":
385-
return {
386-
name: "checkbox"
387-
};
370+
return { name: "checkbox" };
388371
case textWidget:
389-
return {
390-
name: "text"
391-
};
372+
return { name: "text" };
392373
case "initials":
393-
return {
394-
name: "initials"
395-
};
374+
return { name: "initials" };
396375
case "name":
397376
return {
398377
name: "name",
399378
defaultValue: getWidgetValue(type),
400-
validation: {
401-
type: "text",
402-
pattern: ""
403-
}
379+
validation: { type: "text", pattern: "" }
404380
};
405381
case "company":
406382
return {
407383
name: "company",
408384
defaultValue: getWidgetValue(type),
409-
validation: {
410-
type: "text",
411-
pattern: ""
412-
}
385+
validation: { type: "text", pattern: "" }
413386
};
414387
case "job title":
415388
return {
416389
name: "job title",
417390
defaultValue: getWidgetValue(type),
418-
validation: {
419-
type: "text",
420-
pattern: ""
421-
}
391+
validation: { type: "text", pattern: "" }
422392
};
423393
case "date":
424394
return {
@@ -427,17 +397,12 @@ function SignYourSelf() {
427397
validation: { format: "MM/dd/yyyy", type: "date-format" }
428398
};
429399
case "image":
430-
return {
431-
name: "image"
432-
};
400+
return { name: "image" };
433401
case "email":
434402
return {
435403
name: "email",
436404
defaultValue: getWidgetValue(type),
437-
validation: {
438-
type: "email",
439-
pattern: ""
440-
}
405+
validation: { type: "email", pattern: "" }
441406
};
442407
default:
443408
return {};
@@ -449,7 +414,7 @@ function SignYourSelf() {
449414
const key = randomId();
450415
let dropData = [];
451416
let dropObj = {};
452-
let filterDropPos = xyPostion.filter(
417+
let filterDropPos = xyPostion?.filter(
453418
(data) => data.pageNumber === pageNumber
454419
);
455420
const dragTypeValue = item?.text ? item.text : monitor.type;
@@ -486,7 +451,6 @@ function SignYourSelf() {
486451
Height: getHeight / (containerScale * scale),
487452
options: addWidgetOptions(dragTypeValue)
488453
};
489-
490454
dropData.push(dropObj);
491455
} else {
492456
//This method returns the offset of the current pointer (mouse) position relative to the client viewport.
@@ -519,25 +483,18 @@ function SignYourSelf() {
519483
options: addWidgetOptions(dragTypeValue),
520484
scale: containerScale
521485
};
522-
523486
dropData.push(dropObj);
524487
}
525-
if (filterDropPos.length > 0) {
526-
const index = xyPostion.findIndex((object) => {
488+
if (filterDropPos?.length > 0) {
489+
const index = xyPostion?.findIndex((object) => {
527490
return object.pageNumber === pageNumber;
528491
});
529-
const updateData = filterDropPos[0].pos;
492+
const updateData = filterDropPos?.[0].pos;
530493
const newSignPos = updateData.concat(dropData);
531-
let xyPos = {
532-
pageNumber: pageNumber,
533-
pos: newSignPos
534-
};
535-
xyPostion.splice(index, 1, xyPos);
494+
let xyPos = { pageNumber: pageNumber, pos: newSignPos };
495+
xyPostion?.splice(index, 1, xyPos);
536496
} else {
537-
const xyPos = {
538-
pageNumber: pageNumber,
539-
pos: dropData
540-
};
497+
const xyPos = { pageNumber: pageNumber, pos: dropData };
541498
setXyPostion((prev) => [...prev, xyPos]);
542499
}
543500

@@ -549,7 +506,6 @@ function SignYourSelf() {
549506
) {
550507
setIsSignPad(true);
551508
}
552-
553509
if (dragTypeValue === "stamp" || dragTypeValue === "image") {
554510
setIsStamp(true);
555511
} else if (dragTypeValue === "initials") {
@@ -612,6 +568,30 @@ function SignYourSelf() {
612568
setIsVerifyModal(true);
613569
await handleSendOTP(Parse.User.current().getEmail());
614570
};
571+
useEffect(() => {
572+
const timer = setTimeout(() => {
573+
if (xyPostion?.length > 0) {
574+
autosavedetails();
575+
}
576+
}, 2000);
577+
return () => clearTimeout(timer);
578+
// eslint-disable-next-line react-hooks/exhaustive-deps
579+
}, [xyPostion]);
580+
581+
// `autosavedetails` is used to save doc details after every 2 sec when changes are happern in placeholder like drag-drop widgets, remove signers
582+
const autosavedetails = async () => {
583+
try {
584+
const docCls = new Parse.Object("contracts_Document");
585+
docCls.id = documentId;
586+
docCls.set("Placeholders", xyPostion);
587+
docCls.set("IsSignyourself", true);
588+
const res = await docCls.save();
589+
console.log("Res", res);
590+
} catch (e) {
591+
console.log("error", e);
592+
alert(t("something-went-wrong-mssg"));
593+
}
594+
};
615595
//function for send placeholder's co-ordinate(x,y) position embed signature url or stamp url
616596
async function embedWidgetsData() {
617597
//check current user email is verified or not
@@ -791,7 +771,6 @@ function SignYourSelf() {
791771
const getNewse64 = await changeImageWH(base64Sign);
792772
//remove suffiix of base64
793773
const suffixbase64 = getNewse64 && getNewse64.split(",").pop();
794-
795774
const params = {
796775
pdfFile: base64Url,
797776
docId: documentId,
@@ -825,10 +804,10 @@ function SignYourSelf() {
825804
containerWH
826805
);
827806
if (dragKey >= 0) {
828-
const filterDropPos = xyPostion.filter(
807+
const filterDropPos = xyPostion?.filter(
829808
(data) => data.pageNumber === pageNumber
830809
);
831-
if (filterDropPos.length > 0) {
810+
if (filterDropPos?.length > 0) {
832811
const getXYdata = xyPostion[index].pos;
833812
const getPosData = getXYdata;
834813
const addSign = getPosData.map((url) => {
@@ -899,15 +878,11 @@ function SignYourSelf() {
899878
setIsSignPad(false);
900879
setIsImageSelect(false);
901880
setImage();
902-
903881
if (isDefaultSign) {
904882
const img = new Image();
905883
img.src = defaultSignImg;
906884
if (img.complete) {
907-
imgWH = {
908-
width: img.width,
909-
height: img.height
910-
};
885+
imgWH = { width: img.width, height: img.height };
911886
}
912887
}
913888
const getUpdatePosition = onSaveSign(
@@ -932,19 +907,11 @@ function SignYourSelf() {
932907
const touch = e.touches[0]; // Get the first touch point
933908
mouseX = touch.clientX - divRect.left;
934909
mouseY = touch.clientY - divRect.top;
935-
setSignBtnPosition([
936-
{
937-
xPos: mouseX,
938-
yPos: mouseY
939-
}
940-
]);
910+
setSignBtnPosition([{ xPos: mouseX, yPos: mouseY }]);
941911
} else {
942912
mouseX = e.clientX - divRect.left;
943913
mouseY = e.clientY - divRect.top;
944-
const xyPosition = {
945-
xPos: mouseX,
946-
yPos: mouseY
947-
};
914+
const xyPosition = { xPos: mouseX, yPos: mouseY };
948915
setXYSignature(xyPosition);
949916
}
950917
};
@@ -962,9 +929,7 @@ function SignYourSelf() {
962929
const handleDeleteSign = (key) => {
963930
setCurrWidgetsDetails({});
964931
const updateResizeData = [];
965-
966932
let filterData = xyPostion[index].pos.filter((data) => data.key !== key);
967-
968933
//delete and update block position
969934
if (filterData.length > 0) {
970935
updateResizeData.push(filterData);
@@ -1243,7 +1208,6 @@ function SignYourSelf() {
12431208
<Confetti width={window.innerWidth} height={window.innerHeight} />
12441209
</div>
12451210
)}
1246-
12471211
<div className="relative op-card overflow-hidden flex flex-col md:flex-row justify-between bg-base-300">
12481212
{!isEmailVerified && (
12491213
<VerifyEmail
Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
/**
2+
*
3+
* @param {Parse} Parse
4+
*/
5+
exports.up = async Parse => {
6+
const className = 'contracts_Document';
7+
const schema = new Parse.Schema(className);
8+
schema.addBoolean('IsSignyourself');
9+
return schema.update();
10+
};
11+
12+
/**
13+
*
14+
* @param {Parse} Parse
15+
*/
16+
exports.down = async Parse => {
17+
const className = 'contracts_Document';
18+
const schema = new Parse.Schema(className);
19+
schema.deleteField('IsSignyourself');
20+
return schema.update();
21+
};

0 commit comments

Comments
 (0)