🔥 The free & Open Source DocuSign alternative
JavaScript digital-signaturedocument-signingdocusign-alternativedocusign-freee-signatureelectronic-signatureelectronic-signaturesesignesignaturehacktoberfestjavascriptlegaltechmongodbnodejsopen-sourcepdf-signpdf-signaturereactjsself-hostedsign-pdf-files
fix: widgets issue after placing on multiple pages
RaktimaNXG0e5cffa1fa60
diff --git a/apps/OpenSign/src/components/pdf/Placeholder.js b/apps/OpenSign/src/components/pdf/Placeholder.jsindex 2bdf2ed6e..b5b524059 100644--- a/apps/OpenSign/src/components/pdf/Placeholder.js+++ b/apps/OpenSign/src/components/pdf/Placeholder.js@@ -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 dateuseEffect(() => {//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 selectFormatconst 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) {<iclassName="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}/></>)}diff --git a/apps/OpenSign/src/components/pdf/PlaceholderCopy.js b/apps/OpenSign/src/components/pdf/PlaceholderCopy.jsindex 4ae92e18f..b57023bdf 100644--- a/apps/OpenSign/src/components/pdf/PlaceholderCopy.js+++ b/apps/OpenSign/src/components/pdf/PlaceholderCopy.js@@ -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 (<ModalUiisOpen={props.isPageCopy}@@ -220,7 +226,7 @@ function PlaceholderCopy(props) {<buttononClick={() => {handleApplyCopy();- props.setIsPageCopy(false);+ handleUniqueId();}}style={{ background: themeColor }}type="button"@@ -232,7 +238,9 @@ function PlaceholderCopy(props) {<buttontype="button"className="finishBtn cancelBtn"- onClick={() => props.setIsPageCopy(false)}+ onClick={() => {+ handleUniqueId();+ }}>Cancel</button>diff --git a/apps/OpenSign/src/components/pdf/PlaceholderType.js b/apps/OpenSign/src/components/pdf/PlaceholderType.jsindex 795d942bd..5dc0452d3 100644--- a/apps/OpenSign/src/components/pdf/PlaceholderType.js+++ b/apps/OpenSign/src/components/pdf/PlaceholderType.js@@ -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) {<textareaplaceholder="Enter label"rows={1}+ value={textValue}onChange={(e) => {+ setTextValue(e.target.value);onChangeInput(e.target.value,props.pos.key,diff --git a/apps/OpenSign/src/components/pdf/RenderPdf.js b/apps/OpenSign/src/components/pdf/RenderPdf.jsindex af72c3729..2ed1493eb 100644--- a/apps/OpenSign/src/components/pdf/RenderPdf.js+++ b/apps/OpenSign/src/components/pdf/RenderPdf.js@@ -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>);diff --git a/apps/OpenSign/src/constant/Utils.js b/apps/OpenSign/src/constant/Utils.jsindex ceb828315..088424b19 100644--- a/apps/OpenSign/src/constant/Utils.js+++ b/apps/OpenSign/src/constant/Utils.js@@ -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;diff --git a/apps/OpenSign/src/pages/PlaceHolderSign.js b/apps/OpenSign/src/pages/PlaceHolderSign.jsindex 9b46961c8..557b12abf 100644--- a/apps/OpenSign/src/pages/PlaceHolderSign.js+++ b/apps/OpenSign/src/pages/PlaceHolderSign.js@@ -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}/><DropdownWidgetOptiontype="radio"@@ -1639,6 +1640,8 @@ function PlaceHolderSign() {setSelectWidgetId={setSelectWidgetId}selectWidgetId={selectWidgetId}handleNameModal={setIsNameModal}+ setTempSignerId={setTempSignerId}+ uniqueId={uniqueId}/>)}</div>