From c5c001f0307d667354912e3b7e279f4c24ef28be Mon Sep 17 00:00:00 2001 From: RaktimaNXG Date: Fri, 8 Mar 2024 16:21:54 +0530 Subject: [PATCH] feat: year and month selection feature add on date widgets, wrong date embed on pdf issue fix --- .../src/components/pdf/Placeholder.js | 16 ++++++- .../src/components/pdf/PlaceholderType.js | 47 ++++++++++++++++++- apps/OpenSign/src/constant/Utils.js | 20 ++++++++ 3 files changed, 80 insertions(+), 3 deletions(-) diff --git a/apps/OpenSign/src/components/pdf/Placeholder.js b/apps/OpenSign/src/components/pdf/Placeholder.js index d1ec47e01..46e019a0c 100644 --- a/apps/OpenSign/src/components/pdf/Placeholder.js +++ b/apps/OpenSign/src/components/pdf/Placeholder.js @@ -54,7 +54,7 @@ function Placeholder(props) { useEffect(() => { //set default current date and default format MM/dd/yyyy - if (props.isPlaceholder || props.isSignYourself) { + if (props.isSignYourself) { const date = new Date(); const milliseconds = date.getTime(); const newDate = moment(milliseconds).format("MM/DD/YYYY"); @@ -63,6 +63,20 @@ function Placeholder(props) { 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 + }; + setSelectDate(dateObj); } // eslint-disable-next-line react-hooks/exhaustive-deps }, []); diff --git a/apps/OpenSign/src/components/pdf/PlaceholderType.js b/apps/OpenSign/src/components/pdf/PlaceholderType.js index 32ab4aa87..29c250458 100644 --- a/apps/OpenSign/src/components/pdf/PlaceholderType.js +++ b/apps/OpenSign/src/components/pdf/PlaceholderType.js @@ -1,5 +1,5 @@ import React, { useEffect, useState, forwardRef, useRef } from "react"; -import { onChangeInput } from "../../constant/Utils"; +import { getMonth, getYear, onChangeInput, range } from "../../constant/Utils"; import DatePicker from "react-datepicker"; import "react-datepicker/dist/react-datepicker.css"; import "../../styles/signature.css"; @@ -15,6 +15,21 @@ function PlaceholderType(props) { const inputRef = useRef(null); const [textValue, setTextValue] = useState(); const [selectedCheckbox, setSelectedCheckbox] = useState([]); + const years = range(1990, getYear(new Date()) + 16, 1); + const months = [ + "January", + "February", + "March", + "April", + "May", + "June", + "July", + "August", + "September", + "October", + "November", + "December" + ]; const validateExpression = (regexValidation) => { let regexObject = regexValidation; if (props.pos?.options.validation.type === "regex") { @@ -31,7 +46,6 @@ function PlaceholderType(props) { const handleInputBlur = () => { props.setDraggingEnabled(true); const validateType = props.pos?.options?.validation?.type; - let regexValidation; if (validateType) { switch (validateType) { @@ -293,6 +307,7 @@ function PlaceholderType(props) { isRadio ); }; + switch (type) { case "signature": return props.pos.SignUrl ? ( @@ -595,6 +610,34 @@ function PlaceholderType(props) { return (
( +
+ + +
+ )} disabled={ props.isNeedSign && props.data?.signerObjId !== props.signerObjId } diff --git a/apps/OpenSign/src/constant/Utils.js b/apps/OpenSign/src/constant/Utils.js index 3e320cd10..ceb828315 100644 --- a/apps/OpenSign/src/constant/Utils.js +++ b/apps/OpenSign/src/constant/Utils.js @@ -1517,3 +1517,23 @@ export const addDefaultSignatureImg = (xyPostion, defaultSignImg) => { } return xyDefaultPos; }; + +//function for create list of year for date widget +export const range = (start, end, step) => { + const range = []; + for (let i = start; i <= end; i += step) { + range.push(i); + } + return range; +}; +//function for get month +export const getMonth = (date) => { + const newMonth = new Date(date).getMonth(); + return newMonth; +}; + +//function for get year +export const getYear = (date) => { + const newYear = new Date(date).getFullYear(); + return newYear; +};