Skip to content

Commit 5c06ff4

Browse files
Merge pull request #1613 from OpenSignLabs/updates-13494498125
Merge pull request #343 from OpenSignLabs/staging
2 parents 796ff05 + 1899acf commit 5c06ff4

5 files changed

Lines changed: 94 additions & 123 deletions

File tree

apps/OpenSign/package-lock.json

Lines changed: 52 additions & 62 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

apps/OpenSign/package.json

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@
1313
"css-minimizer-webpack-plugin": "^7.0.0",
1414
"file-saver": "^2.0.5",
1515
"i18next": "^23.16.8",
16-
"i18next-browser-languagedetector": "^8.0.4",
16+
"i18next-browser-languagedetector": "^8.0.2",
1717
"i18next-http-backend": "^3.0.1",
1818
"jszip": "^3.10.1",
1919
"jwt-decode": "^4.0.0",
@@ -118,7 +118,7 @@
118118
"pretty-quick": "^4.0.0",
119119
"tailwindcss": "^3.4.17",
120120
"terser-webpack-plugin": "^5.3.11",
121-
"webpack-cli": "^6.0.1"
121+
"webpack-cli": "^5.1.4"
122122
},
123123
"overrides": {
124124
"nth-check": "$nth-check",

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

Lines changed: 30 additions & 47 deletions
Original file line numberDiff line numberDiff line change
@@ -74,25 +74,22 @@ const changeDateToMomentFormat = (format) => {
7474
return "L";
7575
}
7676
};
77-
78-
//function to get default date
79-
const getDefaultdate = (selectedDate, format = "dd-MM-yyyy") => {
77+
//function to get default format
78+
const getDefaultFormat = (dateFormat) => dateFormat || "MM/dd/yyyy";
79+
//function to convert formated date to new Date() format
80+
const getDefaultDate = (dateStr, format) => {
81+
//get valid date format for moment to convert formated date to new Date() format
82+
const formats = changeDateToMomentFormat(format);
83+
const parsedDate = moment(dateStr, formats);
8084
let date;
81-
if (format && format === "dd-MM-yyyy") {
82-
const newdate = selectedDate
83-
? selectedDate
84-
: moment(new Date()).format(changeDateToMomentFormat(format));
85-
const [day, month, year] = newdate.split("-");
86-
date = new Date(`${year}-${month}-${day}`);
85+
if (parsedDate.isValid()) {
86+
date = new Date(parsedDate.toISOString());
87+
return date;
8788
} else {
88-
date = new Date(selectedDate);
89+
date = new Date();
90+
return date;
8991
}
90-
const value = date;
91-
return value;
9292
};
93-
//function to get default format
94-
const getDefaultFormat = (dateFormat) => dateFormat || "MM/dd/yyyy";
95-
9693
function Placeholder(props) {
9794
//'isTouchDevice' is used to detect whether a device has a touchscreen or is mouse-based
9895
const isTouchDevice = navigator.maxTouchPoints > 0;
@@ -104,28 +101,16 @@ function Placeholder(props) {
104101
const holdTimeout = useRef(null);
105102
const startTime = useRef(null); // Track when the user starts holdings
106103
const [isDisableDragging, setIsDisableDragging] = useState(true);
107-
const [selectDate, setSelectDate] = useState({
108-
date:
109-
props.pos.type === "date"
110-
? moment(
111-
getDefaultdate(
112-
props?.pos?.options?.response,
113-
props.pos?.options?.validation?.format
114-
).getTime()
115-
).format(
116-
changeDateToMomentFormat(props.pos?.options?.validation?.format)
117-
)
118-
: "",
119-
format:
120-
props.pos.type === "date"
121-
? getDefaultFormat(props.pos?.options?.validation?.format)
122-
: ""
123-
});
104+
const [selectDate, setSelectDate] = useState({});
124105
const [dateFormat, setDateFormat] = useState([]);
125106
const [clickonWidget, setClickonWidget] = useState({});
126107
const [startDate, setStartDate] = useState(
127-
props.pos.type === "date" &&
128-
getDefaultdate(new Date(), props.pos?.options?.validation?.format)
108+
props?.pos?.options?.response
109+
? getDefaultDate(
110+
props?.pos?.options?.response,
111+
props.pos?.options?.validation?.format
112+
)
113+
: new Date()
129114
);
130115
const [getCheckboxRenderWidth, setGetCheckboxRenderWidth] = useState({
131116
width: null,
@@ -164,7 +149,6 @@ function Placeholder(props) {
164149

165150
return () => clearTimeout(timer);
166151
}, [props.pos]);
167-
168152
useEffect(() => {
169153
const onOutsideClick = () => {
170154
if (!isDraggingEnabled) {
@@ -476,7 +460,7 @@ function Placeholder(props) {
476460
const isDateChange = true;
477461
const dateObj = {
478462
date: startDate,
479-
format: selectDate.format
463+
format: getDefaultFormat(props.pos?.options?.validation?.format)
480464
};
481465
handleSaveDate(dateObj, isDateChange); //function to save date and format in local array
482466
}
@@ -485,19 +469,18 @@ function Placeholder(props) {
485469
//function to save date and format on local array onchange date and onclick format
486470
const handleSaveDate = (data, isDateChange) => {
487471
let updateDate = data.date;
488-
//check if date change by user
489-
if (isDateChange) {
490-
//`changeDateToMomentFormat` is used to convert date as per required to moment package
491-
updateDate = moment(data.date).format(
492-
changeDateToMomentFormat(data.format)
472+
let date;
473+
if (data?.format === "dd-MM-yyyy") {
474+
date = isDateChange
475+
? moment(updateDate).format(changeDateToMomentFormat(data.format))
476+
: updateDate;
477+
} else {
478+
//using moment package is used to change date as per the format provided in selectDate obj e.g. - MM/dd/yyyy -> 03/12/2024
479+
const newDate = new Date(updateDate);
480+
date = moment(newDate.getTime()).format(
481+
changeDateToMomentFormat(data?.format)
493482
);
494483
}
495-
//using moment package is used to change date as per the format provided in selectDate obj e.g. - MM/dd/yyyy -> 03/12/2024
496-
//`getDefaultdate` is used to convert update date in new Date() format
497-
const date = moment(
498-
getDefaultdate(updateDate, data?.format).getTime()
499-
).format(changeDateToMomentFormat(data?.format));
500-
501484
//`onChangeInput` is used to save data related to date in a placeholder field
502485
onChangeInput(
503486
date,

0 commit comments

Comments
 (0)