Skip to content

Commit 375aa0b

Browse files
fix: invalid date issue for indian format
1 parent b94e0fa commit 375aa0b

File tree

5 files changed

+85
-68
lines changed

5 files changed

+85
-68
lines changed

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

Lines changed: 35 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -61,23 +61,53 @@ const changeDateToMomentFormat = (format) => {
6161
}
6262
};
6363

64-
const getDefaultdate = (selectedDate) =>
65-
selectedDate ? new Date(selectedDate) : new Date();
64+
// const getDefaultdate = (selectedDate) => {
65+
// return selectedDate ? new Date(selectedDate) : new Date();
66+
// };
67+
const getDefaultdate = (selectedDate, format = "dd-MM-yyyy") => {
68+
let date;
69+
if (format && format === "dd-MM-yyyy") {
70+
const newdate = selectedDate
71+
? selectedDate
72+
: moment(new Date()).format(changeDateToMomentFormat(format));
73+
const [day, month, year] = newdate.split("-");
74+
date = new Date(`${year}-${month}-${day}`);
75+
} else {
76+
date = new Date(selectedDate);
77+
}
78+
const value = date;
79+
return value;
80+
};
6681
const getDefaultFormat = (dateFormat) => dateFormat || "MM/dd/yyyy";
6782

6883
function Placeholder(props) {
6984
const [isDraggingEnabled, setDraggingEnabled] = useState(true);
7085
const [isShowDateFormat, setIsShowDateFormat] = useState(false);
86+
// const [selectDate, setSelectDate] = useState({
87+
// date: moment(
88+
// getDefaultdate(props?.pos?.options?.response).getTime()
89+
// ).format(changeDateToMomentFormat(props.pos?.options?.validation?.format)),
90+
// format: getDefaultFormat(props.pos?.options?.validation?.format)
91+
// });
7192
const [selectDate, setSelectDate] = useState({
7293
date: moment(
73-
getDefaultdate(props?.pos?.options?.response).getTime()
94+
getDefaultdate(
95+
props?.pos?.options?.response,
96+
props.pos?.options?.validation?.format
97+
).getTime()
7498
).format(changeDateToMomentFormat(props.pos?.options?.validation?.format)),
7599
format: getDefaultFormat(props.pos?.options?.validation?.format)
76100
});
77101
const [dateFormat, setDateFormat] = useState([]);
78102
const [saveDateFormat, setSaveDateFormat] = useState("");
103+
// const [startDate, setStartDate] = useState(
104+
// getDefaultdate(props?.pos?.options?.response)
105+
// );
79106
const [startDate, setStartDate] = useState(
80-
getDefaultdate(props?.pos?.options?.response)
107+
getDefaultdate(
108+
props?.pos?.options?.response,
109+
props.pos?.options?.validation?.format
110+
)
81111
);
82112
const dateFormatArr = [
83113
"L",
@@ -91,8 +121,6 @@ function Placeholder(props) {
91121
"DD MMMM, YYYY"
92122
];
93123

94-
// console.log('props.pos',props.pos?.options?.validation?.format)
95-
96124
//useEffect for to set date and date format for all flow (signyour-self, request-sign,placeholder,template)
97125
//checking if already have data and set else set new date
98126
// useEffect(() => {
@@ -125,28 +153,23 @@ function Placeholder(props) {
125153

126154
//function change format array list with selected date and format
127155
const changeDateFormat = () => {
128-
// console.log("selected date", selectDate);
129156
const updateDate = [];
130157
dateFormatArr.map((data) => {
131158
let date;
132-
if (selectDate.format === "dd-MM-yyyy") {
159+
if (selectDate && selectDate.format === "dd-MM-yyyy") {
133160
const [day, month, year] = selectDate.date.split("-");
134161
date = new Date(`${year}-${month}-${day}`);
135162
} else {
136163
date = new Date(selectDate?.date);
137164
}
138165
const milliseconds = date.getTime();
139-
// console.log('data',data)
140166
const newDate = moment(milliseconds).format(data);
141-
// console.log('new date',newDate)
142167
const dateObj = {
143168
date: newDate,
144169
format: selectFormat(data)
145170
};
146-
// console.log('dateobj',dateObj)
147171
updateDate.push(dateObj);
148172
});
149-
// console.log('updated format',updateDate)
150173
setDateFormat(updateDate);
151174
};
152175

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

Lines changed: 21 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -133,27 +133,28 @@ function PlaceholderType(props) {
133133
if (type && type === "date") {
134134
if (props?.selectDate) {
135135
let updateDate;
136-
if (props?.selectDate.format === "dd-MM-yyyy") {
137-
// console.log('saveDateformat',props.saveDateFormat)
138-
const [day, month, year] = props.saveDateFormat.split("-");
139-
updateDate = new Date(`${year}-${month}-${day}`);
140-
} else {
141-
if (props?.saveDateFormat) {
142-
updateDate = new Date(props.saveDateFormat);
143-
}
144-
}
136+
// if (props?.selectDate.format === "dd-MM-yyyy") {
137+
// // console.log('saveDateformat',props.saveDateFormat)
138+
// const [day, month, year] = props.saveDateFormat.split("-");
139+
// updateDate = new Date(`${year}-${month}-${day}`);
140+
// console.log('update',updateDate)
141+
// } else {
142+
// if (props?.saveDateFormat) {
143+
// updateDate = new Date(props.saveDateFormat);
144+
// }
145+
// }
145146
// const updateDate = new Date(props.saveDateFormat);
146-
props.setStartDate(updateDate);
147-
const dateObj = {
148-
date: props.saveDateFormat,
149-
format: props.selectDate
150-
? props.selectDate?.format
151-
: props.pos?.options?.validation?.format
152-
? props.pos?.options?.validation?.format
153-
: "MM/dd/yyyy"
154-
};
155-
console.log("savedateformat selectdate", dateObj);
156-
props.setSelectDate(dateObj);
147+
// props.setStartDate(updateDate);
148+
// const dateObj = {
149+
// date: props.saveDateFormat,
150+
// format: props.selectDate
151+
// ? props.selectDate?.format
152+
// : props.pos?.options?.validation?.format
153+
// ? props.pos?.options?.validation?.format
154+
// : "MM/dd/yyyy"
155+
// };
156+
157+
// props.setSelectDate(dateObj);
157158
onChangeInput(
158159
props.saveDateFormat,
159160
props.pos.key,

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

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -204,17 +204,17 @@ function WidgetComponent({
204204
dragSignature,
205205
dragStamp,
206206
initials,
207+
name,
208+
jobTitle,
209+
company,
210+
date,
207211
label,
208212
text,
209213
checkbox,
210214
dropdown,
211215
radio,
212216
image,
213-
date,
214-
name,
215-
email,
216-
company,
217-
jobTitle
217+
email
218218
];
219219
const getWidgetArray = widgets;
220220
const newUpdateSigner = getWidgetArray.map((obj, ind) => {

apps/OpenSign/src/constant/Utils.js

Lines changed: 21 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -161,6 +161,26 @@ export const widgets = [
161161
icon: "fa-solid fa-signature",
162162
iconSize: "15px"
163163
},
164+
{
165+
type: "name",
166+
icon: "fa-solid fa-user",
167+
iconSize: "21px"
168+
},
169+
{
170+
type: "job title",
171+
icon: "fa-solid fa-address-card",
172+
iconSize: "17px"
173+
},
174+
{
175+
type: "company",
176+
icon: "fa-solid fa-building",
177+
iconSize: "25px"
178+
},
179+
{
180+
type: "date",
181+
icon: "fa-solid fa-calendar-days",
182+
iconSize: "20px"
183+
},
164184
{
165185
type: "label",
166186
icon: "fa-solid fa-text-width",
@@ -191,40 +211,19 @@ export const widgets = [
191211
icon: "fa-solid fa-image",
192212
iconSize: "20px"
193213
},
194-
{
195-
type: "date",
196-
icon: "fa-solid fa-calendar-days",
197-
iconSize: "20px"
198-
},
199-
{
200-
type: "name",
201-
icon: "fa-solid fa-user",
202-
iconSize: "21px"
203-
},
204214
{
205215
type: "email",
206216
icon: "fa-solid fa-envelope",
207217
iconSize: "20px"
208-
},
209-
{
210-
type: "company",
211-
icon: "fa-solid fa-building",
212-
iconSize: "25px"
213-
},
214-
{
215-
type: "job title",
216-
icon: "fa-solid fa-address-card",
217-
iconSize: "17px"
218218
}
219219
];
220220

221-
const getDate = () => {
221+
export const getDate = () => {
222222
const date = new Date();
223223
const milliseconds = date.getTime();
224224
const newDate = moment(milliseconds).format("MM/DD/YYYY");
225225
return newDate;
226226
};
227-
228227
export const addWidgetOptions = (type) => {
229228
const defaultOpt = {
230229
name: "",

apps/OpenSign/src/pages/SignyourselfPdf.js

Lines changed: 3 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,8 @@ import {
2525
onSaveSign,
2626
contractUsers,
2727
contactBook,
28-
randomId
28+
randomId,
29+
getDate
2930
} from "../constant/Utils";
3031
import { useParams } from "react-router-dom";
3132
import Tour from "reactour";
@@ -308,13 +309,6 @@ function SignYourSelf() {
308309
setIsLoading(loadObj);
309310
}
310311
};
311-
312-
const getDate = () => {
313-
const date = new Date();
314-
const milliseconds = date.getTime();
315-
const newDate = moment(milliseconds).format("MM/DD/YYYY");
316-
return newDate;
317-
};
318312
const getWidgetValue = (type) => {
319313
switch (type) {
320314
case "name":
@@ -333,6 +327,7 @@ function SignYourSelf() {
333327
return "";
334328
}
335329
};
330+
336331
const addWidgetOptions = (type) => {
337332
switch (type) {
338333
case "signature":
@@ -596,7 +591,6 @@ function SignYourSelf() {
596591
await signPdfFun(pdfBytes, documentId);
597592
}
598593
}
599-
600594
//function for get digital signature
601595
const signPdfFun = async (base64Url, documentId) => {
602596
let singleSign = {

0 commit comments

Comments
 (0)