@@ -7,6 +7,7 @@ import { Button } from '@/components/ui/button'
77import { Calendar } from '@/components/ui/calendar'
88import { Popover , PopoverContent , PopoverTrigger } from '@/components/ui/popover'
99import { cn } from '@/lib/utils'
10+ import { useNotificationStore } from '@/stores/notifications/store'
1011import { useSubBlockValue } from '../hooks/use-sub-block-value'
1112
1213interface DateInputProps {
@@ -17,30 +18,45 @@ interface DateInputProps {
1718
1819export function DateInput ( { blockId, subBlockId, placeholder } : DateInputProps ) {
1920 const [ value , setValue ] = useSubBlockValue < string > ( blockId , subBlockId , true )
20-
21+ const addNotification = useNotificationStore ( ( state ) => state . addNotification )
2122 const date = value ? new Date ( value ) : undefined
2223
24+ const isPastDate = React . useMemo ( ( ) => {
25+ if ( ! date ) return false
26+ const today = new Date ( )
27+ today . setHours ( 0 , 0 , 0 , 0 )
28+ return date < today
29+ } , [ date ] )
30+
31+ const handleDateSelect = ( selectedDate : Date | undefined ) => {
32+ if ( selectedDate ) {
33+ const today = new Date ( )
34+ today . setHours ( 0 , 0 , 0 , 0 )
35+
36+ if ( selectedDate < today ) {
37+ addNotification ( 'error' , 'Cannot start at a date in the past' , blockId )
38+ }
39+ }
40+ setValue ( selectedDate ?. toISOString ( ) || '' )
41+ }
42+
2343 return (
2444 < Popover >
2545 < PopoverTrigger asChild >
2646 < Button
2747 variant = "outline"
2848 className = { cn (
2949 'w-full justify-start text-left font-normal' ,
30- ! date && 'text-muted-foreground'
50+ ! date && 'text-muted-foreground' ,
51+ isPastDate && 'border-red-500'
3152 ) }
3253 >
33- < CalendarIcon className = "mr-2 h-4 w-4" />
54+ < CalendarIcon className = "mr-1 h-4 w-4" />
3455 { date ? format ( date , 'MMM d, yy' ) : < span > { placeholder || 'Pick a date' } </ span > }
3556 </ Button >
3657 </ PopoverTrigger >
3758 < PopoverContent className = "w-auto p-0" >
38- < Calendar
39- mode = "single"
40- selected = { date }
41- onSelect = { ( date ) => setValue ( date ?. toISOString ( ) || '' ) }
42- initialFocus
43- />
59+ < Calendar mode = "single" selected = { date } onSelect = { handleDateSelect } initialFocus />
4460 </ PopoverContent >
4561 </ Popover >
4662 )
0 commit comments