1- ' use client' ;
1+ " use client" ;
22
3- import { formatDate } from "date-fns" ;
3+ import { formatDate , subYears } from "date-fns" ;
44import { CalendarIcon } from "lucide-react" ;
55import { usePathname , useRouter , useSearchParams } from "next/navigation" ;
66import { useEffect , useState } from "react" ;
@@ -9,7 +9,7 @@ import { DateRange as ReactDateRange } from "react-day-picker";
99import { cn } from "@/lib/utils" ;
1010
1111import { Button } from "./button" ;
12- import { Calendar } from "./calendar" ;
12+ import { Calendar , CalendarProps } from "./calendar" ;
1313import { Label } from "./label" ;
1414import { Popover , PopoverContent , PopoverTrigger } from "./popover" ;
1515import { Select , SelectContent , SelectItem , SelectTrigger , SelectValue } from "./select" ;
@@ -42,7 +42,11 @@ const RANGES: DateRange[] = [
4242 } ,
4343] ;
4444
45- function AbsoluteDateRangeFilter ( ) {
45+ function AbsoluteDateRangeFilter ( {
46+ disabled = { after : new Date ( ) , before : subYears ( new Date ( ) , 1 ) } ,
47+ } : {
48+ disabled ?: CalendarProps [ "disabled" ] ;
49+ } ) {
4650 const searchParams = new URLSearchParams ( useSearchParams ( ) . toString ( ) ) ;
4751 const pathName = usePathname ( ) ;
4852 const router = useRouter ( ) ;
@@ -59,10 +63,10 @@ function AbsoluteDateRangeFilter() {
5963 urlFrom = new Date ( searchParams . get ( "startDate" ) as string ) ;
6064 setStartTime ( {
6165 hour : urlFrom . getHours ( ) . toString ( ) . padStart ( 2 , "0" ) ,
62- minute : urlFrom . getMinutes ( ) . toString ( ) . padStart ( 2 , "0" )
66+ minute : urlFrom . getMinutes ( ) . toString ( ) . padStart ( 2 , "0" ) ,
6367 } ) ;
6468 }
65- } catch ( e ) { }
69+ } catch ( e ) { }
6670
6771 let urlTo : Date | undefined = undefined ;
6872 try {
@@ -71,10 +75,10 @@ function AbsoluteDateRangeFilter() {
7175 urlTo = new Date ( searchParams . get ( "endDate" ) as string ) ;
7276 setEndTime ( {
7377 hour : urlTo . getHours ( ) . toString ( ) . padStart ( 2 , "0" ) ,
74- minute : urlTo . getMinutes ( ) . toString ( ) . padStart ( 2 , "0" )
78+ minute : urlTo . getMinutes ( ) . toString ( ) . padStart ( 2 , "0" ) ,
7579 } ) ;
7680 }
77- } catch ( e ) { }
81+ } catch ( e ) { }
7882
7983 if ( calendarDate === undefined || urlFrom === undefined || urlTo === undefined ) {
8084 setCalendarDate ( {
@@ -143,7 +147,7 @@ function AbsoluteDateRangeFilter() {
143147 selected = { calendarDate }
144148 onSelect = { setCalendarDate }
145149 numberOfMonths = { 2 }
146- disabled = { { after : new Date ( ) } }
150+ disabled = { disabled }
147151 pagedNavigation
148152 />
149153 < div className = "p-3" >
@@ -252,8 +256,11 @@ function AbsoluteDateRangeFilter() {
252256 </ div >
253257 ) ;
254258}
255-
256- export default function DateRangeFilter ( ) {
259+ export default function DateRangeFilter ( {
260+ disabled = { after : new Date ( ) , before : subYears ( new Date ( ) , 1 ) } ,
261+ } : {
262+ disabled ?: CalendarProps [ "disabled" ] ;
263+ } ) {
257264 const searchParams = new URLSearchParams ( useSearchParams ( ) . toString ( ) ) ;
258265 const pathName = usePathname ( ) ;
259266 const router = useRouter ( ) ;
@@ -287,7 +294,7 @@ export default function DateRangeFilter() {
287294 { range . name }
288295 </ div >
289296 ) ) }
290- < AbsoluteDateRangeFilter />
297+ < AbsoluteDateRangeFilter disabled = { disabled } />
291298 </ >
292299 }
293300 </ div >
0 commit comments