Skip to content

Commit 73c219f

Browse files
Merge pull request #470 from OpenSignLabs/date_issue
feat: year and month selection feature add on date widgets, wrong date embed on pdf issue fix
2 parents 878dca3 + f4090c0 commit 73c219f

File tree

4 files changed

+86
-6
lines changed

4 files changed

+86
-6
lines changed

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

Lines changed: 17 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -54,7 +54,7 @@ function Placeholder(props) {
5454

5555
useEffect(() => {
5656
//set default current date and default format MM/dd/yyyy
57-
if (props.isPlaceholder || props.isSignYourself) {
57+
if (props.isSignYourself) {
5858
const date = new Date();
5959
const milliseconds = date.getTime();
6060
const newDate = moment(milliseconds).format("MM/DD/YYYY");
@@ -63,6 +63,22 @@ function Placeholder(props) {
6363
format: "MM/dd/YYYY"
6464
};
6565
setSelectDate(dateObj);
66+
} else {
67+
const defaultRes = props?.pos?.options?.response;
68+
const defaultFormat = props.pos?.options?.validation?.format;
69+
const updateDate = defaultRes
70+
? new Date(props?.pos?.options?.response)
71+
: new Date();
72+
const dateFormat = defaultFormat ? defaultFormat : "MM/DD/YYYY";
73+
const milliseconds = updateDate.getTime();
74+
const newDate = moment(milliseconds).format(dateFormat);
75+
const dateObj = {
76+
date: newDate,
77+
format: props.pos?.options?.validation?.format
78+
? props.pos?.options?.validation?.format
79+
: "MM/dd/YYYY"
80+
};
81+
setSelectDate(dateObj);
6682
}
6783
// eslint-disable-next-line react-hooks/exhaustive-deps
6884
}, []);

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

Lines changed: 46 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
import React, { useEffect, useState, forwardRef, useRef } from "react";
2-
import { onChangeInput } from "../../constant/Utils";
2+
import { getMonth, getYear, onChangeInput, range } from "../../constant/Utils";
33
import DatePicker from "react-datepicker";
44
import "react-datepicker/dist/react-datepicker.css";
55
import "../../styles/signature.css";
@@ -15,6 +15,21 @@ function PlaceholderType(props) {
1515
const inputRef = useRef(null);
1616
const [textValue, setTextValue] = useState();
1717
const [selectedCheckbox, setSelectedCheckbox] = useState([]);
18+
const years = range(1990, getYear(new Date()) + 16, 1);
19+
const months = [
20+
"January",
21+
"February",
22+
"March",
23+
"April",
24+
"May",
25+
"June",
26+
"July",
27+
"August",
28+
"September",
29+
"October",
30+
"November",
31+
"December"
32+
];
1833
const validateExpression = (regexValidation) => {
1934
let regexObject = regexValidation;
2035
if (props.pos?.options.validation.type === "regex") {
@@ -31,7 +46,6 @@ function PlaceholderType(props) {
3146
const handleInputBlur = () => {
3247
props.setDraggingEnabled(true);
3348
const validateType = props.pos?.options?.validation?.type;
34-
3549
let regexValidation;
3650
if (validateType) {
3751
switch (validateType) {
@@ -293,6 +307,7 @@ function PlaceholderType(props) {
293307
isRadio
294308
);
295309
};
310+
296311
switch (type) {
297312
case "signature":
298313
return props.pos.SignUrl ? (
@@ -595,6 +610,34 @@ function PlaceholderType(props) {
595610
return (
596611
<div>
597612
<DatePicker
613+
renderCustomHeader={({ date, changeYear, changeMonth }) => (
614+
<div className="flex justify-start ml-2 ">
615+
<select
616+
className="bg-transparent outline-none"
617+
value={months[getMonth(date)]}
618+
onChange={({ target: { value } }) =>
619+
changeMonth(months.indexOf(value))
620+
}
621+
>
622+
{months.map((option) => (
623+
<option key={option} value={option}>
624+
{option}
625+
</option>
626+
))}
627+
</select>
628+
<select
629+
className="bg-transparent outline-none"
630+
value={getYear(date)}
631+
onChange={({ target: { value } }) => changeYear(value)}
632+
>
633+
{years.map((option) => (
634+
<option key={option} value={option}>
635+
{option}
636+
</option>
637+
))}
638+
</select>
639+
</div>
640+
)}
598641
disabled={
599642
props.isNeedSign && props.data?.signerObjId !== props.signerObjId
600643
}
@@ -712,6 +755,7 @@ function PlaceholderType(props) {
712755
case "label":
713756
return (
714757
<textarea
758+
placeholder="Enter label"
715759
rows={1}
716760
onChange={(e) => {
717761
onChangeInput(

apps/OpenSign/src/constant/Utils.js

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1517,3 +1517,23 @@ export const addDefaultSignatureImg = (xyPostion, defaultSignImg) => {
15171517
}
15181518
return xyDefaultPos;
15191519
};
1520+
1521+
//function for create list of year for date widget
1522+
export const range = (start, end, step) => {
1523+
const range = [];
1524+
for (let i = start; i <= end; i += step) {
1525+
range.push(i);
1526+
}
1527+
return range;
1528+
};
1529+
//function for get month
1530+
export const getMonth = (date) => {
1531+
const newMonth = new Date(date).getMonth();
1532+
return newMonth;
1533+
};
1534+
1535+
//function for get year
1536+
export const getYear = (date) => {
1537+
const newYear = new Date(date).getFullYear();
1538+
return newYear;
1539+
};

apps/OpenSign/src/pages/TemplatePlaceholder.js

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -725,7 +725,7 @@ const TemplatePlaceholder = () => {
725725
selector: '[data-tut="reactourFirst"]',
726726
content: () => (
727727
<TourContentWithBtn
728-
message={`Select a role from this list to add a place-holder where he is supposed to sign.The placeholder will appear in the same colour as the recipient name once you drop it on the document.`}
728+
message={`Once roles are added, select a role from list to add a place-holder where he is supposed to sign. The placeholder will appear in the same colour as the role name once you drop it on the document.`}
729729
isChecked={handleDontShow}
730730
/>
731731
),
@@ -737,7 +737,7 @@ const TemplatePlaceholder = () => {
737737
selector: '[data-tut="reactourSecond"]',
738738
content: () => (
739739
<TourContentWithBtn
740-
message={`Drag the signature or stamp placeholder onto the PDF to choose your desired signing location.`}
740+
message={`Drag a widget placeholder onto the PDF to choose your desired signing location.`}
741741
isChecked={handleDontShow}
742742
/>
743743
),
@@ -759,7 +759,7 @@ const TemplatePlaceholder = () => {
759759
selector: '[data-tut="reactourFour"]',
760760
content: () => (
761761
<TourContentWithBtn
762-
message={`Clicking "Save" button will save the template and will ask you for creating new document.`}
762+
message={`Clicking "Save" button will save the template and will ask you if you want to create a new document using this template.`}
763763
isChecked={handleDontShow}
764764
/>
765765
),

0 commit comments

Comments
 (0)