diff --git a/app/w/[id]/components/workflow-block/components/sub-block/components/date-input.tsx b/app/w/[id]/components/workflow-block/components/sub-block/components/date-input.tsx index 8aa5d44a92..60ee6ca55f 100644 --- a/app/w/[id]/components/workflow-block/components/sub-block/components/date-input.tsx +++ b/app/w/[id]/components/workflow-block/components/sub-block/components/date-input.tsx @@ -7,6 +7,7 @@ import { Button } from '@/components/ui/button' import { Calendar } from '@/components/ui/calendar' import { Popover, PopoverContent, PopoverTrigger } from '@/components/ui/popover' import { cn } from '@/lib/utils' +import { useNotificationStore } from '@/stores/notifications/store' import { useSubBlockValue } from '../hooks/use-sub-block-value' interface DateInputProps { @@ -17,9 +18,28 @@ interface DateInputProps { export function DateInput({ blockId, subBlockId, placeholder }: DateInputProps) { const [value, setValue] = useSubBlockValue(blockId, subBlockId, true) - + const addNotification = useNotificationStore((state) => state.addNotification) const date = value ? new Date(value) : undefined + const isPastDate = React.useMemo(() => { + if (!date) return false + const today = new Date() + today.setHours(0, 0, 0, 0) + return date < today + }, [date]) + + const handleDateSelect = (selectedDate: Date | undefined) => { + if (selectedDate) { + const today = new Date() + today.setHours(0, 0, 0, 0) + + if (selectedDate < today) { + addNotification('error', 'Cannot start at a date in the past', blockId) + } + } + setValue(selectedDate?.toISOString() || '') + } + return ( @@ -27,20 +47,16 @@ export function DateInput({ blockId, subBlockId, placeholder }: DateInputProps) variant="outline" className={cn( 'w-full justify-start text-left font-normal', - !date && 'text-muted-foreground' + !date && 'text-muted-foreground', + isPastDate && 'border-red-500' )} > - + {date ? format(date, 'MMM d, yy') : {placeholder || 'Pick a date'}} - setValue(date?.toISOString() || '')} - initialFocus - /> + ) diff --git a/app/w/[id]/components/workflow-block/components/sub-block/components/time-input.tsx b/app/w/[id]/components/workflow-block/components/sub-block/components/time-input.tsx index 4ce53b838c..4a29e85bd8 100644 --- a/app/w/[id]/components/workflow-block/components/sub-block/components/time-input.tsx +++ b/app/w/[id]/components/workflow-block/components/sub-block/components/time-input.tsx @@ -82,7 +82,7 @@ export function TimeInput({ blockId, subBlockId, placeholder }: TimeInputProps) !value && 'text-muted-foreground' )} > - + {value ? formatDisplayTime(value) : {placeholder || 'Select time'}}