Skip to content

Commit 899678d

Browse files
feat: implement feature of copy widget to next of that widget for any widgets except signature,text,stamp,initial widgets
1 parent a94e67c commit 899678d

File tree

2 files changed

+95
-14
lines changed

2 files changed

+95
-14
lines changed

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

Lines changed: 27 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@ import PlaceholderBorder from "./PlaceholderBorder";
44
import { Rnd } from "react-rnd";
55
import {
66
defaultWidthHeight,
7+
handleCopyNextToWidget,
78
isMobile,
89
onChangeInput,
910
radioButtonWidget,
@@ -302,19 +303,35 @@ function Placeholder(props) {
302303
props.setWidgetType(props.pos.type);
303304
props.setCurrWidgetsDetails(props.pos);
304305
};
305-
//function ro set state value of onclick on widget's copy icon
306+
//function to set required state value onclick on widget's copy icon
306307
const handleCopyPlaceholder = (e) => {
307-
if (props.data && props?.pos?.type !== textWidget) {
308-
props.setSignerObjId(props?.data?.signerObjId);
309-
props.setUniqueId(props?.data?.Id);
310-
} else if (props.data && props.pos.type === textWidget) {
308+
e.stopPropagation();
309+
//condition to handle text widget signer obj id and unique id
310+
//when user click on copy icon of text widget in that condition text widget does not have any signerObjId
311+
//in that case i have to save in tempSignerId as a unique id of previous select signer's unique id
312+
//and on save or cancel button of copy all page popup i have set this temp signer Id in unique id
313+
if (props.data && props.pos.type === textWidget) {
311314
props.setTempSignerId(props.uniqueId);
312-
props.setSignerObjId(props?.data?.signerObjId);
313-
props.setUniqueId(props?.data?.Id);
314315
}
315-
e.stopPropagation();
316-
props.setIsPageCopy(true);
317-
props.setSignKey(props.pos.key);
316+
props.setSignerObjId(props?.data?.signerObjId);
317+
props.setUniqueId(props?.data?.Id);
318+
//checking widget's type and open widget copy modal for required widgets
319+
if (
320+
["signature", textWidget, "stamp", "initial"].includes(props.pos.type)
321+
) {
322+
props.setIsPageCopy(true);
323+
props.setSignKey(props.pos.key);
324+
} else {
325+
//function to create new widget next to just widget
326+
handleCopyNextToWidget(
327+
props.pos,
328+
props.pos.type,
329+
props.xyPostion,
330+
props.index,
331+
props.setXyPostion,
332+
props.data && props.data?.Id
333+
);
334+
}
318335
};
319336

320337
//function to save date and format on local array onchange date and onclick format

apps/OpenSign/src/constant/Utils.js

Lines changed: 68 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1255,13 +1255,14 @@ export const multiSignEmbed = async (
12551255
"email"
12561256
].includes(position.type);
12571257
if (position.type === "checkbox") {
1258-
let addYPosition, isCheck;
1258+
let addYPosition = 0,
1259+
isCheck;
12591260

12601261
if (position?.options?.values.length > 0) {
12611262
position?.options?.values.forEach((item, ind) => {
12621263
const checkboxRandomId = "checkbox" + randomId();
12631264
let yPosition;
1264-
const height = 10;
1265+
const height = 13;
12651266
if (
12661267
position?.options?.response &&
12671268
position?.options?.response?.length > 0
@@ -1282,14 +1283,14 @@ export const multiSignEmbed = async (
12821283
if (!position?.options?.isHideLabel) {
12831284
// below line of code is used to embed label with radio button in pdf
12841285
page.drawText(item, {
1285-
x: xPos(position) + 15,
1286+
x: xPos(position) + 17,
12861287
y: yPosition + 2,
12871288
size: height
12881289
});
12891290
}
12901291
checkbox.addToPage(page, {
12911292
x: xPos(position),
1292-
y: yPosition,
1293+
y: yPosition - 2,
12931294
width: height,
12941295
height: height
12951296
});
@@ -1702,3 +1703,66 @@ export const getYear = (date) => {
17021703
const newYear = new Date(date).getFullYear();
17031704
return newYear;
17041705
};
1706+
1707+
//function to create/copy widget next to already dropped widget
1708+
export const handleCopyNextToWidget = (
1709+
position,
1710+
widgetType,
1711+
xyPostion,
1712+
index,
1713+
setXyPostion,
1714+
userId
1715+
) => {
1716+
const isSigners = xyPostion.some((data) => data.signerPtr);
1717+
let filterSignerPos;
1718+
//get position of previous widget and create new widget next to that widget on same data except
1719+
// xPosition and key
1720+
let newpos = position;
1721+
const calculateXPosition =
1722+
parseInt(position.xPosition) +
1723+
defaultWidthHeight(widgetType).width +
1724+
resizeBorderExtraWidth();
1725+
const newId = randomId();
1726+
newpos = { ...newpos, xPosition: calculateXPosition, key: newId };
1727+
//if condition to create widget in request-sign flow
1728+
if (isSigners) {
1729+
if (userId) {
1730+
filterSignerPos = xyPostion.filter((data) => data.Id === userId);
1731+
}
1732+
const getPlaceHolder = filterSignerPos[0]?.placeHolder;
1733+
const getPageNumer = getPlaceHolder.filter(
1734+
(data) => data.pageNumber === index
1735+
);
1736+
const getXYdata = getPageNumer[0].pos;
1737+
getXYdata.push(newpos);
1738+
if (getPageNumer.length > 0) {
1739+
const newUpdateSignPos = getPlaceHolder.map((obj) => {
1740+
if (obj.pageNumber === index) {
1741+
return { ...obj, pos: getXYdata };
1742+
}
1743+
return obj;
1744+
});
1745+
1746+
const newUpdateSigner = xyPostion.map((obj) => {
1747+
if (obj.Id === userId) {
1748+
return { ...obj, placeHolder: newUpdateSignPos };
1749+
}
1750+
return obj;
1751+
});
1752+
1753+
setXyPostion(newUpdateSigner);
1754+
}
1755+
} else {
1756+
// else condition to create widget in sign-yourself flow
1757+
let getXYdata = xyPostion[index].pos;
1758+
getXYdata.push(newpos);
1759+
const updatePlaceholder = xyPostion.map((obj, ind) => {
1760+
if (ind === index) {
1761+
return { ...obj, pos: getXYdata };
1762+
}
1763+
return obj;
1764+
});
1765+
1766+
setXyPostion(updatePlaceholder);
1767+
}
1768+
};

0 commit comments

Comments
 (0)