Skip to content

Commit

Permalink
fix: date widgets issue after place change all widgets details which …
Browse files Browse the repository at this point in the history
…are already placed
  • Loading branch information
raktima-opensignlabs committed Feb 21, 2024
1 parent d4fabf0 commit 8308376
Show file tree
Hide file tree
Showing 7 changed files with 73 additions and 149 deletions.
29 changes: 0 additions & 29 deletions microfrontends/SignDocuments/src/Component/SignYourselfPdf.js
Original file line number Diff line number Diff line change
Expand Up @@ -128,32 +128,6 @@ function SignYourSelf() {
})
});

const [{ isDragSignatureSS }, dragSignatureSS] = useDrag({
type: "BOX",

item: {
type: "BOX",
id: 3,
text: "drag me"
},
collect: (monitor) => ({
isDragSignatureSS: !!monitor.isDragging()
})
});

const [, dragStampSS] = useDrag({
type: "BOX",
item: {
type: "BOX",
id: 4,
text: "drag me"
},

collect: (monitor) => ({
isDragStampSS: !!monitor.isDragging()
})
});

const index = xyPostion.findIndex((object) => {
return object.pageNumber === pageNumber;
});
Expand Down Expand Up @@ -1046,9 +1020,6 @@ function SignYourSelf() {
dragStamp={dragStamp}
dragRef={dragRef}
isDragStamp={isDragStamp}
isDragSignatureSS={isDragSignatureSS}
dragSignatureSS={dragSignatureSS}
dragStampSS={dragStampSS}
handleAllDelete={handleAllDelete}
xyPostion={xyPostion}
isSignYourself={true}
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import React, { useRef, useState } from "react";
import React from "react";
import { getWidgetType } from "../../utils/Utils";

function AllWidgets(props) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -402,7 +402,7 @@ function PlaceholderType(props) {
tabIndex="0"
ref={inputRef}
placeholder={"name"}
style={{ fontSize: calculateFontSize() }}
style={{ fontSize: calculateFontSize(), textAlign: "center" }}
className="inputPlaceholder"
type="text"
value={
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,7 @@ function Header({
setIsEditTemplate
}) {
const filterPrefill =
signerPos && signerPos.filter((data) => data.Role !== "prefill");
signerPos && signerPos?.filter((data) => data.Role !== "prefill");
const isMobile = window.innerWidth < 767;
const navigate = useNavigate();
const isGuestSigner = localStorage.getItem("isGuestSigner");
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -495,6 +495,8 @@ function RenderPdf({
>
<EmailToast isShow={successEmail} />
{pdfLoadFail.status &&
signerPos &&
signerPos.length > 0 &&
(pdfRequest
? signerPos.map((data, key) => {
return (
Expand Down
175 changes: 65 additions & 110 deletions microfrontends/SignDocuments/src/Component/placeHolderSign.js
Original file line number Diff line number Diff line change
Expand Up @@ -151,30 +151,6 @@ function PlaceHolderSign() {
})
});

const [{ isDragSignatureSS }, dragSignatureSS] = useDrag({
type: "BOX",
item: {
id: 3,
text: "signature"
},

collect: (monitor) => ({
isDragSignatureSS: !!monitor.isDragging()
})
});

const [, dragStampSS] = useDrag({
type: "BOX",
item: {
id: 4,
text: "stamp"
},

collect: (monitor) => ({
isDragStampSS: !!monitor.isDragging()
})
});

const rowLevel =
localStorage.getItem("rowlevel") &&
JSON.parse(localStorage.getItem("rowlevel"));
Expand Down Expand Up @@ -282,6 +258,7 @@ function PlaceHolderSign() {
blockColor: x.blockColor
};
});

setSignerPos(documentData[0].Placeholders);
setSignersData(updatedSigners);
setIsSelectId(0);
Expand Down Expand Up @@ -362,6 +339,7 @@ function PlaceHolderSign() {
let dropData = [];
let placeHolder;
const dragTypeValue = item?.text ? item.text : monitor.type;

if (item === "onclick") {
const dropObj = {
//onclick put placeholder center on pdf
Expand Down Expand Up @@ -411,7 +389,7 @@ function PlaceHolderSign() {
scale: scale,
isMobile: isMobile,
zIndex: posZIndex,
type: item.text,
type: dragTypeValue,
widgetValue:
dragTypeValue === "checkbox"
? false
Expand All @@ -428,10 +406,16 @@ function PlaceHolderSign() {
}

setSelectWidgetId(key);
if (signer && dragTypeValue !== "label") {
let filterSignerPos = signerPos.filter((data) => data.Id === uniqueId);
if (signer) {
let filterSignerPos;
if (dragTypeValue === "label") {
filterSignerPos = signerPos.filter((data) => data.Role === "prefill");
} else {
filterSignerPos = signerPos.filter((data) => data.Id === uniqueId);
}

const { blockColor, Role } = signer;

//adding placholder in existing signer pos array (placaholder)
if (filterSignerPos.length > 0) {
const getPlaceHolder = filterSignerPos[0].placeHolder;
Expand All @@ -451,50 +435,73 @@ function PlaceHolderSign() {
pos: newSignPos
};
updatePlace.push(xyPos);
const updatesignerPos = signerPos.map((x) =>
x.Id === uniqueId ? { ...x, placeHolder: updatePlace } : x
);
let updatesignerPos;
if (dragTypeValue === "label") {
updatesignerPos = signerPos.map((x) =>
x.Role === "prefill" ? { ...x, placeHolder: updatePlace } : x
);
} else {
updatesignerPos = signerPos.map((x) =>
x.Id === uniqueId ? { ...x, placeHolder: updatePlace } : x
);
}

setSignerPos(updatesignerPos);
} else {
const updatesignerPos = signerPos.map((x) =>
x.Id === uniqueId
? { ...x, placeHolder: [...x.placeHolder, placeHolder] }
: x
);
let updatesignerPos;
if (dragTypeValue === "label") {
updatesignerPos = signerPos.map((x) =>
x.Role === "prefill"
? { ...x, placeHolder: [...x.placeHolder, placeHolder] }
: x
);
} else {
updatesignerPos = signerPos.map((x) =>
x.Id === uniqueId
? { ...x, placeHolder: [...x.placeHolder, placeHolder] }
: x
);
}
setSignerPos(updatesignerPos);
}
} else {
//adding new placeholder for selected signer in pos array (placeholder)
// const signerData = signerPos;
let placeHolderPos;
if (contractName) {
placeHolderPos = {
signerPtr: {
__type: "Pointer",
className: `${contractName}`,
objectId: signerObjId
},
signerObjId: signerObjId,
blockColor: blockColor ? blockColor : color[isSelectListId],
placeHolder: [placeHolder],
Role: Role ? Role : roleName,
Id: uniqueId
};
} else {
if (dragTypeValue === "label") {
placeHolderPos = {
signerPtr: {},
signerObjId: "",
blockColor: blockColor ? blockColor : color[isSelectListId],
blockColor: "#f58f8c",
placeHolder: [placeHolder],
Role: Role ? Role : roleName,
Id: uniqueId
Role: "prefill",
Id: key
};
} else {
if (contractName) {
placeHolderPos = {
signerPtr: {
__type: "Pointer",
className: `${contractName}`,
objectId: signerObjId
},
signerObjId: signerObjId,
blockColor: blockColor ? blockColor : color[isSelectListId],
placeHolder: [placeHolder],
Role: Role ? Role : roleName,
Id: uniqueId
};
} else {
placeHolderPos = {
signerPtr: {},
signerObjId: "",
blockColor: blockColor ? blockColor : color[isSelectListId],
placeHolder: [placeHolder],
Role: Role ? Role : roleName,
Id: uniqueId
};
}
}

// signerData.push(placeHolderPos);
console.log("signersddata", placeHolderPos);
// setSignerPos(signerData);
setSignerPos((prev) => [...prev, placeHolderPos]);
}
if (dragTypeValue === "dropdown") {
Expand All @@ -506,55 +513,6 @@ function PlaceHolderSign() {
}
setWidgetType(dragTypeValue);
setSignKey(key);
} else if (dragTypeValue === "label") {
console.log("go here");
let filterSignerPos = signerPos.filter(
(data) => data.Role === "prefill"
);

if (filterSignerPos.length > 0) {
const getPlaceHolder = filterSignerPos[0].placeHolder;
const updatePlace = getPlaceHolder.filter(
(data) => data.pageNumber !== pageNumber
);
const getPageNumer = getPlaceHolder.filter(
(data) => data.pageNumber === pageNumber
);

//add entry of position for same signer on multiple page
if (getPageNumer.length > 0) {
const getPos = getPageNumer[0].pos;
const newSignPos = getPos.concat(dropData);
let xyPos = {
pageNumber: pageNumber,
pos: newSignPos
};
updatePlace.push(xyPos);
const updatesignerPos = signerPos.map((x) =>
x.Role === "prefill" ? { ...x, placeHolder: updatePlace } : x
);
setSignerPos(updatesignerPos);
} else {
const updatesignerPos = signerPos.map((x) =>
x.Role === "prefill"
? { ...x, placeHolder: [...x.placeHolder, placeHolder] }
: x
);
setSignerPos(updatesignerPos);
}
} else {
let placeHolderPos;
placeHolderPos = {
signerPtr: {},
signerObjId: "",
blockColor: "#f58f8c",
placeHolder: [placeHolder],
Role: "prefill",
Id: key
};
setSignerPos((prev) => [...prev, placeHolderPos]);
}
setSignKey(key);
}
}
};
Expand All @@ -578,7 +536,6 @@ function PlaceHolderSign() {
setIsDragging(true);
};

console.log("signerpos", signerPos);
//function for set and update x and y postion after drag and drop signature tab
const handleStop = (event, dragElement, signerId, key) => {
console.log("handle stop");
Expand Down Expand Up @@ -690,7 +647,7 @@ function PlaceHolderSign() {
}
return obj;
});

console.log("signerpos3");
setSignerPos(newUpdateSigner);
} else {
const updateFilter = signerPos.filter((data) => data.Id !== Id);
Expand Down Expand Up @@ -1150,6 +1107,7 @@ function PlaceHolderSign() {
}
return { ...x };
});

setSignerPos(updatePlaceHolder);

const updateSigner = signersdata.map((x) => {
Expand Down Expand Up @@ -1587,9 +1545,6 @@ function PlaceHolderSign() {
dragRef={dragRef}
isDragStamp={isDragStamp}
isSignYourself={false}
isDragSignatureSS={isDragSignatureSS}
dragSignatureSS={dragSignatureSS}
dragStampSS={dragStampSS}
addPositionOfSignature={addPositionOfSignature}
signerPos={signerPos}
signersdata={signersdata}
Expand Down
10 changes: 3 additions & 7 deletions microfrontends/SignDocuments/src/utils/Utils.js
Original file line number Diff line number Diff line change
Expand Up @@ -94,8 +94,6 @@ export const onChangeInput = (
if (isSigners) {
if (userId) {
filterSignerPos = xyPostion.filter((data) => data.Id === userId);
} else {
filterSignerPos = xyPostion.filter((data) => data.Role === "prefill");
}

const getPlaceHolder = filterSignerPos[0]?.placeHolder;
Expand Down Expand Up @@ -129,17 +127,15 @@ export const onChangeInput = (
return url;
});

const newUpdateSignPos = getPlaceHolder.map((obj, ind) => {
const newUpdateSignPos = getPlaceHolder.map((obj) => {
if (obj.pageNumber === index) {
return { ...obj, pos: addSignPos };
}
return obj;
});

const newUpdateSigner = xyPostion.map((obj, ind) => {
if (obj.Role === "prefill") {
return { ...obj, placeHolder: newUpdateSignPos };
} else if (obj.Id === userId) {
const newUpdateSigner = xyPostion.map((obj) => {
if (obj.Id === userId) {
return { ...obj, placeHolder: newUpdateSignPos };
}
return obj;
Expand Down

0 comments on commit 8308376

Please sign in to comment.