fix: widgets issue after placing on multiple pages

This commit is contained in:
RaktimaNXG
2024-03-11 16:59:10 +05:30
parent 885b5287b4
commit 0e5cffa1fa
6 changed files with 129 additions and 71 deletions
+55 -42
View File
@@ -13,6 +13,8 @@ function Placeholder(props) {
const [selectDate, setSelectDate] = useState();
const [dateFormat, setDateFormat] = useState([]);
const [saveDateFormat, setSaveDateFormat] = useState("");
const [startDate, setStartDate] = useState();
const dateFormatArr = [
"L",
"DD-MM-YYYY",
@@ -52,36 +54,41 @@ function Placeholder(props) {
}
};
//useEffect for to set date and date format for all flow (signyour-self, request-sign,placeholder,template)
//checking if already have data and set else set new date
useEffect(() => {
//set default current date and default format MM/dd/yyyy
if (props.isSignYourself) {
const date = new Date();
const milliseconds = date.getTime();
const newDate = moment(milliseconds).format("MM/DD/YYYY");
const dateObj = {
date: newDate,
format: "MM/dd/YYYY"
};
setSelectDate(dateObj);
} else {
const defaultRes = props?.pos?.options?.response;
const defaultFormat = props.pos?.options?.validation?.format;
const updateDate = defaultRes
? new Date(props?.pos?.options?.response)
: new Date();
const dateFormat = defaultFormat ? defaultFormat : "MM/DD/YYYY";
const milliseconds = updateDate.getTime();
const newDate = moment(milliseconds).format(dateFormat);
const dateObj = {
date: newDate,
format: props.pos?.options?.validation?.format
? props.pos?.options?.validation?.format
: "MM/dd/YYYY"
};
setSelectDate(dateObj);
}
// if (props.isSignYourself) {
// const date = new Date();
// const milliseconds = date.getTime();
// const newDate = moment(milliseconds).format("MM/DD/YYYY");
// const dateObj = {
// date: newDate,
// format: "MM/dd/YYYY"
// };
// setSelectDate(dateObj);
// } else {
const defaultRes = props?.pos?.options?.response;
const defaultFormat = props.pos?.options?.validation?.format;
const updateDate = defaultRes
? new Date(props?.pos?.options?.response)
: new Date();
const dateFormat = defaultFormat ? defaultFormat : "MM/DD/YYYY";
const milliseconds = updateDate.getTime();
const newDate = moment(milliseconds).format(dateFormat);
const dateObj = {
date: newDate,
format: props.pos?.options?.validation?.format
? props.pos?.options?.validation?.format
: "MM/dd/YYYY"
};
setSelectDate(dateObj);
setStartDate(updateDate);
// }
// eslint-disable-next-line react-hooks/exhaustive-deps
}, []);
}, [props.index]);
//function for add selected date and format in selectFormat
const changeDateFormat = () => {
@@ -206,13 +213,27 @@ function Placeholder(props) {
props?.handleNameModal(true);
}
if (props.isPlaceholder) {
if (props.isPlaceholder && props.type !== "label") {
props.setUniqueId(props.data.Id);
}
props.setSignKey(props.pos.key);
props.setWidgetType(props.pos.type);
props.setCurrWidgetsDetails(props.pos);
};
const handleCopyPlaceholder = (e) => {
if (props.data && props?.pos?.type !== "label") {
props.setSignerObjId(props?.data?.signerObjId);
props.setUniqueId(props?.data?.Id);
} else if (props.data && props.pos.type === "label") {
props.setTempSignerId(props.uniqueId);
props.setSignerObjId(props?.data?.signerObjId);
props.setUniqueId(props?.data?.Id);
}
e.stopPropagation();
props.setIsPageCopy(true);
props.setSignKey(props.pos.key);
};
const PlaceholderIcon = () => {
return (
props.isShowBorder && (
@@ -365,22 +386,10 @@ function Placeholder(props) {
<i
className="fa-regular fa-copy signCopy"
onClick={(e) => {
if (props.data) {
props.setSignerObjId(props.data.signerObjId);
props.setUniqueId(props.data.Id);
}
e.stopPropagation();
props.setIsPageCopy(true);
props.setSignKey(props.pos.key);
handleCopyPlaceholder(e);
}}
onTouchEnd={(e) => {
if (props.data) {
props.setSignerObjId(props.data.signerObjId);
props.setUniqueId(props.data.Id);
}
e.stopPropagation();
props.setIsPageCopy(true);
props.setSignKey(props.pos.key);
handleCopyPlaceholder(e);
}}
style={{
color: "#188ae2",
@@ -618,6 +627,8 @@ function Placeholder(props) {
setSaveDateFormat={setSaveDateFormat}
saveDateFormat={saveDateFormat}
setValidateAlert={props.setValidateAlert}
setStartDate={setStartDate}
startDate={startDate}
/>
</div>
) : (
@@ -643,6 +654,8 @@ function Placeholder(props) {
setSaveDateFormat={setSaveDateFormat}
saveDateFormat={saveDateFormat}
setValidateAlert={props.setValidateAlert}
setStartDate={setStartDate}
startDate={startDate}
/>
</>
)}
@@ -180,7 +180,13 @@ function PlaceholderCopy(props) {
copyPlaceholder("first");
}
};
const handleUniqueId = () => {
if (props.widgetType === "label") {
props.setUniqueId(props?.tempSignerId);
props.setTempSignerId("");
}
props.setIsPageCopy(false);
};
return (
<ModalUi
isOpen={props.isPageCopy}
@@ -220,7 +226,7 @@ function PlaceholderCopy(props) {
<button
onClick={() => {
handleApplyCopy();
props.setIsPageCopy(false);
handleUniqueId();
}}
style={{ background: themeColor }}
type="button"
@@ -232,7 +238,9 @@ function PlaceholderCopy(props) {
<button
type="button"
className="finishBtn cancelBtn"
onClick={() => props.setIsPageCopy(false)}
onClick={() => {
handleUniqueId();
}}
>
Cancel
</button>
@@ -7,10 +7,8 @@ import RegexParser from "regex-parser";
function PlaceholderType(props) {
const type = props?.pos?.type;
const [selectOption, setSelectOption] = useState(
props.pos?.options?.defaultValue ? props.pos?.options?.defaultValue : ""
);
const [startDate, setStartDate] = useState(new Date());
const [selectOption, setSelectOption] = useState("");
const [validatePlaceholder, setValidatePlaceholder] = useState("");
const inputRef = useRef(null);
const [textValue, setTextValue] = useState();
@@ -89,10 +87,7 @@ function PlaceholderType(props) {
}
useEffect(() => {
if (props.isNeedSign && type === "date") {
const updateDate = new Date();
setStartDate(updateDate);
} else if (type && type === "checkbox" && props.isNeedSign) {
if (type && type === "checkbox" && props.isNeedSign) {
const isDefaultValue = props.pos.options?.defaultValue;
if (isDefaultValue) {
setSelectedCheckbox(isDefaultValue);
@@ -103,8 +98,20 @@ function PlaceholderType(props) {
checkRegularExpress(props.pos?.options?.validation?.type);
}
setTextValue(
props.pos?.options?.defaultValue ? props.pos?.options?.defaultValue : ""
props.pos?.options?.response
? props.pos?.options?.response
: props.pos?.options?.defaultValue
? props.pos?.options?.defaultValue
: ""
);
setSelectOption(
props.pos?.options?.response
? props.pos?.options?.response
: props.pos?.options?.defaultValue
? props.pos?.options?.defaultValue
: ""
);
// eslint-disable-next-line react-hooks/exhaustive-deps
}, []);
@@ -135,7 +142,7 @@ function PlaceholderType(props) {
}
}
// const updateDate = new Date(props.saveDateFormat);
setStartDate(updateDate);
props.setStartDate(updateDate);
const dateObj = {
date: props.saveDateFormat,
format: props.selectDate
@@ -646,17 +653,23 @@ function PlaceholderType(props) {
className="inputPlaceholder"
style={{ outlineColor: "#007bff" }}
selected={
startDate
? startDate
props?.startDate
? props?.startDate
: props.pos.options?.response &&
new Date(props.pos.options.response)
}
onChange={(date) => {
setStartDate(date);
props.setStartDate(date);
}}
popperPlacement="top-end"
customInput={<ExampleCustomInput />}
dateFormat={
// props.pos?.options?.validation?.format
// ? props.pos?.options?.validation?.format
// : props.selectDate
// ? props.selectDate?.format
// : "MM/dd/YYYY"
props.selectDate
? props.selectDate?.format
: props.pos?.options?.validation?.format
@@ -757,7 +770,9 @@ function PlaceholderType(props) {
<textarea
placeholder="Enter label"
rows={1}
value={textValue}
onChange={(e) => {
setTextValue(e.target.value);
onChangeInput(
e.target.value,
props.pos.key,
@@ -56,7 +56,9 @@ function RenderPdf({
selectWidgetId,
unSignedWidgetId,
setIsCheckbox,
handleNameModal
handleNameModal,
setTempSignerId,
uniqueId
}) {
const isMobile = window.innerWidth < 767;
const newWidth = containerWH.width;
@@ -393,6 +395,8 @@ function RenderPdf({
setSelectWidgetId={setSelectWidgetId}
selectWidgetId={selectWidgetId}
handleNameModal={handleNameModal}
setTempSignerId={setTempSignerId}
uniqueId={uniqueId}
/>
</React.Fragment>
);
@@ -574,6 +578,8 @@ function RenderPdf({
setSelectWidgetId={setSelectWidgetId}
selectWidgetId={selectWidgetId}
handleNameModal={handleNameModal}
setTempSignerId={setTempSignerId}
uniqueId={uniqueId}
/>
</React.Fragment>
);
+21 -8
View File
@@ -692,13 +692,27 @@ export const onChangeInput = (
const updatePosition = getXYdata.map((positionData) => {
if (positionData.key === signKey) {
return {
...positionData,
options: {
...positionData.options,
response: value
}
};
if (dateFormat) {
return {
...positionData,
options: {
...positionData.options,
response: value,
validation: {
type: "date-format",
format: dateFormat // This indicates the required date format explicitly.
}
}
};
} else {
return {
...positionData,
options: {
...positionData.options,
response: value
}
};
}
}
return positionData;
});
@@ -970,7 +984,6 @@ export const multiSignEmbed = async (
} else {
updateItem = item.pos;
}
const newWidth = containerWH.width;
const scale = isMobile ? pdfOriginalWidth / newWidth : 1;
const pageNo = item.pageNumber;
+7 -4
View File
@@ -76,6 +76,7 @@ function PlaceHolderSign() {
const [isResize, setIsResize] = useState(false);
const [zIndex, setZIndex] = useState(1);
const [signKey, setSignKey] = useState();
const [tempSignerId, setTempSignerId] = useState("");
const [pdfLoadFail, setPdfLoadFail] = useState({
status: false,
type: "load"
@@ -380,7 +381,6 @@ function PlaceHolderSign() {
pos: dropData
};
}
setSelectWidgetId(key);
if (signer) {
let filterSignerPos;
@@ -391,7 +391,6 @@ function PlaceHolderSign() {
}
const { blockColor, Role } = signer;
//adding placholder in existing signer pos array (placaholder)
if (filterSignerPos.length > 0) {
const getPlaceHolder = filterSignerPos[0].placeHolder;
@@ -442,7 +441,6 @@ function PlaceHolderSign() {
}
} else {
//adding new placeholder for selected signer in pos array (placeholder)
// const signerData = signerPos;
let placeHolderPos;
if (dragTypeValue === "label") {
placeHolderPos = {
@@ -1553,8 +1551,11 @@ function PlaceHolderSign() {
allPages={allPages}
pageNumber={pageNumber}
signKey={signKey}
// signerObjId={signerObjId}
Id={uniqueId}
widgetType={widgetType}
setUniqueId={setUniqueId}
tempSignerId={tempSignerId}
setTempSignerId={setTempSignerId}
/>
<DropdownWidgetOption
type="radio"
@@ -1639,6 +1640,8 @@ function PlaceHolderSign() {
setSelectWidgetId={setSelectWidgetId}
selectWidgetId={selectWidgetId}
handleNameModal={setIsNameModal}
setTempSignerId={setTempSignerId}
uniqueId={uniqueId}
/>
)}
</div>