Skip to content

Commit a24ebe2

Browse files
Merge pull request #534 from OpenSignLabs/widget_copy
feat: implement feature of copy widget to next of that widget for any widgets except `signature,text,stamp,initial` widgets.
2 parents 076a0f5 + 3e664bf commit a24ebe2

File tree

3 files changed

+95
-9
lines changed

3 files changed

+95
-9
lines changed

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

Lines changed: 26 additions & 4 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,8 +303,14 @@ 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) => {
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+
307314
if (props.data && props?.pos?.type !== textWidget) {
308315
props.setSignerObjId(props?.data?.signerObjId);
309316
props.setUniqueId(props?.data?.Id);
@@ -312,9 +319,24 @@ function Placeholder(props) {
312319
props.setSignerObjId(props?.data?.signerObjId);
313320
props.setUniqueId(props?.data?.Id);
314321
}
315-
e.stopPropagation();
316-
props.setIsPageCopy(true);
317-
props.setSignKey(props.pos.key);
322+
323+
//checking widget's type and open widget copy modal for required widgets
324+
if (
325+
["signature", textWidget, "stamp", "initial"].includes(props.pos.type)
326+
) {
327+
props.setIsPageCopy(true);
328+
props.setSignKey(props.pos.key);
329+
} else {
330+
//function to create new widget next to just widget
331+
handleCopyNextToWidget(
332+
props.pos,
333+
props.pos.type,
334+
props.xyPostion,
335+
props.index,
336+
props.setXyPostion,
337+
props.data && props.data?.Id
338+
);
339+
}
318340
};
319341

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

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

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -353,7 +353,7 @@ function PlaceholderType(props) {
353353
<div key={ind} className="flex items-center text-center gap-0.5">
354354
<input
355355
style={{
356-
width: props.pos.Width,
356+
// width: props.pos.Width,
357357
display: "flex",
358358
justifyContent: "center",
359359
marginTop: ind === 0 ? 0 : "5px"

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 - 3,
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)