@@ -7,14 +7,78 @@ import PlaceholderType from "./PlaceholderType";
7
7
import moment from "moment" ;
8
8
import "../../styles/opensigndrive.css" ;
9
9
10
+ const selectFormat = ( data ) => {
11
+ switch ( data ) {
12
+ case "L" :
13
+ return "MM/dd/yyyy" ;
14
+ case "DD-MM-YYYY" :
15
+ return "dd-MM-yyyy" ;
16
+ case "DD/MM/YYYY" :
17
+ return "dd/MM/yyyy" ;
18
+ case "LL" :
19
+ return "MMMM dd, yyyy" ;
20
+ case "DD MMM, YYYY" :
21
+ return "dd MMM, yyyy" ;
22
+ case "YYYY-MM-DD" :
23
+ return "yyyy-MM-dd" ;
24
+ case "MM-DD-YYYY" :
25
+ return "MM-dd-yyyy" ;
26
+ case "MM.DD.YYYY" :
27
+ return "MM.dd.yyyy" ;
28
+ case "MMM DD, YYYY" :
29
+ return "MMM dd, yyyy" ;
30
+ case "DD MMMM, YYYY" :
31
+ return "dd MMMM, yyyy" ;
32
+ default :
33
+ return "MM/dd/yyyy" ;
34
+ }
35
+ } ;
36
+
37
+ const changeDateToMomentFormat = ( format ) => {
38
+ switch ( format ) {
39
+ case "MM/dd/yyyy" :
40
+ return "L" ;
41
+ case "dd-MM-yyyy" :
42
+ return "DD-MM-YYYY" ;
43
+ case "dd/MM/yyyy" :
44
+ return "DD/MM/YYYY" ;
45
+ case "MMMM dd, yyyy" :
46
+ return "LL" ;
47
+ case "dd MMM, yyyy" :
48
+ return "DD MMM, YYYY" ;
49
+ case "yyyy-MM-dd" :
50
+ return "YYYY-MM-DD" ;
51
+ case "MM-dd-yyyy" :
52
+ return "MM-DD-YYYY" ;
53
+ case "MM.dd.yyyy" :
54
+ return "MM.DD.YYYY" ;
55
+ case "MMM dd, yyyy" :
56
+ return "MMM DD, YYYY" ;
57
+ case "dd MMMM, yyyy" :
58
+ return "DD MMMM, YYYY" ;
59
+ default :
60
+ return "L" ;
61
+ }
62
+ } ;
63
+
64
+ const getDefaultdate = ( selectedDate ) =>
65
+ selectedDate ? new Date ( selectedDate ) : new Date ( ) ;
66
+ const getDefaultFormat = ( dateFormat ) => dateFormat || "MM/dd/yyyy" ;
67
+
10
68
function Placeholder ( props ) {
11
69
const [ isDraggingEnabled , setDraggingEnabled ] = useState ( true ) ;
12
70
const [ isShowDateFormat , setIsShowDateFormat ] = useState ( false ) ;
13
- const [ selectDate , setSelectDate ] = useState ( ) ;
71
+ const [ selectDate , setSelectDate ] = useState ( {
72
+ date : moment (
73
+ getDefaultdate ( props ?. pos ?. options ?. response ) . getTime ( )
74
+ ) . format ( changeDateToMomentFormat ( props . pos ?. options ?. validation ?. format ) ) ,
75
+ format : getDefaultFormat ( props . pos ?. options ?. validation ?. format )
76
+ } ) ;
14
77
const [ dateFormat , setDateFormat ] = useState ( [ ] ) ;
15
78
const [ saveDateFormat , setSaveDateFormat ] = useState ( "" ) ;
16
-
17
- const [ startDate , setStartDate ] = useState ( ) ;
79
+ const [ startDate , setStartDate ] = useState (
80
+ getDefaultdate ( props ?. pos ?. options ?. response )
81
+ ) ;
18
82
const dateFormatArr = [
19
83
"L" ,
20
84
"DD-MM-YYYY" ,
@@ -27,71 +91,41 @@ function Placeholder(props) {
27
91
"DD MMMM, YYYY"
28
92
] ;
29
93
30
- const selectFormat = ( data ) => {
31
- switch ( data ) {
32
- case "L" :
33
- return "MM/dd/yyyy" ;
34
- case "DD-MM-YYYY" :
35
- return "dd-MM-yyyy" ;
36
- case "DD/MM/YYYY" :
37
- return "dd/MM/yyyy" ;
38
- case "LL" :
39
- return "MMMM dd, yyyy" ;
40
- case "DD MMM, YYYY" :
41
- return "dd MMM, YYYY" ;
42
- case "YYYY-MM-DD" :
43
- return "YYYY-MM-dd" ;
44
- case "MM-DD-YYYY" :
45
- return "MM-dd-YYYY" ;
46
- case "MM.DD.YYYY" :
47
- return "MM.dd.YYYY" ;
48
- case "MMM DD, YYYY" :
49
- return "MMM dd, YYYY" ;
50
- case "DD MMMM, YYYY" :
51
- return "dd MMMM, YYYY" ;
52
- default :
53
- return "dd/MM/yyyy" ;
54
- }
55
- } ;
94
+ // console.log('props.pos',props.pos?.options?.validation?.format)
56
95
57
96
//useEffect for to set date and date format for all flow (signyour-self, request-sign,placeholder,template)
58
97
//checking if already have data and set else set new date
59
- useEffect ( ( ) => {
60
- //set default current date and default format MM/dd/yyyy
61
- // if (props.isSignYourself) {
62
- // const date = new Date();
63
- // const milliseconds = date.getTime();
64
- // const newDate = moment(milliseconds).format("MM/DD/YYYY");
65
- // const dateObj = {
66
- // date: newDate,
67
- // format: "MM/dd/YYYY"
68
- // };
69
- // setSelectDate(dateObj);
70
- // } else {
71
- const defaultRes = props ?. pos ?. options ?. response ;
72
-
73
- const defaultFormat = props . pos ?. options ?. validation ?. format ;
74
- const updateDate = defaultRes
75
- ? new Date ( props ?. pos ?. options ?. response )
76
- : new Date ( ) ;
77
- const dateFormat = defaultFormat ? defaultFormat : "MM/DD/YYYY" ;
78
- const milliseconds = updateDate . getTime ( ) ;
79
- const newDate = moment ( milliseconds ) . format ( dateFormat ) ;
80
- const dateObj = {
81
- date : newDate ,
82
- format : props . pos ?. options ?. validation ?. format
83
- ? props . pos ?. options ?. validation ?. format
84
- : "MM/dd/YYYY"
85
- } ;
86
- setSelectDate ( dateObj ) ;
87
- setStartDate ( updateDate ) ;
98
+ // useEffect(() => {
99
+ // console.log('go here')
100
+ // //set default current date and default format MM/dd/yyyy
101
+ // const defaultFormat = props.pos?.options?.validation?.format;
102
+ // const updateDate = props?.pos?.options?.response
103
+ // ? new Date(props?.pos?.options?.response)
104
+ // : new Date();
105
+ // //DD-mm-YYYY
106
+ // const dateFormat = defaultFormat && defaultFormat;
107
+ // // const isMomentType = dateFormat && dateFormat === "MM/dd/YYYY";
108
+ // // const selectMomentFormat = isMomentType ? "MM/DD/YYYY" : dateFormat;
109
+ // const selectMomentFormat = changeDateToMomentFormat(dateFormat);
88
110
89
- // }
90
- // eslint-disable-next-line react-hooks/exhaustive-deps
91
- } , [ props . index ] ) ;
111
+ // // const isFormatType = dateFormat && dateFormat === "MM/dd/YYYY";
112
+ // const getFormat = dateFormat || "MM/dd/yyyy";
113
+ // const milliseconds = updateDate.getTime();
114
+ // const newDate = moment(milliseconds).format(selectMomentFormat);
115
+ // // console.log('new date',newDate)
116
+ // const dateObj = {
117
+ // date: newDate,
118
+ // format: getFormat
119
+ // };
120
+ // console.log("dateobj selectdate useEffect", dateObj);
121
+ // setSelectDate(dateObj);
122
+ // setStartDate(updateDate);
123
+ // // eslint-disable-next-line react-hooks/exhaustive-deps
124
+ // }, []);
92
125
93
- //function for add selected date and format in selectFormat
126
+ //function change format array list with selected date and format
94
127
const changeDateFormat = ( ) => {
128
+ // console.log("selected date", selectDate);
95
129
const updateDate = [ ] ;
96
130
dateFormatArr . map ( ( data ) => {
97
131
let date ;
@@ -102,17 +136,24 @@ function Placeholder(props) {
102
136
date = new Date ( selectDate ?. date ) ;
103
137
}
104
138
const milliseconds = date . getTime ( ) ;
139
+ // console.log('data',data)
105
140
const newDate = moment ( milliseconds ) . format ( data ) ;
141
+ // console.log('new date',newDate)
106
142
const dateObj = {
107
143
date : newDate ,
108
144
format : selectFormat ( data )
109
145
} ;
146
+ // console.log('dateobj',dateObj)
110
147
updateDate . push ( dateObj ) ;
111
148
} ) ;
149
+ // console.log('updated format',updateDate)
112
150
setDateFormat ( updateDate ) ;
113
151
} ;
152
+
153
+ // console.log("selected date", selectDate);
114
154
useEffect ( ( ) => {
115
155
if ( props . isPlaceholder || props . isSignYourself ) {
156
+ // console.log("selected date useEffect", selectDate);
116
157
selectDate && changeDateFormat ( ) ;
117
158
}
118
159
// eslint-disable-next-line react-hooks/exhaustive-deps
0 commit comments