@@ -6,17 +6,26 @@ import duration from "dayjs/plugin/duration";
6
6
import { useFormContext } from "react-hook-form" ;
7
7
8
8
import { useCallback , useEffect } from "react" ;
9
- import { RequiredOrNull } from "../../../../../common/types/common" ;
9
+ import { Optional , RequiredOrNull } from "../../../../../common/types/common" ;
10
10
import { PaymentAndRefundSummaryFormData } from "../../types/types" ;
11
11
12
12
dayjs . extend ( duration ) ;
13
13
const THIRTY_ONE_DAYS = 31 ;
14
14
const roundingBuffer = dayjs . duration ( 1 , "hour" ) . asDays ( ) ;
15
15
16
+ /**
17
+ * The props used by the ReportDateTimePickers component.
18
+ */
19
+ export type ReportDateTimePickersProps = {
20
+ enableDateRangeValidation ?: Optional < boolean > ;
21
+ } ;
22
+
16
23
/**
17
24
* The date time pickers for reports.
18
25
*/
19
- export const ReportDateTimePickers = ( ) => {
26
+ export const ReportDateTimePickers = ( {
27
+ enableDateRangeValidation = false ,
28
+ } : ReportDateTimePickersProps ) => {
20
29
const { setValue, watch, setError, formState, clearErrors } =
21
30
useFormContext < PaymentAndRefundSummaryFormData > ( ) ;
22
31
const { errors } = formState ;
@@ -42,8 +51,10 @@ export const ReportDateTimePickers = () => {
42
51
} , [ fromDateTime , toDateTime ] ) ;
43
52
44
53
useEffect ( ( ) => {
45
- validateToDateTime ( ) ;
46
- } , [ fromDateTime , toDateTime ] ) ;
54
+ if ( enableDateRangeValidation ) {
55
+ validateToDateTime ( ) ;
56
+ }
57
+ } , [ fromDateTime , toDateTime , enableDateRangeValidation ] ) ;
47
58
48
59
return (
49
60
< >
@@ -114,8 +125,14 @@ export const ReportDateTimePickers = () => {
114
125
* The reports API account for a rounding value which allows this buffer.
115
126
*
116
127
* Hence the decision to add 1 minute to 30 days, to make life easier for user.
128
+ *
129
+ * Note: Date range validation is not applicable for Summary Reports.
117
130
*/
118
- maxDateTime = { fromDateTime . add ( THIRTY_ONE_DAYS , "days" ) . add ( 1 , "minute" ) }
131
+ maxDateTime = {
132
+ enableDateRangeValidation
133
+ ? fromDateTime . add ( THIRTY_ONE_DAYS , "days" ) . add ( 1 , "minute" )
134
+ : undefined
135
+ }
119
136
views = { [ "year" , "month" , "day" , "hours" , "minutes" ] }
120
137
slotProps = { {
121
138
textField : {
0 commit comments