Skip to content

Commit 4470a54

Browse files
committed
fix(ui/ux): date/time styling and input validation
1 parent feb8ba3 commit 4470a54

File tree

2 files changed

+26
-10
lines changed

2 files changed

+26
-10
lines changed

app/w/[id]/components/workflow-block/components/sub-block/components/date-input.tsx

Lines changed: 25 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@ import { Button } from '@/components/ui/button'
77
import { Calendar } from '@/components/ui/calendar'
88
import { Popover, PopoverContent, PopoverTrigger } from '@/components/ui/popover'
99
import { cn } from '@/lib/utils'
10+
import { useNotificationStore } from '@/stores/notifications/store'
1011
import { useSubBlockValue } from '../hooks/use-sub-block-value'
1112

1213
interface DateInputProps {
@@ -17,30 +18,45 @@ interface DateInputProps {
1718

1819
export 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
)

app/w/[id]/components/workflow-block/components/sub-block/components/time-input.tsx

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -82,7 +82,7 @@ export function TimeInput({ blockId, subBlockId, placeholder }: TimeInputProps)
8282
!value && 'text-muted-foreground'
8383
)}
8484
>
85-
<Clock className="mr-2 h-4 w-4" />
85+
<Clock className="mr-1 h-4 w-4" />
8686
{value ? formatDisplayTime(value) : <span>{placeholder || 'Select time'}</span>}
8787
</Button>
8888
</PopoverTrigger>

0 commit comments

Comments
 (0)